String relayState = httpContext.getRequest().getParameter(GeneralConstants.RELAY_STATE);
LogoutRequestType logOutRequest = (LogoutRequestType) request.getSAML2Object();
String issuer = logOutRequest.getIssuer().getValue();
try {
SAML2Request saml2Request = new SAML2Request();
ServletContext servletCtx = httpContext.getServletContext();
IdentityServer server = (IdentityServer) servletCtx.getAttribute(GeneralConstants.IDENTITY_SERVER);
if (server == null)
throw logger.samlHandlerIdentityServerNotFoundError();
String originalIssuer = (relayState == null) ? issuer : relayState;
String participant = this.getParticipant(server, sessionID, originalIssuer);
if (participant == null || participant.equals(originalIssuer)) {
// All log out is done
session.invalidate();
server.stack().pop(sessionID);
generateSuccessStatusResponseType(logOutRequest.getID(), request, response, originalIssuer);
boolean isPost = isPostBindingForResponse(server, participant, request);
response.setPostBindingForResponse(isPost);
response.setSendRequest(false);
} else {
// Put the participant in transit mode
server.stack().registerTransitParticipant(sessionID, participant);
if (relayState == null) {
relayState = originalIssuer;
}
// send logout request to participant with relaystate to orig
response.setRelayState(originalIssuer);
response.setDestination(participant);
boolean isPost = isPostBindingForResponse(server, participant, request);
response.setPostBindingForResponse(isPost);
LogoutRequestType lort = saml2Request.createLogoutRequest(request.getIssuer().getValue());
Principal userPrincipal = httpServletRequest.getUserPrincipal();
if (userPrincipal == null) {
throw logger.samlHandlerPrincipalNotFoundError();
}
NameIDType nameID = new NameIDType();
nameID.setValue(userPrincipal.getName());
lort.setNameID(nameID);
long assertionValidity = PicketLinkCoreSTS.instance().getConfiguration().getIssuedTokenTimeout();
lort.setNotOnOrAfter(XMLTimeUtil.add(lort.getIssueInstant(), assertionValidity));
lort.setDestination(URI.create(participant));
response.setResultingDocument(saml2Request.convert(lort));
response.setSendRequest(true);
}
} catch (ParserConfigurationException pe) {
throw logger.processingError(pe);
} catch (ConfigurationException pe) {