use of org.keycloak.representations.idm.authorization.RegexPolicyRepresentation in project keycloak by keycloak.
the class RegexPolicyProvider method evaluate.
@Override
public void evaluate(Evaluation evaluation) {
AuthorizationProvider authorizationProvider = evaluation.getAuthorizationProvider();
RegexPolicyRepresentation policy = representationFunction.apply(evaluation.getPolicy(), authorizationProvider);
Attributes.Entry targetClaim = evaluation.getContext().getIdentity().getAttributes().getValue(policy.getTargetClaim());
if (targetClaim == null) {
return;
}
Pattern pattern = Pattern.compile(policy.getPattern());
Matcher matcher = pattern.matcher(targetClaim.asString(0));
if (matcher.matches()) {
evaluation.grant();
}
}
use of org.keycloak.representations.idm.authorization.RegexPolicyRepresentation in project keycloak by keycloak.
the class RegexPolicyProviderFactory method toRepresentation.
@Override
public RegexPolicyRepresentation toRepresentation(Policy policy, AuthorizationProvider authorization) {
RegexPolicyRepresentation representation = new RegexPolicyRepresentation();
Map<String, String> config = policy.getConfig();
representation.setTargetClaim(config.get("targetClaim"));
representation.setPattern(config.get("pattern"));
return representation;
}
use of org.keycloak.representations.idm.authorization.RegexPolicyRepresentation in project keycloak by keycloak.
the class RegexPolicyTest method createRegexPolicy.
private void createRegexPolicy(String name, String targetClaim, String pattern) {
RegexPolicyRepresentation policy = new RegexPolicyRepresentation();
policy.setName(name);
policy.setTargetClaim(targetClaim);
policy.setPattern(pattern);
getClient().authorization().policies().regex().create(policy).close();
}
Aggregations