Search in sources :

Example 11 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy 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 12 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy in project cas by apereo.

the class RegisteredServiceAuthenticationPolicyResolverTests method checkGroovyPolicy.

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

Example 13 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy in project cas by apereo.

the class RegisteredServiceAuthenticationPolicyResolverTests method checkAllPolicy.

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

Example 14 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy in project cas by apereo.

the class DefaultSingleSignOnParticipationStrategyTests method verifyCookieCreationByService.

@Test
public void verifyCookieCreationByService() {
    val mgr = mock(ServicesManager.class);
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
    val policy = new DefaultRegisteredServiceSingleSignOnParticipationPolicy();
    policy.setCreateCookieOnRenewedAuthentication(TriStateBoolean.FALSE);
    when(registeredService.getSingleSignOnParticipationPolicy()).thenReturn(policy);
    when(mgr.findServiceBy(any(Service.class))).thenReturn(registeredService);
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    val plan = new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy());
    val sso = new SingleSignOnProperties().setCreateSsoCookieOnRenewAuthn(false).setRenewAuthnEnabled(true);
    val strategy = new DefaultSingleSignOnParticipationStrategy(mgr, sso, mock(TicketRegistrySupport.class), plan);
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication("casuser"), context);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    val create = strategy.isCreateCookieOnRenewedAuthentication(ssoRequest);
    assertTrue(create.isFalse());
}
Also used : lombok.val(lombok.val) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Service(org.apereo.cas.authentication.principal.Service) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) DefaultRegisteredServiceSingleSignOnParticipationPolicy(org.apereo.cas.services.DefaultRegisteredServiceSingleSignOnParticipationPolicy) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SingleSignOnProperties(org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties) Test(org.junit.jupiter.api.Test)

Example 15 with DefaultAuthenticationServiceSelectionStrategy

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy in project cas by apereo.

the class LogoutManagerImplTests method setUp.

@Before
public void setUp() {
    when(client.isValidEndPoint(any(String.class))).thenReturn(true);
    when(client.isValidEndPoint(any(URL.class))).thenReturn(true);
    when(client.sendMessageToEndPoint(any(HttpMessage.class))).thenReturn(true);
    singleLogoutServiceMessageHandler = new DefaultSingleLogoutServiceMessageHandler(client, new SamlCompliantLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(), true, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    final Map<String, Service> services = new HashMap<>();
    this.simpleWebApplicationServiceImpl = RegisteredServiceTestUtils.getService(URL);
    services.put(ID, this.simpleWebApplicationServiceImpl);
    when(this.tgt.getServices()).thenReturn(services);
    this.logoutManager = new LogoutManagerImpl(new SamlCompliantLogoutMessageCreator(), singleLogoutServiceMessageHandler, false);
    this.registeredService = RegisteredServiceTestUtils.getRegisteredService(URL);
    when(servicesManager.findServiceBy(this.simpleWebApplicationServiceImpl)).thenReturn(this.registeredService);
}
Also used : DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) HashMap(java.util.HashMap) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Service(org.apereo.cas.authentication.principal.Service) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) HttpMessage(org.apereo.cas.util.http.HttpMessage) URL(java.net.URL) Before(org.junit.Before)

Aggregations

DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)25 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)25 lombok.val (lombok.val)19 Test (org.junit.jupiter.api.Test)13 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)9 RegisteredServiceAuthenticationPolicyResolver (org.apereo.cas.authentication.policy.RegisteredServiceAuthenticationPolicyResolver)7 Service (org.apereo.cas.authentication.principal.Service)7 Before (org.junit.Before)5 HashMap (java.util.HashMap)4 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)4 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)4 URL (java.net.URL)3 HashSet (java.util.HashSet)3 AuditableExecutionResult (org.apereo.cas.audit.AuditableExecutionResult)3 SimpleUrlValidatorFactoryBean (org.apereo.cas.web.SimpleUrlValidatorFactoryBean)3 MockRequestContext (org.springframework.webflow.test.MockRequestContext)3 ArrayList (java.util.ArrayList)2