Skip to content

Commit 2886c71

Browse files
committed
Expose validation exception in SamlResponse
1 parent bed44f3 commit 2886c71

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class SamlResponse {
8383
/**
8484
* After validation, if it fails this property has the cause of the problem
8585
*/
86-
private String error;
86+
private Exception validationException;
8787

8888
/**
8989
* Constructor to have a Response object fully built and ready to validate the saml response.
@@ -148,7 +148,7 @@ public void loadXmlFromBase64(String responseStr) throws ParserConfigurationExce
148148
* @return if the response is valid or not
149149
*/
150150
public boolean isValid(String requestId) {
151-
error = null;
151+
validationException = null;
152152

153153
try {
154154
if (samlResponseDocument == null) {
@@ -311,9 +311,9 @@ public boolean isValid(String requestId) {
311311
LOGGER.debug("SAMLResponse validated --> {}", samlResponseString);
312312
return true;
313313
} catch (Exception e) {
314-
error = e.getMessage();
314+
validationException = e;
315315
LOGGER.debug("SAMLResponse invalid --> {}", samlResponseString);
316-
LOGGER.error(error);
316+
LOGGER.error(validationException.getMessage());
317317
return false;
318318
}
319319
}
@@ -964,15 +964,24 @@ public void setDestinationUrl(String url) {
964964
/**
965965
* After execute a validation process, if fails this method returns the cause
966966
*
967-
* @return the cause of the validation error
967+
* @return the cause of the validation error as a string
968968
*/
969969
public String getError() {
970-
if (error != null) {
971-
return error;
970+
if (validationException != null) {
971+
return validationException.getMessage();
972972
}
973973
return null;
974974
}
975975

976+
/**
977+
* After execute a validation process, if fails this method returns the cause
978+
*
979+
* @return the cause of the validation error
980+
*/
981+
public Exception getValidationException() {
982+
return validationException;
983+
}
984+
976985
/**
977986
* Extracts a node from the DOMDocument (Assertion).
978987
*

0 commit comments

Comments
 (0)