Search in sources :

Example 6 with AtLeastOneCredentialValidatedAuthenticationPolicy

use of org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy in project cas by apereo.

the class RegisteredServiceAuthenticationPolicyResolverTests method checkDefaultPolicy.

@Test
public void checkDefaultPolicy() {
    val resolver = new RegisteredServiceAuthenticationPolicyResolver(this.servicesManager, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    val transaction = new DefaultAuthenticationTransactionFactory().newTransaction(RegisteredServiceTestUtils.getService("serviceid2"), RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"));
    assertTrue(resolver.supports(transaction));
    val policies = resolver.resolve(transaction);
    assertFalse(policies.isEmpty());
    assertTrue(policies.iterator().next() instanceof AtLeastOneCredentialValidatedAuthenticationPolicy);
}
Also used : lombok.val(lombok.val) AtLeastOneCredentialValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy) RegisteredServiceAuthenticationPolicyResolver(org.apereo.cas.authentication.policy.RegisteredServiceAuthenticationPolicyResolver) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) Test(org.junit.jupiter.api.Test)

Example 7 with AtLeastOneCredentialValidatedAuthenticationPolicy

use of org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy in project cas by apereo.

the class RegisteredServiceAuthenticationPolicyResolverTests method checkAnyPolicy.

@Test
public void checkAnyPolicy() {
    val resolver = new RegisteredServiceAuthenticationPolicyResolver(this.servicesManager, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    val transaction = new DefaultAuthenticationTransactionFactory().newTransaction(RegisteredServiceTestUtils.getService("serviceid1"), RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"));
    val policies = resolver.resolve(transaction);
    assertEquals(1, policies.size());
    assertTrue(policies.iterator().next() instanceof AtLeastOneCredentialValidatedAuthenticationPolicy);
}
Also used : lombok.val(lombok.val) AtLeastOneCredentialValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy) RegisteredServiceAuthenticationPolicyResolver(org.apereo.cas.authentication.policy.RegisteredServiceAuthenticationPolicyResolver) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) Test(org.junit.jupiter.api.Test)

Example 8 with AtLeastOneCredentialValidatedAuthenticationPolicy

use of org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy in project cas by apereo.

the class DefaultAuthenticationManagerTests method verifyAuthenticateAnyFailureWithError.

@Test
public void verifyAuthenticateAnyFailureWithError() {
    val map = new LinkedHashMap<AuthenticationHandler, PrincipalResolver>();
    map.put(newMockHandler(false, true), null);
    map.put(newMockHandler(false, true), null);
    val authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
    authenticationExecutionPlan.registerAuthenticationPolicy(new AtLeastOneCredentialValidatedAuthenticationPolicy());
    val manager = new DefaultAuthenticationManager(authenticationExecutionPlan, false, applicationContext);
    assertThrows(AuthenticationException.class, () -> manager.authenticate(transaction));
}
Also used : lombok.val(lombok.val) AtLeastOneCredentialValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 9 with AtLeastOneCredentialValidatedAuthenticationPolicy

use of org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy in project cas by apereo.

the class DefaultAuthenticationManagerTests method verifyAuthenticateAnyFailure.

@Test
public void verifyAuthenticateAnyFailure() {
    val map = new LinkedHashMap<AuthenticationHandler, PrincipalResolver>();
    map.put(newMockHandler(false), null);
    map.put(newMockHandler(false), null);
    val authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
    authenticationExecutionPlan.registerAuthenticationPolicy(new AtLeastOneCredentialValidatedAuthenticationPolicy());
    val manager = new DefaultAuthenticationManager(authenticationExecutionPlan, false, applicationContext);
    assertThrows(AuthenticationException.class, () -> manager.authenticate(transaction));
}
Also used : lombok.val(lombok.val) AtLeastOneCredentialValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)9 AtLeastOneCredentialValidatedAuthenticationPolicy (org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy)9 Test (org.junit.jupiter.api.Test)8 LinkedHashMap (java.util.LinkedHashMap)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)2 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)2 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)2 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)2 RegisteredServiceAuthenticationPolicyResolver (org.apereo.cas.authentication.policy.RegisteredServiceAuthenticationPolicyResolver)2 Executable (org.junit.jupiter.api.function.Executable)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 Splitter (com.google.common.base.Splitter)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Multimap (com.google.common.collect.Multimap)1 GroovyClassLoader (groovy.lang.GroovyClassLoader)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1