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