Skip to content

Commit 5f525ac

Browse files
author
Kouroche Sedaghatian
committed
Issue #218: Exposing statuscode and substatuscode through toolkit.
1 parent db6c5ac commit 5f525ac

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

core/src/main/java/com/onelogin/saml2/authn/SamlResponse.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public class SamlResponse {
8585
*/
8686
private String error;
8787

88+
/**
89+
* The respone status code and messages
90+
*/
91+
private SamlResponseStatus responseStatus;
92+
8893
/**
8994
* Constructor to have a Response object fully built and ready to validate the saml response.
9095
*
@@ -574,19 +579,27 @@ public HashMap<String, List<String>> getAttributes() throws XPathExpressionExcep
574579
return attributes;
575580
}
576581

582+
/**
583+
* Returns the latest response status
584+
*
585+
* @return
586+
*/
587+
public SamlResponseStatus getResponseStatus() {
588+
return this.responseStatus;
589+
}
590+
577591
/**
578592
* Checks the Status
579593
*
580-
* @throws ValidationError
581-
* If status is not success
594+
* @throws ValidationError If status is not success
582595
*/
583596
public void checkStatus() throws ValidationError {
584-
SamlResponseStatus responseStatus = getStatus(samlResponseDocument);
585-
if (!responseStatus.is(Constants.STATUS_SUCCESS)) {
597+
this.responseStatus = getStatus(samlResponseDocument);
598+
if (!this.responseStatus.is(Constants.STATUS_SUCCESS)) {
586599
String statusExceptionMsg = "The status code of the Response was not Success, was "
587-
+ responseStatus.getStatusCode();
588-
if (responseStatus.getStatusMessage() != null) {
589-
statusExceptionMsg += " -> " + responseStatus.getStatusMessage();
600+
+ this.responseStatus.getStatusCode();
601+
if (this.responseStatus.getStatusMessage() != null) {
602+
statusExceptionMsg += " -> " + this.responseStatus.getStatusMessage();
590603
}
591604
throw new ValidationError(statusExceptionMsg, ValidationError.STATUS_CODE_IS_NOT_SUCCESS);
592605
}

toolkit/src/main/java/com/onelogin/saml2/Auth.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.onelogin.saml2.http.HttpRequest;
3030
import com.onelogin.saml2.logout.LogoutRequest;
3131
import com.onelogin.saml2.logout.LogoutResponse;
32+
import com.onelogin.saml2.model.SamlResponseStatus;
3233
import com.onelogin.saml2.servlet.ServletUtils;
3334
import com.onelogin.saml2.settings.Saml2Settings;
3435
import com.onelogin.saml2.settings.SettingsBuilder;
@@ -655,6 +656,13 @@ public void processResponse(String requestId) throws Exception {
655656
LOGGER.error("processResponse error. invalid_response");
656657
LOGGER.debug(" --> " + samlResponseParameter);
657658
errorReason = samlResponse.getError();
659+
SamlResponseStatus samlResponseStatus = samlResponse.getResponseStatus();
660+
if (samlResponseStatus.getStatusCode() != null) {
661+
errors.add(samlResponseStatus.getStatusCode());
662+
}
663+
if (samlResponseStatus.getSubStatusCode() != null) {
664+
errors.add(samlResponseStatus.getSubStatusCode());
665+
}
658666
}
659667
} else {
660668
errors.add("invalid_binding");

0 commit comments

Comments
 (0)