public class SamlResponse extends Object
| Constructor and Description |
|---|
SamlResponse(Saml2Settings settings,
HttpRequest request)
Constructor to have a Response object fully built and ready to validate the saml response.
|
SamlResponse(Saml2Settings settings,
String currentUrl,
String samlResponse)
Constructor to have a Response object fully built and ready to validate the saml response.
|
| Modifier and Type | Method and Description |
|---|---|
Boolean |
checkOneAuthnStatement()
Checks that the samlp:Response/saml:Assertion/saml:AuthnStatement element exists and is unique.
|
Boolean |
checkOneCondition()
Checks that the samlp:Response/saml:Assertion/saml:Conditions element exists and is unique.
|
void |
checkStatus()
Checks the Status
|
String |
getAssertionId() |
String |
getAssertionIssuer()
Gets the Assertion Issuer.
|
List<org.joda.time.Instant> |
getAssertionNotOnOrAfter() |
HashMap<String,List<String>> |
getAttributes()
Gets the Attributes from the AttributeStatement element.
|
List<String> |
getAudiences()
Gets the audiences.
|
String |
getError()
After execute a validation process, if fails this method returns the cause
|
String |
getId() |
List<String> |
getIssuers()
Deprecated.
use
getResponseIssuer() and/or
getAssertionIssuer(); the contract of this method is
quite controversial |
String |
getNameId()
Gets the NameID value provided from the SAML Response String.
|
Map<String,String> |
getNameIdData()
Gets the NameID provided from the SAML Response Document.
|
String |
getNameIdFormat()
Gets the NameID Format provided from the SAML Response String.
|
String |
getNameIdNameQualifier()
Gets the NameID NameQualifier provided from the SAML Response String.
|
String |
getNameIdSPNameQualifier()
Gets the NameID SP NameQualifier provided from the SAML Response String.
|
Calendar |
getResponseIssueInstant()
Returns the issue instant of this message.
|
String |
getResponseIssuer()
Gets the Response Issuer.
|
SamlResponseStatus |
getResponseStatus()
Returns the ResponseStatus object
|
protected Document |
getSAMLResponseDocument() |
String |
getSAMLResponseXml() |
String |
getSessionIndex()
Gets the SessionIndex from the AuthnStatement.
|
org.joda.time.DateTime |
getSessionNotOnOrAfter()
Gets the SessionNotOnOrAfter from the AuthnStatement.
|
static SamlResponseStatus |
getStatus(Document dom)
Get Status from a Response
|
Exception |
getValidationException()
After execute a validation process, if fails this method returns the Exception object
|
boolean |
isValid()
Determines if the SAML Response is valid using the certificate.
|
boolean |
isValid(String requestId)
Determines if the SAML Response is valid using the certificate.
|
void |
loadXmlFromBase64(String responseStr)
Load a XML base64encoded SAMLResponse
|
ArrayList<String> |
processSignedElements()
Verifies the signature nodes:
- Checks that are Response or Assertion
- Check that IDs and reference URI are unique and consistent.
|
protected NodeList |
query(String nameQuery,
Node context)
Extracts nodes that match the query from the DOMDocument (Response Message)
|
protected NodeList |
queryAssertion(String assertionXpath)
Extracts a node from the DOMDocument (Assertion).
|
void |
setDestinationUrl(String url)
Aux method to set the destination url
|
protected void |
setValidationException(Exception validationException)
Sets the validation exception that this
SamlResponse should return
when a validation error occurs. |
protected void |
validateAudiences()
Validates the audiences.
|
protected void |
validateDestination(Element element)
Validate the destination.
|
Boolean |
validateNumAssertions()
Verifies that the document only contains a single Assertion (encrypted or not).
|
protected SubjectConfirmationIssue |
validateRecipient(Node recipient,
int index)
Validate a subject confirmation recipient.
|
boolean |
validateSignedElements(ArrayList<String> signedElements)
Verifies that the document has the expected signed nodes.
|
protected void |
validateSpNameQualifier(String spNameQualifier)
Validates a SPNameQualifier.
|
boolean |
validateTimestamps()
Verifies that the document is still valid according Conditions Element.
|
public SamlResponse(Saml2Settings settings, String currentUrl, String samlResponse) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException, SettingsException, ValidationError
settings - Saml2Settings object. Setting datacurrentUrl - URL of the current host + current viewsamlResponse - A string containting the base64 encoded response from the IdPValidationErrorSettingsExceptionIOExceptionSAXExceptionParserConfigurationExceptionXPathExpressionExceptionpublic SamlResponse(Saml2Settings settings, HttpRequest request) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException, SettingsException, ValidationError
settings - Saml2Settings object. Setting datarequest - the HttpRequest object to be processed (Contains GET and POST parameters, request URL, ...).ValidationErrorSettingsExceptionIOExceptionSAXExceptionParserConfigurationExceptionXPathExpressionExceptionNullPointerExceptionpublic void loadXmlFromBase64(String responseStr) throws ParserConfigurationException, XPathExpressionException, SAXException, IOException, SettingsException, ValidationError
responseStr - Saml2Settings object. Setting dataParserConfigurationExceptionSettingsExceptionIOExceptionSAXExceptionXPathExpressionExceptionValidationErrorpublic boolean isValid(String requestId)
requestId - The ID of the AuthNRequest sent by this SP to the IdPpublic boolean isValid()
public Map<String,String> getNameIdData() throws Exception
Exceptionpublic String getNameId() throws Exception
Exceptionpublic String getNameIdFormat() throws Exception
Exceptionpublic String getNameIdNameQualifier() throws Exception
Exceptionpublic String getNameIdSPNameQualifier() throws Exception
Exceptionpublic HashMap<String,List<String>> getAttributes() throws XPathExpressionException, ValidationError
XPathExpressionExceptionValidationErrorpublic SamlResponseStatus getResponseStatus()
public void checkStatus()
throws ValidationError
ValidationError - If status is not successpublic static SamlResponseStatus getStatus(Document dom) throws ValidationError
dom - The Response as XMLIllegalArgumentException - if the response not contain status or if Unexpected XPath errorValidationErrorpublic Boolean checkOneCondition() throws XPathExpressionException
XPathExpressionExceptionpublic Boolean checkOneAuthnStatement() throws XPathExpressionException
XPathExpressionExceptionpublic List<String> getAudiences() throws XPathExpressionException
XPathExpressionExceptionpublic String getResponseIssuer() throws XPathExpressionException, ValidationError
null if not specifiedXPathExpressionExceptionValidationError - if multiple Response issuers were foundgetAssertionIssuer(),
getIssuers()public String getAssertionIssuer() throws XPathExpressionException, ValidationError
XPathExpressionExceptionValidationError - if no Assertion Issuer could be found, or if multiple Assertion
issuers were foundgetResponseIssuer(),
getIssuers()@Deprecated public List<String> getIssuers() throws XPathExpressionException, ValidationError
getResponseIssuer() and/or
getAssertionIssuer(); the contract of this method is
quite controversialValidationError will be thrown instead)
isValid(String) (which requires both issuers to be equal to the
Identity Provider entity id)
Warning: as a consequence of the above, if this response status code is not a
successful one, this method will throw a ValidationError because it
won't find any Assertion Issuer. In this case, if you need to retrieve the
Response Issuer any way, you must use getResponseIssuer() instead.
XPathExpressionExceptionValidationError - if multiple Response Issuers or multiple Assertion Issuers were
found, or if no Assertion Issuer could be foundgetResponseIssuer(),
getAssertionIssuer()public org.joda.time.DateTime getSessionNotOnOrAfter()
throws XPathExpressionException
XPathExpressionExceptionpublic String getSessionIndex() throws XPathExpressionException
XPathExpressionExceptionpublic String getId()
public String getAssertionId() throws XPathExpressionException
XPathExpressionExceptionpublic List<org.joda.time.Instant> getAssertionNotOnOrAfter() throws XPathExpressionException
XPathExpressionExceptionpublic Boolean validateNumAssertions() throws IllegalArgumentException
IllegalArgumentExceptionpublic ArrayList<String> processSignedElements() throws XPathExpressionException, ValidationError
XPathExpressionExceptionValidationErrorpublic boolean validateSignedElements(ArrayList<String> signedElements) throws XPathExpressionException, ValidationError
signedElements - the elements to be validatedXPathExpressionExceptionValidationErrorpublic boolean validateTimestamps()
throws ValidationError
ValidationErrorpublic void setDestinationUrl(String url)
url - the url to set as currentUrlpublic String getError()
public Exception getValidationException()
protected void setValidationException(Exception validationException)
SamlResponse should return
when a validation error occurs.validationException - the validation exception to setprotected NodeList queryAssertion(String assertionXpath) throws XPathExpressionException
assertionXpath - Xpath ExpressionXPathExpressionExceptionprotected NodeList query(String nameQuery, Node context) throws XPathExpressionException
nameQuery - Xpath Expressioncontext - The context nodeXPathExpressionExceptionpublic String getSAMLResponseXml()
protected Document getSAMLResponseDocument()
protected void validateAudiences()
throws XPathExpressionException,
ValidationError
protected void validateDestination(Element element) throws ValidationError
element - element with the destination attributeValidationErrorprotected SubjectConfirmationIssue validateRecipient(Node recipient, int index)
recipient - recipient nodeindex - index of the subject confirmation nodeprotected void validateSpNameQualifier(String spNameQualifier) throws ValidationError
spNameQualifier - the SPNameQualifierValidationErrorpublic Calendar getResponseIssueInstant() throws ValidationError
Calendar instance carrying the issue instant of this messageValidationError - if the found IssueInstant attribute is not in the expected
UTC form of ISO-8601 formatCopyright © 2022. All rights reserved.