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() |
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()
Gets the Issuers (from Response and Assertion).
|
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.
|
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.
|
void |
setDestinationUrl(String url)
Aux method to set the destination url
|
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 List<String> getIssuers() throws XPathExpressionException, ValidationError
XPathExpressionExceptionValidationErrorpublic 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()
public 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 SPNameQualifierValidationErrorCopyright © 2020. All rights reserved.