Search in sources :

Example 91 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket 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 92 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class ServiceTicketRequestWebflowEventResolverTests method verifyAttemptWithoutCredential.

@Test
public void verifyAttemptWithoutCredential() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    val service = RegisteredServiceTestUtils.getService("service-ticket-request");
    val registeredService = RegisteredServiceTestUtils.getRegisteredService(service.getId(), Map.of());
    servicesManager.save(registeredService);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    WebUtils.putServiceIntoFlowScope(context, service);
    val event = serviceTicketRequestWebflowEventResolver.resolveSingle(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_GENERATE_SERVICE_TICKET, event.getId());
}
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) 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 93 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class ServiceTicketRequestWebflowEventResolverTests method verifyServiceTicketRequestFailsAuthN.

@Test
public void verifyServiceTicketRequestFailsAuthN() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    val service = RegisteredServiceTestUtils.getService("service-ticket-request");
    val registeredService = RegisteredServiceTestUtils.getRegisteredService(service.getId());
    registeredService.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(true, true));
    servicesManager.save(registeredService);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    WebUtils.putServiceIntoFlowScope(context, service);
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "badP@ass"));
    val event = serviceTicketRequestWebflowEventResolver.resolveSingle(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, event.getId());
}
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) MockRequestContext(org.springframework.webflow.test.MockRequestContext) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 94 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class ServiceTicketRequestWebflowEventResolverTests method verifyServiceTicketRequestCreated.

@Test
public void verifyServiceTicketRequestCreated() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    val service = RegisteredServiceTestUtils.getService("service-ticket-request");
    val registeredService = RegisteredServiceTestUtils.getRegisteredService(service.getId());
    registeredService.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(true, true));
    servicesManager.save(registeredService);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    WebUtils.putServiceIntoFlowScope(context, service);
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon"));
    val event = serviceTicketRequestWebflowEventResolver.resolveSingle(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_GENERATE_SERVICE_TICKET, event.getId());
}
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) MockRequestContext(org.springframework.webflow.test.MockRequestContext) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 95 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class ServiceTicketRequestWebflowEventResolverTests method verifyServiceTicketRequestPrincipalMismatch.

@Test
public void verifyServiceTicketRequestPrincipalMismatch() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val tgt = new MockTicketGrantingTicket("randomuser");
    ticketRegistry.addTicket(tgt);
    val service = RegisteredServiceTestUtils.getService("service-ticket-request");
    val registeredService = RegisteredServiceTestUtils.getRegisteredService(service.getId());
    registeredService.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(true, true));
    servicesManager.save(registeredService);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    WebUtils.putServiceIntoFlowScope(context, service);
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon"));
    assertNull(serviceTicketRequestWebflowEventResolver.resolveSingle(context));
}
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) MockRequestContext(org.springframework.webflow.test.MockRequestContext) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)224 lombok.val (lombok.val)199 Test (org.junit.jupiter.api.Test)164 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)93 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)92 MockRequestContext (org.springframework.webflow.test.MockRequestContext)42 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)39 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)36 JEEContext (org.pac4j.core.context.JEEContext)33 MockServletContext (org.springframework.mock.web.MockServletContext)33 HashMap (java.util.HashMap)31 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)18 Test (org.junit.Test)18 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)13 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)12 CasProfile (org.pac4j.cas.profile.CasProfile)11 Authentication (org.apereo.cas.authentication.Authentication)10 HardTimeoutExpirationPolicy (org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy)10 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)10 RedirectView (org.springframework.web.servlet.view.RedirectView)10