use of org.apereo.cas.authentication.principal.WebApplicationService in project cas by apereo.
the class DefaultSingleLogoutServiceMessageHandler method handle.
/**
* Handle logout for slo service.
*
* @param singleLogoutService the service
* @param ticketId the ticket id
* @return the logout request
*/
@Override
public LogoutRequest handle(final WebApplicationService singleLogoutService, final String ticketId) {
if (!singleLogoutService.isLoggedOutAlready()) {
final WebApplicationService selectedService = WebApplicationService.class.cast(this.authenticationRequestServiceSelectionStrategies.resolveService(singleLogoutService));
LOGGER.debug("Processing logout request for service [{}]", selectedService);
final RegisteredService registeredService = this.servicesManager.findServiceBy(selectedService);
if (serviceSupportsSingleLogout(registeredService)) {
LOGGER.debug("Service [{}] supports single logout and is found in the registry as [{}]. Proceeding...", selectedService, registeredService);
final URL logoutUrl = this.singleLogoutServiceLogoutUrlBuilder.determineLogoutUrl(registeredService, selectedService);
LOGGER.debug("Prepared logout url [{}] for service [{}]", logoutUrl, selectedService);
final DefaultLogoutRequest logoutRequest = new DefaultLogoutRequest(ticketId, selectedService, logoutUrl);
LOGGER.debug("Logout request [{}] created for [{}] and ticket id [{}]", logoutRequest, selectedService, ticketId);
final LogoutType type = registeredService.getLogoutType() == null ? LogoutType.BACK_CHANNEL : registeredService.getLogoutType();
LOGGER.debug("Logout type registered for [{}] is [{}]", selectedService, type);
switch(type) {
case BACK_CHANNEL:
if (performBackChannelLogout(logoutRequest)) {
logoutRequest.setStatus(LogoutRequestStatus.SUCCESS);
} else {
logoutRequest.setStatus(LogoutRequestStatus.FAILURE);
LOGGER.warn("Logout message not sent to [{}]; Continuing processing...", singleLogoutService.getId());
}
break;
default:
logoutRequest.setStatus(LogoutRequestStatus.NOT_ATTEMPTED);
break;
}
return logoutRequest;
}
}
return null;
}
use of org.apereo.cas.authentication.principal.WebApplicationService in project cas by apereo.
the class SamlCompliantLogoutMessageCreatorTests method verifyMessageBuilding.
@Test
public void verifyMessageBuilding() throws Exception {
final WebApplicationService service = mock(WebApplicationService.class);
when(service.getOriginalUrl()).thenReturn(RegisteredServiceTestUtils.CONST_TEST_URL);
final URL logoutUrl = new URL(service.getOriginalUrl());
final DefaultLogoutRequest request = new DefaultLogoutRequest("TICKET-ID", service, logoutUrl);
final String msg = builder.create(request);
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = factory.newDocumentBuilder();
final InputStream is = new ByteArrayInputStream(msg.getBytes());
final Document document = builder.parse(is);
final NodeList list = document.getDocumentElement().getElementsByTagName("samlp:SessionIndex");
assertEquals(list.getLength(), 1);
assertEquals(list.item(0).getTextContent(), request.getTicketId());
}
use of org.apereo.cas.authentication.principal.WebApplicationService in project cas by apereo.
the class SamlMetadataUIParserAction method doExecute.
@Override
public Event doExecute(final RequestContext requestContext) throws Exception {
final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
final String entityId = request.getParameter(this.entityIdParameterName);
if (StringUtils.isBlank(entityId)) {
LOGGER.debug("No entity id found for parameter [{}]", this.entityIdParameterName);
return success();
}
final WebApplicationService service = this.serviceFactory.createService(entityId);
final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
if (registeredService == null || !registeredService.getAccessStrategy().isServiceAccessAllowed()) {
LOGGER.debug("Entity id [{}] is not recognized/allowed by the CAS service registry", entityId);
if (registeredService != null) {
WebUtils.putUnauthorizedRedirectUrlIntoFlowScope(requestContext, registeredService.getAccessStrategy().getUnauthorizedRedirectUrl());
}
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, "Entity [" + entityId + "] not recognized");
}
final SamlMetadataUIInfo mdui = MetadataUIUtils.locateMetadataUserInterfaceForEntityId(this.metadataAdapter, entityId, registeredService);
WebUtils.putServiceUserInterfaceMetadata(requestContext, mdui);
return success();
}
use of org.apereo.cas.authentication.principal.WebApplicationService in project cas by apereo.
the class RedirectToServiceAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
final WebApplicationService service = WebUtils.getService(requestContext);
final String serviceTicketId = WebUtils.getServiceTicketFromRequestScope(requestContext);
final Response response = responseBuilderLocator.locate(service).build(service, serviceTicketId);
WebUtils.putServiceResponseIntoRequestScope(requestContext, response);
WebUtils.putServiceOriginalUrlIntoRequestScope(requestContext, service);
return new EventFactorySupport().event(this, response.getResponseType().name().toLowerCase());
}
Aggregations