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());
}
}
}
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));
}
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());
}
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());
}
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"));
}
Aggregations