Getting Started
This guide adds Ihawu to a Spring Boot application and masks a field end to end.
-
Add the starter. It pulls
ihawu-coretransitively, so it’s the only dependency you add.implementation("org.ihawu:ihawu-spring-boot-starter:0.4.1")<dependency><groupId>org.ihawu</groupId><artifactId>ihawu-spring-boot-starter</artifactId><version>0.4.1</version></dependency> -
Annotate your response type and mark the sensitive fields’ resource. Declare every maskable field nullable — a masked field is either omitted (
HIDE) or set tonull(REDACTon a non-String), so the type has to allow that.import org.ihawu.core.annotation.IhawuResource@IhawuResource("employee")data class EmployeeResponse(val id: String,val fullName: String,val email: String,val salary: Double?,val socialSecurityNumber: String?,) -
Define a policy. Supply the per-role rules either as a
ResourcePolicyProviderbean or straight fromihawu.policiesconfiguration — the two are equivalent.import org.ihawu.core.masking.MaskingStrategyimport org.ihawu.core.policy.FieldPolicyimport org.ihawu.core.policy.ResourcePolicyimport org.ihawu.spring.boot.starter.configuration.ResourcePolicyProviderimport org.springframework.context.annotation.Bean@Beanfun resourcePolicyProvider() =ResourcePolicyProvider {listOf(ResourcePolicy(resourceName = "employee",roleFieldPolicies = mapOf("MANAGER" to listOf(FieldPolicy("socialSecurityNumber", MaskingStrategy.REDACT, "***-**-****"),),"EMPLOYEE" to listOf(FieldPolicy("salary", MaskingStrategy.HIDE),FieldPolicy("socialSecurityNumber", MaskingStrategy.HIDE),),),),)}# application.yml — same rules, no codeihawu:policies:- resource: employeeroles:MANAGER:- field: socialSecurityNumberstrategy: REDACTplaceholder: "***-**-****"EMPLOYEE:- field: salarystrategy: HIDE- field: socialSecurityNumberstrategy: HIDE -
Call the endpoint. The same handler now returns different fields per role — a
MANAGERsees a redacted SSN; anEMPLOYEEsees neither salary nor SSN; an unconfigured role sees the full record (masking is a denylist).
A runnable example
Section titled “A runnable example”The repository ships a complete, runnable sample under samples/spring-boot-sample — a secured
endpoint, three roles, and an integration test that pins each role’s masked JSON. It’s the fastest way
to see Ihawu working against a live HTTP endpoint.
Next steps
Section titled “Next steps”- Understand the model in How Ihawu Works.
- Browse the full API in the Dokka reference.