Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid throwing generic exception when Detailed Status Message is returned #89

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.wso2.carbon.identity.authenticator.saml2.sso.ui;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.opensaml.saml.saml2.core.Assertion;
Expand Down Expand Up @@ -112,7 +113,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
// If SAML Response is not present in the redirected req, send the user to an error page.
if (samlRespString == null) {
log.error("SAML Response is not present in the request.");
handleMalformedResponses(req, resp,
handleErrorResponses(req, resp,
SAML2SSOAuthenticatorConstants.ErrorMessageConstants.RESPONSE_NOT_PRESENT);
return;
}
Expand All @@ -139,7 +140,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
}
} catch (SAML2SSOUIAuthenticatorException e) {
log.error("Error when processing the SAML Assertion in the request.", e);
handleMalformedResponses(req, resp, SAML2SSOAuthenticatorConstants.ErrorMessageConstants.RESPONSE_MALFORMED);
handleErrorResponses(req, resp, SAML2SSOAuthenticatorConstants.ErrorMessageConstants.RESPONSE_MALFORMED);
}
}

Expand Down Expand Up @@ -193,6 +194,10 @@ private void handleSAMLResponses(HttpServletRequest req, HttpServletResponse res
if (samlResponse.getStatus() != null &&
samlResponse.getStatus().getStatusMessage() != null) {
log.error(samlResponse.getStatus().getStatusMessage().getMessage());
if (StringUtils.isNotBlank(samlResponse.getStatus().getStatusMessage().getMessage())) {
handleErrorResponses(req, resp, samlResponse.getStatus().getStatusMessage().getMessage());
return;
}
} else {
log.error("SAML Assertion not found in the Response.");
}
Expand Down Expand Up @@ -297,7 +302,7 @@ private void handleSAMLResponses(HttpServletRequest req, HttpServletResponse res
* @param errorMsg Error message to be displayed in HttpServletResponse.jsp
* @throws IOException Error when redirecting
*/
private void handleMalformedResponses(HttpServletRequest req, HttpServletResponse resp,
private void handleErrorResponses(HttpServletRequest req, HttpServletResponse resp,
String errorMsg) throws IOException {
HttpSession session = req.getSession();
session.setAttribute(SAML2SSOAuthenticatorConstants.NOTIFICATIONS_ERROR_MSG, errorMsg);
Expand Down Expand Up @@ -495,4 +500,4 @@ private void clearCookies(HttpServletRequest req, HttpServletResponse resp) {
}
}
}
}
}