Search in sources :

Example 16 with ReturnAllowedAttributeReleasePolicy

use of org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy in project cas by apereo.

the class DefaultAttributeReleasePolicyMapper method mapAttributeReleasePolicy.

@Override
public void mapAttributeReleasePolicy(final RegisteredServiceAttributeReleasePolicy policy, final RegisteredServiceEditBean.ServiceData bean) {
    if (policy instanceof AbstractRegisteredServiceAttributeReleasePolicy) {
        final AbstractRegisteredServiceAttributeReleasePolicy attrPolicy = (AbstractRegisteredServiceAttributeReleasePolicy) policy;
        final RegisteredServiceAttributeReleasePolicyEditBean attrPolicyBean = bean.getAttrRelease();
        attrPolicyBean.setReleasePassword(attrPolicy.isAuthorizedToReleaseCredentialPassword());
        attrPolicyBean.setReleaseTicket(attrPolicy.isAuthorizedToReleaseProxyGrantingTicket());
        attrPolicyBean.setExcludeDefault(attrPolicy.isExcludeDefaultAttributes());
        this.attributeFilterMapper.mapAttributeFilter(attrPolicy.getAttributeFilter(), bean);
        this.principalAttributesRepositoryMapper.mapPrincipalRepository(attrPolicy.getPrincipalAttributesRepository(), bean);
        final RegisteredServiceAttributeReleasePolicyStrategyEditBean sBean = attrPolicyBean.getAttrPolicy();
        if (attrPolicy instanceof ScriptedRegisteredServiceAttributeReleasePolicy) {
            final ScriptedRegisteredServiceAttributeReleasePolicy policyS = (ScriptedRegisteredServiceAttributeReleasePolicy) attrPolicy;
            sBean.setType(AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.SCRIPT.toString());
            sBean.setScriptFile(policyS.getScriptFile());
        } else if (attrPolicy instanceof GroovyScriptAttributeReleasePolicy) {
            final GroovyScriptAttributeReleasePolicy policyG = (GroovyScriptAttributeReleasePolicy) attrPolicy;
            sBean.setScriptFile(policyG.getGroovyScript());
            sBean.setType(AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.GROOVY.toString());
        } else if (attrPolicy instanceof ReturnAllAttributeReleasePolicy) {
            sBean.setType(AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.ALL.toString());
        } else if (attrPolicy instanceof ReturnAllowedAttributeReleasePolicy) {
            final ReturnAllowedAttributeReleasePolicy attrPolicyAllowed = (ReturnAllowedAttributeReleasePolicy) attrPolicy;
            sBean.setType(AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.ALLOWED.toString());
            sBean.setAttributes(attrPolicyAllowed.getAllowedAttributes());
        } else if (attrPolicy instanceof ReturnMappedAttributeReleasePolicy) {
            final ReturnMappedAttributeReleasePolicy attrPolicyAllowed = (ReturnMappedAttributeReleasePolicy) attrPolicy;
            sBean.setType(AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.MAPPED.toString());
            sBean.setAttributes(attrPolicyAllowed.getAllowedAttributes());
        } else if (attrPolicy instanceof DenyAllAttributeReleasePolicy) {
            sBean.setType(AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.DENY.toString());
        }
    }
}
Also used : RegisteredServiceAttributeReleasePolicyStrategyEditBean(org.apereo.cas.mgmt.services.web.beans.RegisteredServiceAttributeReleasePolicyStrategyEditBean) DenyAllAttributeReleasePolicy(org.apereo.cas.services.DenyAllAttributeReleasePolicy) ReturnAllAttributeReleasePolicy(org.apereo.cas.services.ReturnAllAttributeReleasePolicy) ScriptedRegisteredServiceAttributeReleasePolicy(org.apereo.cas.services.ScriptedRegisteredServiceAttributeReleasePolicy) AbstractRegisteredServiceAttributeReleasePolicy(org.apereo.cas.services.AbstractRegisteredServiceAttributeReleasePolicy) ReturnAllowedAttributeReleasePolicy(org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy) GroovyScriptAttributeReleasePolicy(org.apereo.cas.services.GroovyScriptAttributeReleasePolicy) ReturnMappedAttributeReleasePolicy(org.apereo.cas.services.ReturnMappedAttributeReleasePolicy) RegisteredServiceAttributeReleasePolicyEditBean(org.apereo.cas.mgmt.services.web.beans.RegisteredServiceAttributeReleasePolicyEditBean)

Example 17 with ReturnAllowedAttributeReleasePolicy

use of org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy in project cas by apereo.

the class CasConsentReviewConfiguration method configureServiceRegistry.

@Override
public void configureServiceRegistry(final ServiceRegistryExecutionPlan plan) {
    final RegexRegisteredService service = new RegexRegisteredService();
    service.setEvaluationOrder(0);
    service.setName("CAS Consent Review");
    service.setDescription("Review consent decisions for attribute release");
    service.setServiceId(consentCallbackService().getId());
    final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
    final DefaultRegisteredServiceConsentPolicy consentPolicy = new DefaultRegisteredServiceConsentPolicy();
    consentPolicy.setEnabled(false);
    policy.setConsentPolicy(consentPolicy);
    service.setAttributeReleasePolicy(policy);
    LOGGER.debug("Saving consent service [{}] into the registry", service);
    plan.registerServiceRegistry(new ConsentServiceRegistry(service));
}
Also used : DefaultRegisteredServiceConsentPolicy(org.apereo.cas.services.consent.DefaultRegisteredServiceConsentPolicy) ReturnAllowedAttributeReleasePolicy(org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) ConsentServiceRegistry(org.apereo.cas.consent.services.ConsentServiceRegistry)

