Attribute Release Policy - Pattern Matching
This policy allows the release of defined allowed attributes only if the attribute value(s) matches the given regular expression pattern. If the attribute value is matched successfully, the policy is then able to apply transformation rules on the value to extract and collect the matched groups to then assemble the final attribute value.
-
Consider an authenticated principal with a
memberOfattribute which contains values such asCN=g1,OU=example,DC=org, andCN=g2,OU=example,DC=org. The following policy applies the defined pattern and the transformation on each attribute value. The final result would be amemberOfattribute with valuesg1@example.organdg2@example.org.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
{ "@class" : "org.apereo.cas.services.CasRegisteredService", "serviceId" : "...", "name" : "sample", "id" : 300, "attributeReleasePolicy" : { "@class": "org.apereo.cas.services.PatternMatchingAttributeReleasePolicy", "allowedAttributes": { "@class": "java.util.TreeMap", "memberOf": { "@class": "org.apereo.cas.services.PatternMatchingAttributeReleasePolicy$Rule", "pattern": "^CN=(\\w+),\\s*OU=(\\w+),\\s*DC=(\\w+)", "transform": "${1}@${2}/${3}" } } } }
Matched pattern groups typically start at
1. If you need to refer to the entire matched region, use${0}. -
Consider an authenticated principal with a
memberOfattribute which contains values such asCN=g1,OU=example,DC=org, andCN=g2,OU=example,DC=org. The following policy applies the defined pattern and the transformation on each attribute value.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
{ "@class" : "org.apereo.cas.services.CasRegisteredService", "serviceId" : "...", "name" : "sample", "id" : 300, "attributeReleasePolicy" : { "@class": "org.apereo.cas.services.PatternMatchingAttributeReleasePolicy", "allowedAttributes": { "@class": "java.util.TreeMap", "memberOf": { "@class": "org.apereo.cas.services.PatternMatchingAttributeReleasePolicy$Rule", "pattern": ".*CN=(\w+),OU=example.*", "transform": ''' groovy { logger.info("Full matched value is ${matched}") def value = matchedGroup1 == 'g1' ? 'group1' : 'group2' // return a Map of attribute names to values return [mem: [value]] } ''' } } } }
The final released attribute would be
memwith valuesgroup1andgroup2.The script must return a
Mapof attribute names to values. A single value is released as a one-element collection, and entries without a name or without any value are ignored. When more than one rule returns the same attribute name, their values are combined.The following parameters are passed to the script:
Parameter Description attributesMapof attributes currently resolved and available for release.loggerThe object responsible for issuing log messages such as logger.info(...).contextThe object representing the attribute release policy context carrying service,principal, etc.matchedThe full matched value. matchedGroup0Same as matched.matchedGroupXMatched group where Xis the group index, if the pattern uses groups.To prepare CAS to support and integrate with Apache Groovy, please review this guide.