Search in sources :

Example 6 with SingleSignOnProperties

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

the class DefaultSingleSignOnParticipationStrategyTests method verifyRegisteredServiceWithValidSsoAndServiceExpPolicy.

@Test
public void verifyRegisteredServiceWithValidSsoAndServiceExpPolicy() {
    val mgr = mock(ServicesManager.class);
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
    when(registeredService.getAccessStrategy().isServiceAccessAllowedForSso()).thenReturn(true);
    when(registeredService.getTicketGrantingTicketExpirationPolicy()).thenReturn(new DefaultRegisteredServiceTicketGrantingTicketExpirationPolicy(1));
    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");
    tgt.setCreated(ZonedDateTime.now(ZoneOffset.UTC).minusHours(1));
    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();
    assertFalse(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultRegisteredServiceTicketGrantingTicketExpirationPolicy(org.apereo.cas.services.DefaultRegisteredServiceTicketGrantingTicketExpirationPolicy) 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)

Example 7 with SingleSignOnProperties

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

the class DefaultSingleSignOnParticipationStrategyTests method verifyRegisteredServiceFromContextEvaluatedBeforeService.

@Test
public void verifyRegisteredServiceFromContextEvaluatedBeforeService() {
    val mgr = mock(ServicesManager.class);
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
    val callbackRegisteredService = CoreAuthenticationTestUtils.getRegisteredService("https://cas/idp/profile/SAML2/Callback");
    when(registeredService.getAccessStrategy().isServiceAccessAllowedForSso()).thenReturn(false);
    when(callbackRegisteredService.getAccessStrategy().isServiceAccessAllowedForSso()).thenReturn(true);
    when(mgr.findServiceBy(any(Service.class))).thenReturn(callbackRegisteredService);
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val sso = new SingleSignOnProperties().setCreateSsoCookieOnRenewAuthn(false).setRenewAuthnEnabled(true);
    val strategy = new DefaultSingleSignOnParticipationStrategy(mgr, sso, mock(TicketRegistrySupport.class), 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);
    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) Service(org.apereo.cas.authentication.principal.Service) 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 8 with SingleSignOnProperties

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

the class DefaultSingleSignOnParticipationStrategyTests method verifyParticipatesForRenewDisabled.

@Test
public void verifyParticipatesForRenewDisabled() {
    val mgr = mock(ServicesManager.class);
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val sso = new SingleSignOnProperties().setCreateSsoCookieOnRenewAuthn(false).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();
    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 9 with SingleSignOnProperties

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

the class DefaultSingleSignOnParticipationStrategyTests method verifyDoesNotParticipateForService.

@Test
public void verifyDoesNotParticipateForService() {
    val mgr = mock(ServicesManager.class);
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
    when(registeredService.getAccessStrategy().isServiceAccessAllowedForSso()).thenReturn(false);
    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();
    assertFalse(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Service(org.apereo.cas.authentication.principal.Service) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) 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