use of org.apereo.cas.services.ChainingAttributeReleasePolicy in project cas by apereo.
the class OidcProfileScopeToAttributesFilter method reconcile.
@Override
public void reconcile(final RegisteredService service) {
if (!(service instanceof OidcRegisteredService)) {
super.reconcile(service);
return;
}
final List<String> otherScopes = new ArrayList<>();
final ChainingAttributeReleasePolicy policy = new ChainingAttributeReleasePolicy();
final OidcRegisteredService oidc = OidcRegisteredService.class.cast(service);
oidc.getScopes().forEach(s -> {
switch(s.trim().toLowerCase()) {
case OidcConstants.EMAIL:
policy.getPolicies().add(new OidcEmailScopeAttributeReleasePolicy());
break;
case OidcConstants.ADDRESS:
policy.getPolicies().add(new OidcAddressScopeAttributeReleasePolicy());
break;
case OidcConstants.PROFILE:
policy.getPolicies().add(new OidcProfileScopeAttributeReleasePolicy());
break;
case OidcConstants.PHONE:
policy.getPolicies().add(new OidcPhoneScopeAttributeReleasePolicy());
break;
case OidcConstants.OFFLINE_ACCESS:
oidc.setGenerateRefreshToken(true);
break;
case OidcCustomScopeAttributeReleasePolicy.SCOPE_CUSTOM:
otherScopes.add(s.trim());
break;
default:
final BaseOidcScopeAttributeReleasePolicy userPolicy = userScopes.stream().filter(t -> t.getScopeName().equals(s.trim())).findFirst().orElse(null);
if (userPolicy != null) {
policy.getPolicies().add(userPolicy);
}
}
});
otherScopes.remove(OidcConstants.OPENID);
if (!otherScopes.isEmpty()) {
policy.getPolicies().add(new OidcCustomScopeAttributeReleasePolicy(otherScopes));
}
if (policy.getPolicies().isEmpty()) {
oidc.setAttributeReleasePolicy(new DenyAllAttributeReleasePolicy());
} else {
oidc.setAttributeReleasePolicy(policy);
}
this.servicesManager.save(oidc);
}
use of org.apereo.cas.services.ChainingAttributeReleasePolicy in project cas by apereo.
the class SamlRegisteredServiceTests method verifySavingInCommonSamlService.
@Test
public void verifySavingInCommonSamlService() throws Exception {
final SamlRegisteredService service = new SamlRegisteredService();
service.setName(SAML_SERVICE);
service.setServiceId("http://mmoayyed.unicon.net");
service.setMetadataLocation(METADATA_LOCATION);
final InCommonRSAttributeReleasePolicy policy = new InCommonRSAttributeReleasePolicy();
final ChainingAttributeReleasePolicy chain = new ChainingAttributeReleasePolicy();
chain.setPolicies(Arrays.asList(policy, new DenyAllAttributeReleasePolicy()));
service.setAttributeReleasePolicy(chain);
final JsonServiceRegistryDao dao = new JsonServiceRegistryDao(RESOURCE, false, mock(ApplicationEventPublisher.class));
dao.save(service);
dao.load();
}
Aggregations