idpSingleLogoutPOST.jsp revision 9740fa737ef2ed9453ab46d145777dbbbf6a747b
1029N/A<%--
1029N/A DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1361N/A
1029N/A Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
246N/A
246N/A The contents of this file are subject to the terms
246N/A of the Common Development and Distribution License
281N/A (the License). You may not use this file except in
281N/A compliance with the License.
246N/A
131N/A You can obtain a copy of the License at
131N/A https://opensso.dev.java.net/public/CDDLv1.0.html or
131N/A opensso/legal/CDDLv1.0.txt
131N/A See the License for the specific language governing
1086N/A permission and limitations under the License.
131N/A
725N/A When distributing Covered Code, include this CDDL
131N/A Header Notice in each file and include the License file
758N/A at opensso/legal/CDDLv1.0.txt.
131N/A If applicable, add the following below the CDDL Header,
131N/A with the fields enclosed by brackets [] replaced by
131N/A your own identifying information:
131N/A "Portions Copyrighted [year] [name of copyright owner]"
500N/A
131N/A $Id: idpSingleLogoutPOST.jsp,v 1.5 2009/06/24 23:05:30 mrudulahg Exp $
131N/A
131N/A--%>
131N/A
131N/A<%--
131N/A Portions Copyrighted 2013 ForgeRock AS
131N/A--%>
144N/A
131N/A<%@ page import="com.sun.identity.saml.common.SAMLUtils" %>
1029N/A<%@ page import="com.sun.identity.saml2.common.SAML2Utils" %>
131N/A<%@ page import="com.sun.identity.saml2.common.SAML2Constants" %>
246N/A<%@ page import="com.sun.identity.saml2.common.SAML2Exception" %>
929N/A<%@ page import="com.sun.identity.saml2.profile.IDPCache" %>
1029N/A<%@ page import="com.sun.identity.saml2.profile.IDPSingleLogout" %>
1029N/A<%@ page import="org.owasp.esapi.ESAPI" %>
1097N/A
131N/A<%--
131N/A idpSingleLogoutPOST.jsp
131N/A
131N/A - receives the LogoutRequest and sends the LogoutResponse to
131N/A Service Provider from the Identity Provider.
246N/A OR
929N/A - receives the LogoutResponse from the Service Provider.
1097N/A
131N/A Required parameters to this jsp are :
340N/A - RelayState - the target URL on successful Single Logout
1029N/A - SAMLRequest - the LogoutRequest
1036N/A OR
340N/A - SAMLResponse - the LogoutResponse
131N/A
131N/A Check the SAML2 Documentation for supported parameters.
131N/A--%>
1029N/A
1029N/A<%
920N/A // Retrieves the LogoutRequest or LogoutResponse
920N/A //Retrieves :
131N/A //- RelayState - the target URL on successful Single Logout
131N/A //- SAMLRequest - the LogoutRequest
131N/A //OR
214N/A //- SAMLResponse - the LogoutResponse
214N/A
131N/A String relayState = request.getParameter(SAML2Constants.RELAY_STATE);
131N/A if (relayState != null) {
131N/A String tmpRs = (String) IDPCache.relayStateCache.remove(relayState);
131N/A if (tmpRs != null) {
131N/A relayState = tmpRs;
131N/A }
131N/A }
131N/A if (!ESAPI.validator().isValidInput("HTTP Parameter Value: " + relayState, relayState, "URL", 2000, true)) {
131N/A relayState = null;
131N/A }
131N/A String samlResponse = request.getParameter(SAML2Constants.SAML_RESPONSE);
927N/A if (samlResponse != null) {
131N/A boolean doRelayState = true;
131N/A try {
131N/A /**
131N/A * Gets and processes the Single <code>LogoutResponse</code> from SP,
131N/A * destroys the local session, checks response's issuer
131N/A * and inResponseTo.
131N/A *
131N/A * @param request the HttpServletRequest.
131N/A * @param response the HttpServletResponse.
131N/A * @param samlResponse <code>LogoutResponse</code> in the
131N/A * XML string format.
131N/A * @param relayState the target URL on successful
131N/A * <code>LogoutResponse</code>.
131N/A * @throws SAML2Exception if error processing
131N/A * <code>LogoutResponse</code>.
227N/A */
131N/A doRelayState = IDPSingleLogout.processLogoutResponse(
131N/A request, response,samlResponse, relayState);
895N/A } catch (SAML2Exception sse) {
895N/A SAML2Utils.debug.error("Error processing LogoutResponse :",
131N/A sse);
131N/A SAMLUtils.sendError(request, response, response.SC_BAD_REQUEST,
131N/A "LogoutResponseProcessingError",
131N/A SAML2Utils.bundle.getString("LogoutResponseProcessingError") +
" " + sse.getMessage());
return;
} catch (Exception e) {
SAML2Utils.debug.error("Error processing LogoutResponse ",e);
SAMLUtils.sendError(request, response, response.SC_BAD_REQUEST,
"LogoutResponseProcessingError",
SAML2Utils.bundle.getString("LogoutResponseProcessingError") +
" " + e.getMessage());
return;
}
if (!doRelayState) {
if (relayState != null && SAML2Utils.isRelayStateURLValid(request, relayState, SAML2Constants.IDP_ROLE)) {
if (relayState.indexOf("?") != -1) {
response.sendRedirect(relayState
+ "&logoutStatus=logoutSuccess");
} else {
response.sendRedirect(relayState
+ "?logoutStatus=logoutSuccess");
}
} else {
%>
<jsp:forward page="/saml2/jsp/default.jsp?message=idpSloSuccess" />
<%
}
}
} else {
String samlRequest = request.getParameter(SAML2Constants.SAML_REQUEST);
if (samlRequest != null) {
try {
/**
* Gets and processes the Single <code>LogoutRequest</code> from SP.
*
* @param request the HttpServletRequest.
* @param response the HttpServletResponse.
* @param samlRequest <code>LogoutRequest</code> in the
* XML string format.
* @param relayState the target URL on successful
* <code>LogoutRequest</code>.
* @throws SAML2Exception if error processing
* <code>LogoutRequest</code>.
*/
IDPSingleLogout.processLogoutRequest(request,response,
samlRequest,relayState);
} catch (SAML2Exception sse) {
SAML2Utils.debug.error("Error processing LogoutRequest :", sse);
SAMLUtils.sendError(request, response, response.SC_BAD_REQUEST,
"LogoutRequestProcessingError",
SAML2Utils.bundle.getString("LogoutRequestProcessingError")
+ " " + sse.getMessage());
return;
} catch (Exception e) {
SAML2Utils.debug.error("Error processing LogoutRequest ",e);
SAMLUtils.sendError(request, response, response.SC_BAD_REQUEST,
"LogoutRequestProcessingError",
SAML2Utils.bundle.getString("LogoutRequestProcessingError")
+ " " + e.getMessage());
return;
}
}
}
%>