Search in sources :

Example 1 with ChainingAttributeReleasePolicy

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);
}
Also used : DenyAllAttributeReleasePolicy(org.apereo.cas.services.DenyAllAttributeReleasePolicy) OidcProfileScopeAttributeReleasePolicy(org.apereo.cas.oidc.claims.OidcProfileScopeAttributeReleasePolicy) OidcCustomScopeAttributeReleasePolicy(org.apereo.cas.oidc.claims.OidcCustomScopeAttributeReleasePolicy) BaseOidcScopeAttributeReleasePolicy(org.apereo.cas.oidc.claims.BaseOidcScopeAttributeReleasePolicy) OidcRegisteredService(org.apereo.cas.services.OidcRegisteredService) ArrayList(java.util.ArrayList) ChainingAttributeReleasePolicy(org.apereo.cas.services.ChainingAttributeReleasePolicy) OidcPhoneScopeAttributeReleasePolicy(org.apereo.cas.oidc.claims.OidcPhoneScopeAttributeReleasePolicy) OidcAddressScopeAttributeReleasePolicy(org.apereo.cas.oidc.claims.OidcAddressScopeAttributeReleasePolicy) OidcEmailScopeAttributeReleasePolicy(org.apereo.cas.oidc.claims.OidcEmailScopeAttributeReleasePolicy)

Example 2 with ChainingAttributeReleasePolicy

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();
}
Also used : InCommonRSAttributeReleasePolicy(org.apereo.cas.support.saml.services.InCommonRSAttributeReleasePolicy) DenyAllAttributeReleasePolicy(org.apereo.cas.services.DenyAllAttributeReleasePolicy) JsonServiceRegistryDao(org.apereo.cas.services.JsonServiceRegistryDao) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ChainingAttributeReleasePolicy(org.apereo.cas.services.ChainingAttributeReleasePolicy) Test(org.junit.Test)

Aggregations

ChainingAttributeReleasePolicy (org.apereo.cas.services.ChainingAttributeReleasePolicy)2 DenyAllAttributeReleasePolicy (org.apereo.cas.services.DenyAllAttributeReleasePolicy)2 ArrayList (java.util.ArrayList)1 BaseOidcScopeAttributeReleasePolicy (org.apereo.cas.oidc.claims.BaseOidcScopeAttributeReleasePolicy)1 OidcAddressScopeAttributeReleasePolicy (org.apereo.cas.oidc.claims.OidcAddressScopeAttributeReleasePolicy)1 OidcCustomScopeAttributeReleasePolicy (org.apereo.cas.oidc.claims.OidcCustomScopeAttributeReleasePolicy)1 OidcEmailScopeAttributeReleasePolicy (org.apereo.cas.oidc.claims.OidcEmailScopeAttributeReleasePolicy)1 OidcPhoneScopeAttributeReleasePolicy (org.apereo.cas.oidc.claims.OidcPhoneScopeAttributeReleasePolicy)1 OidcProfileScopeAttributeReleasePolicy (org.apereo.cas.oidc.claims.OidcProfileScopeAttributeReleasePolicy)1 JsonServiceRegistryDao (org.apereo.cas.services.JsonServiceRegistryDao)1 OidcRegisteredService (org.apereo.cas.services.OidcRegisteredService)1 InCommonRSAttributeReleasePolicy (org.apereo.cas.support.saml.services.InCommonRSAttributeReleasePolicy)1 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)1 Test (org.junit.Test)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1