Class LogoutResponse


  • public class LogoutResponse
    extends java.lang.Object
    LogoutResponse class of OneLogin's Java Toolkit. A class that implements SAML 2 Logout Response builder/parser/validator
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String currentUrl
      URL of the current host + current view
      private java.lang.String id
      SAML LogoutResponse ID.
      private java.util.Calendar issueInstant
      Time when the Logout Request was created
      private static org.slf4j.Logger LOGGER
      Private property to construct a logger for this class.
      private org.w3c.dom.Document logoutResponseDocument
      A DOMDocument object loaded from the SAML Response.
      private java.lang.String logoutResponseString
      SAML LogoutResponse string
      private HttpRequest request
      HttpRequest object to be processed (Contains GET and POST parameters, request URL, ...).
      private Saml2Settings settings
      Settings data.
      private java.lang.Exception validationException
      After validation, if it fails this property has the cause of the problem
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void build()
      Deprecated.
      use LogoutResponse(Saml2Settings, LogoutResponseParams) instead, in which case this method becomes completely useless; indeed, invoking this method in an outgoing logout response scenario will cause the response parameters specified at construction time (inResponseTo and responseStatus) to be overwritten, as well as its generated id and issue instant; on the other hand invoking this method in a received logout response scenario does not make sense at all (and in that case LogoutResponse(Saml2Settings, HttpRequest) should be used instead)
      void build​(java.lang.String inResponseTo)
      Deprecated.
      use LogoutResponse(Saml2Settings, LogoutResponseParams) instead, in which case this method becomes completely useless; indeed, invoking this method in an outgoing logout response scenario will cause the response parameters specified at construction time (inResponseTo and responseStatus) to be overwritten, as well as its generated id and issue instant; on the other hand invoking this method in a received logout response scenario does not make sense at all (and in that case LogoutResponse(Saml2Settings, HttpRequest) should be used instead)
      void build​(java.lang.String inResponseTo, SamlResponseStatus responseStatus)
      Deprecated.
      use LogoutResponse(Saml2Settings, LogoutResponseParams) instead, in which case this method becomes completely useless; indeed, invoking this method in an outgoing logout response scenario will cause the response parameters specified at construction time (inResponseTo and responseStatus) to be overwritten, as well as its generated id and issue instant; on the other hand invoking this method in a received logout response scenario does not make sense at all (and in that case LogoutResponse(Saml2Settings, HttpRequest) should be used instead)
      void build​(java.lang.String inResponseTo, java.lang.String statusCode)
      Deprecated.
      use LogoutResponse(Saml2Settings, LogoutResponseParams) instead, in which case this method becomes completely useless; indeed, invoking this method in an outgoing logout response scenario will cause the response parameters specified at construction time (inResponseTo and responseStatus) to be overwritten, as well as its generated id and issue instant; on the other hand invoking this method in a received logout response scenario does not make sense at all (and in that case LogoutResponse(Saml2Settings, HttpRequest) should be used instead)
      private org.apache.commons.lang3.text.StrSubstitutor generateSubstitutor​(LogoutResponseParams params, Saml2Settings settings)
      Substitutes LogoutResponse variables within a string by values.
      java.lang.String getEncodedLogoutResponse()  
      java.lang.String getEncodedLogoutResponse​(java.lang.Boolean deflated)  
      java.lang.String getError()
      After execute a validation process, if fails this method returns the cause
      java.lang.String getId()  
      java.util.Calendar getIssueInstant()
      Returns the issue instant of this message.
      java.lang.String getIssuer()
      Gets the Issuer from Logout Response.
      private static java.lang.StringBuilder getLogoutResponseTemplate()  
      java.lang.String getLogoutResponseXml()  
      SamlResponseStatus getSamlResponseStatus()
      Gets the Status of the Logout Response.
      java.lang.String getStatus()
      Gets the Status of the Logout Response.
      java.lang.Exception getValidationException()
      After execute a validation process, if fails this method returns the Exception object
      java.lang.Boolean isValid()  
      java.lang.Boolean isValid​(java.lang.String requestId)
      Determines if the SAML LogoutResponse is valid
      protected java.lang.String postProcessXml​(java.lang.String logoutResponseXml, LogoutResponseParams params, Saml2Settings settings)
      Allows for an extension class to post-process the LogoutResponse XML generated for this response, in order to customize the result.
      protected org.w3c.dom.NodeList query​(java.lang.String query)
      Extracts nodes that match the query from the DOMDocument (Logout Response Menssage)
      protected void setValidationException​(java.lang.Exception validationException)
      Sets the validation exception that this LogoutResponse should return when a validation error occurs.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
        Private property to construct a logger for this class.
      • logoutResponseString

        private java.lang.String logoutResponseString
        SAML LogoutResponse string
      • logoutResponseDocument

        private org.w3c.dom.Document logoutResponseDocument
        A DOMDocument object loaded from the SAML Response.
      • id

        private java.lang.String id
        SAML LogoutResponse ID.
      • request

        private final HttpRequest request
        HttpRequest object to be processed (Contains GET and POST parameters, request URL, ...).
      • currentUrl

        private java.lang.String currentUrl
        URL of the current host + current view
      • issueInstant

        private java.util.Calendar issueInstant
        Time when the Logout Request was created
      • validationException

        private java.lang.Exception validationException
        After validation, if it fails this property has the cause of the problem
    • Constructor Detail

      • LogoutResponse

        public LogoutResponse​(Saml2Settings settings,
                              HttpRequest request)
        Constructs the LogoutResponse object when a received response should be extracted from the HTTP request and parsed.
        Parameters:
        settings - OneLogin_Saml2_Settings
        request - the HttpRequest object to be processed (Contains GET and POST parameters, request URL, ...); may be null when building an outgoing logout response
      • LogoutResponse

        public LogoutResponse​(Saml2Settings settings,
                              LogoutResponseParams params)
        Constructs the LogoutResponse object when a new response should be generated and sent.
        Parameters:
        settings - OneLogin_Saml2_Settings
        params - a set of logout response input parameters that shape the request to create
    • Method Detail

      • getEncodedLogoutResponse

        public java.lang.String getEncodedLogoutResponse​(java.lang.Boolean deflated)
                                                  throws java.io.IOException
        Parameters:
        deflated - If deflated or not the encoded Logout Response
        Returns:
        the base64 encoded unsigned Logout Response (deflated or not)
        Throws:
        java.io.IOException
      • getEncodedLogoutResponse

        public java.lang.String getEncodedLogoutResponse()
                                                  throws java.io.IOException
        Returns:
        the base64 encoded, unsigned Logout Response (deflated or not)
        Throws:
        java.io.IOException
      • getLogoutResponseXml

        public java.lang.String getLogoutResponseXml()
        Returns:
        the plain XML Logout Response
      • getId

        public java.lang.String getId()
        Returns:
        the ID of the Response
      • isValid

        public java.lang.Boolean isValid​(java.lang.String requestId)
        Determines if the SAML LogoutResponse is valid
        Parameters:
        requestId - The ID of the LogoutRequest sent by this SP to the IdP
        Returns:
        if the SAML LogoutResponse is or not valid
      • isValid

        public java.lang.Boolean isValid()
      • getIssuer

        public java.lang.String getIssuer()
                                   throws javax.xml.xpath.XPathExpressionException
        Gets the Issuer from Logout Response.
        Returns:
        the issuer of the logout response
        Throws:
        javax.xml.xpath.XPathExpressionException
      • getStatus

        public java.lang.String getStatus()
                                   throws javax.xml.xpath.XPathExpressionException
        Gets the Status of the Logout Response.
        Returns:
        the Status
        Throws:
        javax.xml.xpath.XPathExpressionException
      • query

        protected org.w3c.dom.NodeList query​(java.lang.String query)
                                      throws javax.xml.xpath.XPathExpressionException
        Extracts nodes that match the query from the DOMDocument (Logout Response Menssage)
        Parameters:
        query - Xpath Expression
        Returns:
        DOMNodeList The queried nodes
        Throws:
        javax.xml.xpath.XPathExpressionException
      • build

        @Deprecated
        public void build​(java.lang.String inResponseTo,
                          SamlResponseStatus responseStatus)
        Deprecated.
        use LogoutResponse(Saml2Settings, LogoutResponseParams) instead, in which case this method becomes completely useless; indeed, invoking this method in an outgoing logout response scenario will cause the response parameters specified at construction time (inResponseTo and responseStatus) to be overwritten, as well as its generated id and issue instant; on the other hand invoking this method in a received logout response scenario does not make sense at all (and in that case LogoutResponse(Saml2Settings, HttpRequest) should be used instead)
        Generates a Logout Response XML string.
        Parameters:
        inResponseTo - InResponseTo attribute value to bet set at the Logout Response.
        responseStatus - SamlResponseStatus response status to be set on the LogoutResponse
      • build

        @Deprecated
        public void build​(java.lang.String inResponseTo,
                          java.lang.String statusCode)
        Deprecated.
        use LogoutResponse(Saml2Settings, LogoutResponseParams) instead, in which case this method becomes completely useless; indeed, invoking this method in an outgoing logout response scenario will cause the response parameters specified at construction time (inResponseTo and responseStatus) to be overwritten, as well as its generated id and issue instant; on the other hand invoking this method in a received logout response scenario does not make sense at all (and in that case LogoutResponse(Saml2Settings, HttpRequest) should be used instead)
        Generates a Logout Response XML string.
        Parameters:
        inResponseTo - InResponseTo attribute value to bet set at the Logout Response.
        statusCode - String StatusCode to be set on the LogoutResponse
      • build

        @Deprecated
        public void build​(java.lang.String inResponseTo)
        Deprecated.
        use LogoutResponse(Saml2Settings, LogoutResponseParams) instead, in which case this method becomes completely useless; indeed, invoking this method in an outgoing logout response scenario will cause the response parameters specified at construction time (inResponseTo and responseStatus) to be overwritten, as well as its generated id and issue instant; on the other hand invoking this method in a received logout response scenario does not make sense at all (and in that case LogoutResponse(Saml2Settings, HttpRequest) should be used instead)
        Generates a Logout Response XML string.
        Parameters:
        inResponseTo - InResponseTo attribute value to bet set at the Logout Response.
      • build

        @Deprecated
        public void build()
        Deprecated.
        use LogoutResponse(Saml2Settings, LogoutResponseParams) instead, in which case this method becomes completely useless; indeed, invoking this method in an outgoing logout response scenario will cause the response parameters specified at construction time (inResponseTo and responseStatus) to be overwritten, as well as its generated id and issue instant; on the other hand invoking this method in a received logout response scenario does not make sense at all (and in that case LogoutResponse(Saml2Settings, HttpRequest) should be used instead)
        Generates a Logout Response XML string.
      • postProcessXml

        protected java.lang.String postProcessXml​(java.lang.String logoutResponseXml,
                                                  LogoutResponseParams params,
                                                  Saml2Settings settings)
        Allows for an extension class to post-process the LogoutResponse XML generated for this response, in order to customize the result.

        This method is invoked by build(String, String) (and all of its overloadings) and hence only in the logout response sending scenario. Its default implementation simply returns the input XML as-is, with no change.

        Parameters:
        logoutResponseXml - the XML produced for this LogoutResponse by the standard implementation provided by LogoutResponse
        params - the logout request input parameters
        settings - the settings
        Returns:
        the post-processed XML for this LogoutResponse, which will then be returned by any call to getLogoutResponseXml()
      • generateSubstitutor

        private org.apache.commons.lang3.text.StrSubstitutor generateSubstitutor​(LogoutResponseParams params,
                                                                                 Saml2Settings settings)
        Substitutes LogoutResponse variables within a string by values.
        Parameters:
        params - the logout response input parameters
        settings - Saml2Settings object. Setting data
        Returns:
        the StrSubstitutor object of the LogoutResponse
      • getLogoutResponseTemplate

        private static java.lang.StringBuilder getLogoutResponseTemplate()
        Returns:
        the LogoutResponse's template
      • getError

        public java.lang.String getError()
        After execute a validation process, if fails this method returns the cause
        Returns:
        the cause of the validation error
      • getValidationException

        public java.lang.Exception getValidationException()
        After execute a validation process, if fails this method returns the Exception object
        Returns:
        the cause of the validation error
      • setValidationException

        protected void setValidationException​(java.lang.Exception validationException)
        Sets the validation exception that this LogoutResponse should return when a validation error occurs.
        Parameters:
        validationException - the validation exception to set
      • getIssueInstant

        public java.util.Calendar getIssueInstant()
                                           throws ValidationError
        Returns the issue instant of this message.
        Returns:
        a new Calendar instance carrying the issue instant of this message
        Throws:
        ValidationError - if this logout response was received and parsed and the found IssueInstant attribute is not in the expected UTC form of ISO-8601 format