Search in sources :

Example 1 with DefaultRegisteredServiceAuthenticationPolicy

use of org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy in project cas by apereo.

the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifySsoWithHandlers.

@Test
public void verifySsoWithHandlers() throws Exception {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
    val policy = new DefaultRegisteredServiceAuthenticationPolicy();
    policy.setRequiredAuthenticationHandlers(Set.of(SimpleTestUsernamePasswordAuthenticationHandler.class.getSimpleName()));
    svc.setAuthenticationPolicy(policy);
    val ticketRegistry = new DefaultTicketRegistry();
    val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService("serviceid1"));
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.supports(ssoRequest));
    assertTrue(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTicketRegistry(org.apereo.cas.ticket.registry.DefaultTicketRegistry) DefaultRegisteredServiceAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultRegisteredServiceAuthenticationPolicy

use of org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy in project cas by apereo.

the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifySsoWithExcludedHandlers.

@Test
public void verifySsoWithExcludedHandlers() throws Exception {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
    val policy = new DefaultRegisteredServiceAuthenticationPolicy();
    policy.setCriteria(new ExcludedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria());
    policy.setExcludedAuthenticationHandlers(Set.of(SimpleTestUsernamePasswordAuthenticationHandler.class.getName()));
    svc.setAuthenticationPolicy(policy);
    val ticketRegistry = new DefaultTicketRegistry();
    val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService("serviceid1"));
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.supports(ssoRequest));
    assertFalse(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTicketRegistry(org.apereo.cas.ticket.registry.DefaultTicketRegistry) DefaultRegisteredServiceAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ExcludedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria(org.apereo.cas.services.ExcludedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultRegisteredServiceAuthenticationPolicy

use of org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy in project cas by apereo.

the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifyNoServiceOrPolicy.

@Test
public void verifyNoServiceOrPolicy() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
    val policy = new DefaultRegisteredServiceAuthenticationPolicy();
    policy.setCriteria(null);
    svc.setAuthenticationPolicy(policy);
    val ticketRegistry = new DefaultTicketRegistry();
    val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.isParticipating(ssoRequest));
    WebUtils.putRegisteredService(context, svc);
    assertEquals(0, strategy.getOrder());
    assertFalse(strategy.supports(ssoRequest));
    svc.setAuthenticationPolicy(null);
    assertTrue(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTicketRegistry(org.apereo.cas.ticket.registry.DefaultTicketRegistry) DefaultRegisteredServiceAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultRegisteredServiceAuthenticationPolicy

use of org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy in project cas by apereo.

the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifySsoWithMismatchedHandlers.

@Test
public void verifySsoWithMismatchedHandlers() throws Exception {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
    val policy = new DefaultRegisteredServiceAuthenticationPolicy();
    policy.setRequiredAuthenticationHandlers(Set.of("SomeOtherHandler"));
    policy.setCriteria(new AllowedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria());
    svc.setAuthenticationPolicy(policy);
    val ticketRegistry = new DefaultTicketRegistry();
    val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService("serviceid1"));
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
    assertTrue(strategy.supports(ssoRequest));
    assertFalse(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTicketRegistry(org.apereo.cas.ticket.registry.DefaultTicketRegistry) DefaultRegisteredServiceAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy) MockRequestContext(org.springframework.webflow.test.MockRequestContext) AllowedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria(org.apereo.cas.services.AllowedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultRegisteredServiceAuthenticationPolicy

use of org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy in project cas by apereo.

the class DelegatedClientAuthenticationActionTests method verifySsoAuthenticationWithUnauthorizedSso.

@Test
public void verifySsoAuthenticationWithUnauthorizedSso() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val client = builtClients.findClient("FacebookClient").get();
    val webContext = new JEEContext(request, new MockHttpServletResponse());
    request.setParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient");
    val service = CoreAuthenticationTestUtils.getService("https://delegated2-authn-policy.example.org");
    val registeredService = RegisteredServiceTestUtils.getRegisteredService(service.getId(), Map.of());
    val authenticationPolicy = new DefaultRegisteredServiceAuthenticationPolicy();
    authenticationPolicy.setRequiredAuthenticationHandlers(Set.of("DelegatedClientAuthenticationHandler"));
    authenticationPolicy.setCriteria(new AllAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria());
    registeredService.setAuthenticationPolicy(authenticationPolicy);
    servicesManager.save(registeredService);
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
    val ticket = delegatedClientAuthenticationWebflowManager.store(webContext, client);
    request.addParameter(DefaultDelegatedClientAuthenticationWebflowManager.PARAMETER_CLIENT_ID, ticket.getId());
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    setRequestContext(context);
    setExternalContext(context.getExternalContext());
    val tgt = new MockTicketGrantingTicket("casuser");
    centralAuthenticationService.addTicket(tgt);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, delegatedAuthenticationAction.execute(context).getId());
    assertThrows(InvalidTicketException.class, () -> centralAuthenticationService.getTicket(tgt.getId()));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) AllAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria(org.apereo.cas.services.AllAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) JEEContext(org.pac4j.core.context.JEEContext) DefaultRegisteredServiceAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)5 DefaultRegisteredServiceAuthenticationPolicy (org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy)5 Test (org.junit.jupiter.api.Test)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)5 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)5 MockRequestContext (org.springframework.webflow.test.MockRequestContext)5 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)4 DefaultTicketRegistry (org.apereo.cas.ticket.registry.DefaultTicketRegistry)4 MockServletContext (org.springframework.mock.web.MockServletContext)4 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)3 AllAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria (org.apereo.cas.services.AllAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria)1 AllowedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria (org.apereo.cas.services.AllowedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria)1 ExcludedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria (org.apereo.cas.services.ExcludedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria)1 MockServletContext (org.apereo.cas.util.MockServletContext)1 JEEContext (org.pac4j.core.context.JEEContext)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1