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();
}
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());
}
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));
}
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);
}
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));
}
Aggregations