Search in sources :

Example 1 with AllAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria

use of org.apereo.cas.services.AllAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria 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)1 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)1 AllAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria (org.apereo.cas.services.AllAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria)1 DefaultRegisteredServiceAuthenticationPolicy (org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy)1 MockServletContext (org.apereo.cas.util.MockServletContext)1 Test (org.junit.jupiter.api.Test)1 JEEContext (org.pac4j.core.context.JEEContext)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1 MockRequestContext (org.springframework.webflow.test.MockRequestContext)1