Skip to content

Added support to display child status codes if they exist in SAML response #12818

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

Closed
wants to merge 7 commits into from
Closed
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 @@ -371,13 +371,14 @@ public static Converter<ResponseToken, Saml2ResponseValidatorResult> createDefau
Response response = responseToken.getResponse();
Saml2AuthenticationToken token = responseToken.getToken();
Saml2ResponseValidatorResult result = Saml2ResponseValidatorResult.success();
String statusCode = getStatusCode(response);
if (!StatusCode.SUCCESS.equals(statusCode)) {
String message = String.format("Invalid status [%s] for SAML response [%s]", statusCode,
response.getID());
result = result.concat(new Saml2Error(Saml2ErrorCodes.INVALID_RESPONSE, message));
List<String> statusCodes = getStatusCodes(response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of getting all the status codes ad infinitum, please just get the top-level one.

If it is of type REQUESTER, RESPONDER, or VERSION_MISMATCH, then add a single error message that includes this status code and any single child status code.

Otherwise, if it isn't SUCCESS, then add a single error message like it already does.

This is based on the logic outlined in: https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf#page=39

if (!StatusCode.SUCCESS.equals(statusCodes.get(0))) {
for (String statusCode : statusCodes) {
String message = String.format("Invalid status [%s] for SAML response [%s]", statusCode,
response.getID());
result = result.concat(new Saml2Error(Saml2ErrorCodes.INVALID_RESPONSE, message));
}
}

String inResponseTo = response.getInResponseTo();
result = result.concat(validateInResponseTo(token.getAuthenticationRequest(), inResponseTo));

Expand Down Expand Up @@ -613,14 +614,25 @@ private Consumer<ResponseToken> createDefaultResponseElementsDecrypter() {
};
}

private static String getStatusCode(Response response) {
private static List<String> getStatusCodes(Response response) {
List<String> statusCodes = new ArrayList<>();
if (response.getStatus() == null) {
return StatusCode.SUCCESS;
statusCodes.add(StatusCode.SUCCESS);
return statusCodes;
}
if (response.getStatus().getStatusCode() == null) {
return StatusCode.SUCCESS;
statusCodes.add(StatusCode.SUCCESS);
return statusCodes;
}
return response.getStatus().getStatusCode().getValue();
StatusCode parentStatusCode = response.getStatus().getStatusCode();
statusCodes.add(parentStatusCode.getValue());
StatusCode childStatusCode = parentStatusCode.getStatusCode();
while (childStatusCode != null) {
statusCodes.add(childStatusCode.getValue());
childStatusCode = childStatusCode.getStatusCode();
}

return statusCodes;
}

private Converter<AssertionToken, Saml2ResponseValidatorResult> createDefaultAssertionSignatureValidator() {
Expand Down