use of org.apereo.cas.authentication.policy.RequiredAuthenticationHandlerAuthenticationPolicy in project cas by apereo.
the class CoreAuthenticationUtils method newAuthenticationPolicy.
/**
* New authentication policy collection.
*
* @param policyProps the policy props
* @return the collection
*/
public static Collection<AuthenticationPolicy> newAuthenticationPolicy(final AuthenticationPolicyProperties policyProps) {
if (policyProps.getReq().isEnabled()) {
LOGGER.trace("Activating authentication policy [{}]", RequiredAuthenticationHandlerAuthenticationPolicy.class.getSimpleName());
val requiredHandlerNames = org.springframework.util.StringUtils.commaDelimitedListToSet(policyProps.getReq().getHandlerName());
var policy = new RequiredAuthenticationHandlerAuthenticationPolicy(requiredHandlerNames, policyProps.getReq().isTryAll());
return CollectionUtils.wrapList(policy);
}
if (policyProps.getAllHandlers().isEnabled()) {
LOGGER.trace("Activating authentication policy [{}]", AllAuthenticationHandlersSucceededAuthenticationPolicy.class.getSimpleName());
return CollectionUtils.wrapList(new AllAuthenticationHandlersSucceededAuthenticationPolicy());
}
if (policyProps.getAll().isEnabled()) {
LOGGER.trace("Activating authentication policy [{}]", AllCredentialsValidatedAuthenticationPolicy.class.getSimpleName());
return CollectionUtils.wrapList(new AllCredentialsValidatedAuthenticationPolicy());
}
if (policyProps.getNotPrevented().isEnabled()) {
LOGGER.trace("Activating authentication policy [{}]", NotPreventedAuthenticationPolicy.class.getSimpleName());
return CollectionUtils.wrapList(new NotPreventedAuthenticationPolicy());
}
if (!policyProps.getGroovy().isEmpty()) {
LOGGER.trace("Activating authentication policy [{}]", GroovyScriptAuthenticationPolicy.class.getSimpleName());
return policyProps.getGroovy().stream().map(groovy -> new GroovyScriptAuthenticationPolicy(groovy.getScript())).collect(Collectors.toList());
}
if (!policyProps.getRest().isEmpty()) {
LOGGER.trace("Activating authentication policy [{}]", RestfulAuthenticationPolicy.class.getSimpleName());
return policyProps.getRest().stream().map(RestfulAuthenticationPolicy::new).collect(Collectors.toList());
}
if (policyProps.getAny().isEnabled()) {
LOGGER.trace("Activating authentication policy [{}]", AtLeastOneCredentialValidatedAuthenticationPolicy.class.getSimpleName());
return CollectionUtils.wrapList(new AtLeastOneCredentialValidatedAuthenticationPolicy(policyProps.getAny().isTryAll()));
}
return new ArrayList<>();
}
use of org.apereo.cas.authentication.policy.RequiredAuthenticationHandlerAuthenticationPolicy in project cas by apereo.
the class AuthenticationPolicyAwareServiceTicketValidationAuthorizerTests method verifyRequiredHandlerAuthenticationPolicyTryAll.
@Test
public void verifyRequiredHandlerAuthenticationPolicyTryAll() {
val handler = getAcceptUsersAuthenticationHandler();
val handlers = List.of(getTestOtpAuthenticationHandler(), handler, getSimpleTestAuthenticationHandler());
val service = CoreAuthenticationTestUtils.getService("https://example.com/high/");
val authz = getAuthorizer(new RequiredAuthenticationHandlerAuthenticationPolicy(Set.of(handler.getName()), true), handlers);
val map = (Map) Map.of(new UsernamePasswordCredential(), handler, getOtpCredential(), getTestOtpAuthenticationHandler());
val assertion = getAssertion(map);
assertDoesNotThrow(new Executable() {
@Override
public void execute() {
authz.authorize(new MockHttpServletRequest(), service, assertion);
}
});
}
use of org.apereo.cas.authentication.policy.RequiredAuthenticationHandlerAuthenticationPolicy in project cas by apereo.
the class DefaultAuthenticationManagerTests method verifyAuthenticateRequiredHandlerTryAllSuccess.
@Test
public void verifyAuthenticateRequiredHandlerTryAllSuccess() {
val map = new LinkedHashMap<AuthenticationHandler, PrincipalResolver>();
map.put(newMockHandler(HANDLER_A, true), null);
map.put(newMockHandler(HANDLER_B, false), null);
val authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
authenticationExecutionPlan.registerAuthenticationPolicy(new RequiredAuthenticationHandlerAuthenticationPolicy(Set.of(HANDLER_A), true));
val manager = new DefaultAuthenticationManager(authenticationExecutionPlan, false, applicationContext);
val auth = manager.authenticate(transaction);
assertEquals(1, auth.getSuccesses().size());
assertEquals(1, auth.getFailures().size());
assertEquals(2, auth.getCredentials().size());
}
use of org.apereo.cas.authentication.policy.RequiredAuthenticationHandlerAuthenticationPolicy in project cas by apereo.
the class AuthenticationPolicyAwareServiceTicketValidationAuthorizerTests method verifyRequiredHandlerAuthenticationPolicy.
@Test
public void verifyRequiredHandlerAuthenticationPolicy() {
val handler = getAcceptUsersAuthenticationHandler();
val handlers = List.of(getTestOtpAuthenticationHandler(), handler, getSimpleTestAuthenticationHandler());
val service = CoreAuthenticationTestUtils.getService("https://example.com/high/");
val authz = getAuthorizer(new RequiredAuthenticationHandlerAuthenticationPolicy(handler.getName()), handlers);
val map = (Map) Map.of(new UsernamePasswordCredential(), handler, getOtpCredential(), getTestOtpAuthenticationHandler());
val assertion = getAssertion(map);
assertDoesNotThrow(new Executable() {
@Override
public void execute() {
authz.authorize(new MockHttpServletRequest(), service, assertion);
}
});
}
use of org.apereo.cas.authentication.policy.RequiredAuthenticationHandlerAuthenticationPolicy in project cas by apereo.
the class DefaultAuthenticationManagerTests method verifyTransactionWithAuthnHistoryAndAuthnPolicy.
@Test
public void verifyTransactionWithAuthnHistoryAndAuthnPolicy() {
val map = new LinkedHashMap<AuthenticationHandler, PrincipalResolver>();
map.put(newMockHandler(true), null);
val authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
val policy = new RequiredAuthenticationHandlerAuthenticationPolicy(SimpleTestUsernamePasswordAuthenticationHandler.class.getSimpleName());
authenticationExecutionPlan.registerAuthenticationPolicy(policy);
val manager = new DefaultAuthenticationManager(authenticationExecutionPlan, false, applicationContext);
val testTransaction = new DefaultAuthenticationTransactionFactory().newTransaction(CoreAuthenticationTestUtils.getService(), mock(Credential.class, withSettings().serializable()));
testTransaction.collect(List.of(CoreAuthenticationTestUtils.getAuthentication()));
assertNotNull(manager.authenticate(testTransaction));
}
Aggregations