Write ALFA policies
With the requirements captured, the attributes defined, and a failing test written, write the policy that makes the test pass.
-
Delete the example policies of the APD distribution in
src/authorizationDomain/alfaSpecifications/:main.alfaand theconsultantsandmanagersdirectories. Keepsystem.alfa, which defines the ALFA types, categories, and combining algorithms, andattributes.alfa, the ALFA dictionary generated fromattributes.yaml. -
Create the main policy in
src/authorizationDomain/alfaSpecifications/main.alfa. The following policy implements the requirement of the test in Write tests:src/authorizationDomain/alfaSpecifications/main.alfanamespace acme {policy Main {target clause acme.user.role == "consultant"apply firstApplicablerule permitInSameLocation {permitcondition acme.user.location == acme.resource.location}}}The target makes the policy apply to consultants only, and the rule permits the request when the user and the resource are in the same location. The full name of the policy,
acme.Main, is the main policy set withmainpolicy "acme.Main"inbuild.gradle.tipFor the ALFA language, see the ALFA reference documentationOpens in a new tab.
-
Run the tests again with
./gradlew test. The build reports ALFA errors with the file and line. Change the policy until all tests pass.
Next, connect the attributes that the requests do not provide: Create the attribute connectors.
To learn ALFA, take the Axiomatics ALFA coursesOpens in a new tab. Contact Axiomatics Customer SupportOpens in a new tab for access.