ADFS has the concept of claim rules which allow you to enumerate, add, delete, and modify claims. This is useful when you want for example introduce extra claims (based on data in a database or AD) or transform incoming claims.
Although the available documentation is already helpful, I still find it a challenge to write my own claim rules. So therefore this post…
Claim rule components
To start a claim rule consists of 2 parts, separated by the “=>” operator:
-
An optional(!) condition
-
An issuance statement
So both these rules are correct:
Rule #1:
=> issue(type = "https://test/role", value = "employee");
Rule #2:
c:[type == "https://test/employee", value == "true"] => issue(type = "https://test/role", value = "employee")
The first rule will always generate a new outgoing claim of type https://test/role. The second rule will only generate a new outgoing claim of type https://test/role when an incoming claim of type https://test/employee with a value true is found.
Remark: It is also possible to generate a new claim in the incoming claim set, If you want to know more, check the documentation here.
Conditions
Conditions can come in multiple forms. In the example above I used a single-expression condition but it is also possible to combine multiple conditions using the &&:
c1:[type == "https://test/name"] && c2:[type == "https://test/email"] => issue(claim = c1);
Scenarios
Now that I have explained the basics, let’s look at some typical scenario’s I use the most:
Scenario 1 – Create a new claim
Let’s start simple by creating a new claim:
=> issue(Type = http://schemas.example.be/iam/claims/authorized, Value = "True");
Scenario 2 – Create a new claim from an existing one
We can also create a new claim based on values from an existing claim:
c1:[Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"]
=> issue(Type = http://schemas.example.be/iam/claims/fullname, Value = c1.Value);
Scenario 3 - Pass an existing claim
By default no claims are automatically passed. If you want to pass a claim, you can use the following rule:
c:[Type == "http://schemas.example.be/iam/claims/personid"]
=> issue(claim = c);
Scenario 4 – Check the attribute store
ADFS can link to one or more attribute stores that can be queried for extra data. For example, we can query a database based on an incoming claims value:
c:[Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"]
=> issue(store = "IAMDB", types = (http://schemas.example.be/iam/claims/authorized, http://schemas.example.be/iam/claims/FullName"), query = "exec IsAuthorized @UserName={0}, @Application=Example'", param = c.Value);
Rule order
It is important to understand that the rules are executed in a specific order. So if one rule depends on the output of a previous rule, make sure that the order is correctly set.