The most recent patch for this version is 26.2.1.  Learn more

Skip to main content

Write ALFA policies

With the requirements captured, the attributes defined, and a failing test written, write the policy that makes the test pass.

  1. Delete the example policies of the APD distribution in src/authorizationDomain/alfaSpecifications/: main.alfa and the consultants and managers directories. Keep system.alfa, which defines the ALFA types, categories, and combining algorithms, and attributes.alfa, the ALFA dictionary generated from attributes.yaml.

  2. 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.alfa
    namespace acme {
    policy Main {
    target clause acme.user.role == "consultant"
    apply firstApplicable
    rule permitInSameLocation {
    permit
    condition 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 with mainpolicy "acme.Main" in build.gradle.

    tip

    For the ALFA language, see the ALFA reference documentationOpens in a new tab.

  3. 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.

tip

To learn ALFA, take the Axiomatics ALFA coursesOpens in a new tab. Contact Axiomatics Customer SupportOpens in a new tab for access.