public class SamlResponse extends Object
Constructor and Description |
---|
SamlResponse(Saml2Settings settings,
HttpRequest request)
Constructor to have a Response object full builded 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.
|
HashMap<String,String> |
getNameIdData()
Gets the NameID provided from the SAML Response Document.
|
String |
getNameIdFormat()
Gets the NameID Format provided from the SAML Response String.
|
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
|
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 urld)
Aux method to set the destination url
|
Boolean |
validateNumAssertions()
Verifies that the document only contains a single Assertion (encrypted or not).
|
boolean |
validateSignedElements(ArrayList<String> signedElements)
Verifies that the document has the expected signed nodes.
|
boolean |
validateTimestamps()
Verifies that the document is still valid according Conditions Element.
|
public 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, ...).ValidationError
SettingsException
IOException
SAXException
ParserConfigurationException
XPathExpressionException
public void loadXmlFromBase64(String responseStr) throws ParserConfigurationException, XPathExpressionException, SAXException, IOException, SettingsException, ValidationError
responseStr
- Saml2Settings object. Setting dataParserConfigurationException
SettingsException
IOException
SAXException
XPathExpressionException
ValidationError
public boolean isValid(String requestId)
requestId
- The ID of the AuthNRequest sent by this SP to the IdPpublic boolean isValid()
public HashMap<String,String> getNameIdData() throws Exception
Exception
public String getNameId() throws Exception
Exception
public String getNameIdFormat() throws Exception
Exception
public HashMap<String,List<String>> getAttributes() throws XPathExpressionException, ValidationError
XPathExpressionException
ValidationError
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 errorValidationError
public Boolean checkOneCondition() throws XPathExpressionException
XPathExpressionException
public Boolean checkOneAuthnStatement() throws XPathExpressionException
XPathExpressionException
public List<String> getAudiences() throws XPathExpressionException
XPathExpressionException
public List<String> getIssuers() throws XPathExpressionException, ValidationError
XPathExpressionException
ValidationError
public org.joda.time.DateTime getSessionNotOnOrAfter() throws XPathExpressionException
XPathExpressionException
public String getSessionIndex() throws XPathExpressionException
XPathExpressionException
public String getId()
public String getAssertionId() throws XPathExpressionException
XPathExpressionException
public List<org.joda.time.Instant> getAssertionNotOnOrAfter() throws XPathExpressionException
XPathExpressionException
public Boolean validateNumAssertions() throws IllegalArgumentException
IllegalArgumentException
public ArrayList<String> processSignedElements() throws XPathExpressionException, ValidationError
XPathExpressionException
ValidationError
public boolean validateSignedElements(ArrayList<String> signedElements) throws XPathExpressionException, ValidationError
signedElements
- the elements to be validatedXPathExpressionException
ValidationError
public boolean validateTimestamps() throws ValidationError
ValidationError
public void setDestinationUrl(String urld)
urld
- the url to set as currentUrlpublic String getError()
public String getSAMLResponseXml()
protected Document getSAMLResponseDocument()
Copyright © 2017. All rights reserved.