Example 18 with ReturnAllowedAttributeReleasePolicy

use of org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy in project cas by apereo.

the class DefaultAuthenticationAttributeReleasePolicyTests method verifyNoRelease.

@Test
public void verifyNoRelease() {
    val policy = new DefaultAuthenticationAttributeReleasePolicy("authnContext");
    val service = CoreAuthenticationTestUtils.getRegisteredService();
    val attrPolicy = new ReturnAllowedAttributeReleasePolicy();
    attrPolicy.setAuthorizedToReleaseAuthenticationAttributes(false);
    when(service.getAttributeReleasePolicy()).thenReturn(attrPolicy);
    assertTrue(policy.getAuthenticationAttributesForRelease(CoreAuthenticationTestUtils.getAuthentication(), mock(Assertion.class), Map.of(), service).isEmpty());
}
Also used : lombok.val(lombok.val) ReturnAllowedAttributeReleasePolicy(org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy) Assertion(org.apereo.cas.validation.Assertion) Test(org.junit.jupiter.api.Test)

Example 19 with ReturnAllowedAttributeReleasePolicy

use of org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy in project cas by apereo.

the class DefaultAuthenticationAttributeReleasePolicyTests method verifyNoReleaseCredential.

@Test
public void verifyNoReleaseCredential() {
    val policy = new DefaultAuthenticationAttributeReleasePolicy("authnContext");
    policy.getOnlyReleaseAttributes().add(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_AUTHENTICATION_DATE);
    val service = CoreAuthenticationTestUtils.getRegisteredService();
    val attrPolicy = new ReturnAllowedAttributeReleasePolicy();
    attrPolicy.setAuthorizedToReleaseCredentialPassword(false);
    when(service.getAttributeReleasePolicy()).thenReturn(attrPolicy);
    val authentication = CoreAuthenticationTestUtils.getAuthentication(Map.of(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL_CREDENTIAL, List.of("Password")));
    assertFalse(policy.getAuthenticationAttributesForRelease(authentication, mock(Assertion.class), Map.of(), service).isEmpty());
}
Also used : lombok.val(lombok.val) ReturnAllowedAttributeReleasePolicy(org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy) Assertion(org.apereo.cas.validation.Assertion) Test(org.junit.jupiter.api.Test)

Example 20 with ReturnAllowedAttributeReleasePolicy

use of org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy in project cas by apereo.

the class DefaultAuthenticationAttributeReleasePolicyTests method verifyReleaseAll.

@Test
public void verifyReleaseAll() {
    val policy = new DefaultAuthenticationAttributeReleasePolicy(Set.of(), Set.of(), "authnContext");
    val service = CoreAuthenticationTestUtils.getRegisteredService();
    val attrPolicy = new ReturnAllowedAttributeReleasePolicy();
    when(service.getAttributeReleasePolicy()).thenReturn(attrPolicy);
    val results = policy.getAuthenticationAttributesForRelease(CoreAuthenticationTestUtils.getAuthentication(CoreAuthenticationTestUtils.getPrincipal(), Map.of("cn", List.of("common-name"), "givenName", List.of("given-name"))), mock(Assertion.class), Map.of("authnContext", List.of("mfa-something")), service);
    assertEquals(6, results.size());
    assertTrue(results.containsKey("cn"));
    assertTrue(results.containsKey("givenName"));
    assertTrue(results.containsKey(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_AUTHENTICATION_DATE));
    assertTrue(results.containsKey(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_FROM_NEW_LOGIN));
    assertTrue(results.containsKey(CasProtocolConstants.VALIDATION_REMEMBER_ME_ATTRIBUTE_NAME));
    assertTrue(results.containsKey("authnContext"));
}
Also used : lombok.val(lombok.val) ReturnAllowedAttributeReleasePolicy(org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy) Assertion(org.apereo.cas.validation.Assertion) Test(org.junit.jupiter.api.Test)

Aggregations

ReturnAllowedAttributeReleasePolicy (org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy)20 lombok.val (lombok.val)9 Test (org.junit.jupiter.api.Test)8 DefaultRegisteredServiceUsernameProvider (org.apereo.cas.services.DefaultRegisteredServiceUsernameProvider)5 ReturnAllAttributeReleasePolicy (org.apereo.cas.services.ReturnAllAttributeReleasePolicy)5 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)5 RegexMatchingRegisteredServiceProxyPolicy (org.apereo.cas.services.RegexMatchingRegisteredServiceProxyPolicy)4 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)4 AbstractRegisteredService (org.apereo.cas.services.AbstractRegisteredService)3 AbstractRegisteredServiceAttributeReleasePolicy (org.apereo.cas.services.AbstractRegisteredServiceAttributeReleasePolicy)3 DefaultRegisteredServiceAccessStrategy (org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy)3 DenyAllAttributeReleasePolicy (org.apereo.cas.services.DenyAllAttributeReleasePolicy)3 GroovyScriptAttributeReleasePolicy (org.apereo.cas.services.GroovyScriptAttributeReleasePolicy)3 RegisteredService (org.apereo.cas.services.RegisteredService)3 ReturnMappedAttributeReleasePolicy (org.apereo.cas.services.ReturnMappedAttributeReleasePolicy)3 ScriptedRegisteredServiceAttributeReleasePolicy (org.apereo.cas.services.ScriptedRegisteredServiceAttributeReleasePolicy)3 Assertion (org.apereo.cas.validation.Assertion)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2