Search in sources :

Example 61 with MockTicketGrantingTicket

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

the class SamlIdPConsentSingleSignOnParticipationStrategyTests method verifyIdPNeedsConsentOperation.

@Test
public void verifyIdPNeedsConsentOperation() {
    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 principal = RegisteredServiceTestUtils.getPrincipal("casuser", CollectionUtils.wrap("uid", "CAS-System"));
    val authn = RegisteredServiceTestUtils.getAuthentication(principal);
    val cookie = new MockTicketGrantingTicket(authn);
    val issuer = UUID.randomUUID().toString();
    val registeredService = SamlIdPTestUtils.getSamlRegisteredService(issuer);
    registeredService.setAttributeReleasePolicy(new ReturnAllowedAttributeReleasePolicy(List.of("uid")));
    val service = RegisteredServiceTestUtils.getService(issuer);
    val authnRequest = getAuthnRequestFor(issuer);
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build().attribute(AuthnRequest.class.getName(), authnRequest).attribute(Issuer.class.getName(), issuer).attribute(Service.class.getName(), service).attribute(RegisteredService.class.getName(), registeredService).attribute(Authentication.class.getName(), authn).attribute(TicketGrantingTicket.class.getName(), cookie);
    assertFalse(singleSignOnParticipationStrategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) RegisteredService(org.apereo.cas.services.RegisteredService) Issuer(org.opensaml.saml.saml2.core.Issuer) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) ReturnAllowedAttributeReleasePolicy(org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) 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 62 with MockTicketGrantingTicket

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

the class SamlIdPSingleLogoutServiceMessageHandlerTests method verifySkipLogoutForOriginator.

@Test
public void verifySkipLogoutForOriginator() throws Exception {
    val service = RegisteredServiceTestUtils.getService("https://mocky.io");
    service.getAttributes().put(SamlProtocolConstants.PARAMETER_ENTITY_ID, CollectionUtils.wrapList(samlRegisteredService.getServiceId()));
    val request = new MockHttpServletRequest();
    val logoutRequest = samlIdPLogoutResponseObjectBuilder.newLogoutRequest(UUID.randomUUID().toString(), ZonedDateTime.now(Clock.systemUTC()), "https://github.com/apereo/cas", samlIdPLogoutResponseObjectBuilder.newIssuer(service.getId()), UUID.randomUUID().toString(), samlIdPLogoutResponseObjectBuilder.getNameID(NameID.EMAIL, "cas@example.org"));
    try (val writer = SamlUtils.transformSamlObject(openSamlConfigBean, logoutRequest)) {
        val encodedRequest = EncodingUtils.encodeBase64(writer.toString().getBytes(StandardCharsets.UTF_8));
        WebUtils.putSingleLogoutRequest(request, encodedRequest);
    }
    val response = new MockHttpServletResponse();
    val result = samlSingleLogoutServiceMessageHandler.handle(service, "ST-1234567890", SingleLogoutExecutionRequest.builder().ticketGrantingTicket(new MockTicketGrantingTicket("casuser")).httpServletRequest(Optional.of(request)).httpServletResponse(Optional.of(response)).build());
    assertFalse(result.isEmpty());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 63 with MockTicketGrantingTicket

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

the class SamlIdPSingleLogoutServiceMessageHandlerTests method verifySoap.

@Test
public void verifySoap() {
    val service = RegisteredServiceTestUtils.getService("urn:soap:slo:example");
    val registeredService = new SamlRegisteredService();
    registeredService.setName("MockySoap");
    registeredService.setServiceId(service.getId());
    registeredService.setId(101);
    registeredService.setMetadataLocation("classpath:metadata/testshib-providers.xml");
    servicesManager.save(registeredService);
    service.getAttributes().put(SamlProtocolConstants.PARAMETER_ENTITY_ID, CollectionUtils.wrapList(registeredService.getServiceId()));
    val result = samlSingleLogoutServiceMessageHandler.handle(service, "ST-1234567890", SingleLogoutExecutionRequest.builder().ticketGrantingTicket(new MockTicketGrantingTicket("casuser")).build());
    assertFalse(result.isEmpty());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) Test(org.junit.jupiter.api.Test)

Example 64 with MockTicketGrantingTicket

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

the class SamlIdPSingleLogoutServiceMessageHandlerTests method verifySendByPost.

@Test
public void verifySendByPost() {
    val service = RegisteredServiceTestUtils.getService(samlRegisteredService.getServiceId());
    service.getAttributes().put(SamlProtocolConstants.PARAMETER_ENTITY_ID, CollectionUtils.wrapList(samlRegisteredService.getServiceId()));
    val result = samlSingleLogoutServiceMessageHandler.handle(service, "ST-1234567890", SingleLogoutExecutionRequest.builder().ticketGrantingTicket(new MockTicketGrantingTicket("casuser")).build());
    assertFalse(result.isEmpty());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Test(org.junit.jupiter.api.Test)

Example 65 with MockTicketGrantingTicket

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

the class WSFederationValidateRequestControllerTests method verifyLoginRenewWithNoToken.

@Test
public void verifyLoginRenewWithNoToken() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val registeredService = getWsFederationRegisteredService();
    request.addParameter(WSFederationConstants.WTREALM, registeredService.getRealm());
    request.addParameter(WSFederationConstants.WREPLY, registeredService.getServiceId());
    request.addParameter(WSFederationConstants.WREFRESH, "5000");
    request.addParameter(WSFederationConstants.WA, WSFederationConstants.WSIGNIN10);
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    assertDoesNotThrow(() -> {
        federationValidateRequestController.handleFederationRequest(response, request);
        return null;
    });
    assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, response.getStatus());
    val builder = new URIBuilder(response.getHeader("Location"));
    assertTrue(builder.getQueryParams().stream().anyMatch(p -> p.getName().equals(CasProtocolConstants.PARAMETER_SERVICE)));
    assertTrue(builder.getQueryParams().stream().anyMatch(p -> p.getName().equals(CasProtocolConstants.PARAMETER_RENEW)));
    assertTrue(builder.getQueryParams().stream().anyMatch(p -> p.getName().equals(WSFederationConstants.WTREALM)));
    assertTrue(builder.getQueryParams().stream().anyMatch(p -> p.getName().equals(WSFederationConstants.WREPLY)));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) HttpStatus(org.apache.http.HttpStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SecurityTokenTicket(org.apereo.cas.ticket.SecurityTokenTicket) TicketRegistry(org.apereo.cas.ticket.registry.TicketRegistry) CasCookieBuilder(org.apereo.cas.web.cookie.CasCookieBuilder) WSFederationRegisteredService(org.apereo.cas.ws.idp.services.WSFederationRegisteredService) RegisteredServiceTestUtils(org.apereo.cas.services.RegisteredServiceTestUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) BaseCoreWsSecurityIdentityProviderConfigurationTests(org.apereo.cas.BaseCoreWsSecurityIdentityProviderConfigurationTests) Tag(org.junit.jupiter.api.Tag) ServicesManager(org.apereo.cas.services.ServicesManager) CasProtocolConstants(org.apereo.cas.CasProtocolConstants) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException) URIBuilder(org.apache.http.client.utils.URIBuilder) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) lombok.val(lombok.val) TestPropertySource(org.springframework.test.context.TestPropertySource) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UUID(java.util.UUID) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Mockito(org.mockito.Mockito) UnauthorizedAuthenticationException(org.apereo.cas.authentication.adaptive.UnauthorizedAuthenticationException) Assertions(org.junit.jupiter.api.Assertions) Clock(java.time.Clock) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) URIBuilder(org.apache.http.client.utils.URIBuilder) 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