Search in sources :

Example 1 with SingleSignOnProperties

use of org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties in project cas by apereo.

the class InitialFlowSetupCookieActionTests method initialize.

@BeforeEach
public void initialize() throws Exception {
    val warn = CookieGenerationContext.builder().name("warn").path(StringUtils.EMPTY).maxAge(2).domain(null).secure(false).httpOnly(false).comment("CAS Cookie").build();
    val tgt = CookieGenerationContext.builder().name("tgt").path(StringUtils.EMPTY).maxAge(2).domain(null).secure(false).httpOnly(false).comment("CAS Cookie").build();
    this.warnCookieGenerator = new CookieRetrievingCookieGenerator(warn);
    this.warnCookieGenerator.setCookiePath(StringUtils.EMPTY);
    this.tgtCookieGenerator = new CookieRetrievingCookieGenerator(tgt);
    this.tgtCookieGenerator.setCookiePath(StringUtils.EMPTY);
    val argExtractors = Collections.<ArgumentExtractor>singletonList(new DefaultArgumentExtractor(new WebApplicationServiceFactory()));
    val servicesManager = mock(ServicesManager.class);
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(RegisteredServiceTestUtils.getRegisteredService("test"));
    val sso = new SingleSignOnProperties().setCreateSsoCookieOnRenewAuthn(true).setRenewAuthnEnabled(true);
    this.action = new InitialFlowSetupAction(argExtractors, servicesManager, authenticationRequestServiceSelectionStrategies, tgtCookieGenerator, warnCookieGenerator, casProperties, authenticationEventExecutionPlan, new DefaultSingleSignOnParticipationStrategy(servicesManager, sso, mock(TicketRegistrySupport.class), mock(AuthenticationServiceSelectionPlan.class)), mock(TicketRegistrySupport.class));
    this.action.afterPropertiesSet();
}
Also used : lombok.val(lombok.val) ArgumentExtractor(org.apereo.cas.web.support.ArgumentExtractor) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) CookieRetrievingCookieGenerator(org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) Service(org.apereo.cas.authentication.principal.Service) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) InitialFlowSetupAction(org.apereo.cas.web.flow.login.InitialFlowSetupAction) SingleSignOnProperties(org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SingleSignOnProperties

use of org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties 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 3 with SingleSignOnProperties

use of org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties in project cas by apereo.

the class DefaultSingleSignOnParticipationStrategyTests method verifyParticipationDisabled.

@Test
public void verifyParticipationDisabled() {
    val mgr = mock(ServicesManager.class);
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val sso = new SingleSignOnProperties().setSsoEnabled(false);
    val strategy = new DefaultSingleSignOnParticipationStrategy(mgr, sso, mock(TicketRegistrySupport.class), mock(AuthenticationServiceSelectionPlan.class));
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertFalse(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) SingleSignOnProperties(org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties) Test(org.junit.jupiter.api.Test)

Example 4 with SingleSignOnProperties

use of org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties in project cas by apereo.

the class DefaultSingleSignOnParticipationStrategyTests method verifyParticipatesForRenew.

@Test
public void verifyParticipatesForRenew() {
    val mgr = mock(ServicesManager.class);
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val sso = new SingleSignOnProperties().setCreateSsoCookieOnRenewAuthn(true).setRenewAuthnEnabled(true);
    val strategy = new DefaultSingleSignOnParticipationStrategy(mgr, sso, mock(TicketRegistrySupport.class), mock(AuthenticationServiceSelectionPlan.class));
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.isParticipating(ssoRequest) || strategy.isCreateCookieOnRenewedAuthentication(ssoRequest) == TriStateBoolean.TRUE);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) SingleSignOnProperties(org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties) Test(org.junit.jupiter.api.Test)

Example 5 with SingleSignOnProperties

use of org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties in project cas by apereo.

the class DefaultSingleSignOnParticipationStrategyTests method verifyRegisteredServiceWithValidSso.

@Test
public void verifyRegisteredServiceWithValidSso() {
    val mgr = mock(ServicesManager.class);
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
    when(registeredService.getAccessStrategy().isServiceAccessAllowedForSso()).thenReturn(true);
    when(registeredService.getSingleSignOnParticipationPolicy()).thenReturn(new DefaultRegisteredServiceSingleSignOnParticipationPolicy());
    when(mgr.findServiceBy(any(Service.class))).thenReturn(registeredService);
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val tgt = new MockTicketGrantingTicket("casuser");
    val sso = new SingleSignOnProperties();
    val ticketRegistrySupport = mock(TicketRegistrySupport.class);
    when(ticketRegistrySupport.getTicket(anyString())).thenReturn(tgt);
    val strategy = new DefaultSingleSignOnParticipationStrategy(mgr, sso, ticketRegistrySupport, mock(AuthenticationServiceSelectionPlan.class));
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    WebUtils.putRegisteredService(context, registeredService);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication("casuser"), context);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) DefaultRegisteredServiceSingleSignOnParticipationPolicy(org.apereo.cas.services.DefaultRegisteredServiceSingleSignOnParticipationPolicy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Service(org.apereo.cas.authentication.principal.Service) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) SingleSignOnProperties(org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)9 SingleSignOnProperties (org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties)9 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)8 Test (org.junit.jupiter.api.Test)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 MockServletContext (org.springframework.mock.web.MockServletContext)8 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)8 MockRequestContext (org.springframework.webflow.test.MockRequestContext)8 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)7 TicketRegistrySupport (org.apereo.cas.ticket.registry.TicketRegistrySupport)7 Service (org.apereo.cas.authentication.principal.Service)6 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)2 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)2 DefaultRegisteredServiceSingleSignOnParticipationPolicy (org.apereo.cas.services.DefaultRegisteredServiceSingleSignOnParticipationPolicy)2 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)1 DefaultRegisteredServiceTicketGrantingTicketExpirationPolicy (org.apereo.cas.services.DefaultRegisteredServiceTicketGrantingTicketExpirationPolicy)1 InitialFlowSetupAction (org.apereo.cas.web.flow.login.InitialFlowSetupAction)1 ArgumentExtractor (org.apereo.cas.web.support.ArgumentExtractor)1 DefaultArgumentExtractor (org.apereo.cas.web.support.DefaultArgumentExtractor)1