Class AuthenticatingConnector

  • All Implemented Interfaces:
    Connector

    public class AuthenticatingConnector
    extends java.lang.Object
    implements Connector
    An implementation of an Authenticating Connector.

    The AuthenticatingConnector is a wrapper around a Connector object and an Authenticator object. It appears as a Connector to the outside world but provides additional functionality.

    When a call is made, the underlying connector is used to call over to the resource. The underlying connector retrieves cookie state from the connector session (if available) and attempts to access the remote resource.

    If this succeeds, then the AuthenticatingConnector returns this response.

    On the other hand, if this fails (i.e. it receives a 401 unauthorized response), the AuthenticatingConnector calls into the underlying Authenticator instance to perform an "authentication handshake".

    This handshake retrieves the necessary cookies or tokens and places them into the connector session. The connector session is persisted to the session (if it was originally bound to the session).

    The AuthenticatingConnector then reattempts the connection using the newly retrieved cookies or tokens. If a 401 is received again, the credentials are assumed to be invalid.

    Author:
    muzquiano, kevinr
    • Field Detail

      • logger

        protected static org.apache.commons.logging.Log logger
    • Constructor Detail

      • AuthenticatingConnector

        public AuthenticatingConnector​(Connector connector,
                                       Authenticator authenticator)
        Instantiates a new authenticating connector.
        Parameters:
        connector - the connector
        authenticator - the authenticator
    • Method Detail

      • call

        public Response call​(java.lang.String uri)
        Description copied from interface: Connector
        Invokes a URI on a remote service. The response data is buffered into a data element on the returned object of type Response.
        Specified by:
        call in interface Connector
        Parameters:
        uri - the uri
        Returns:
        the response
      • call

        public Response call​(java.lang.String uri,
                             ConnectorContext context)
        Description copied from interface: Connector
        Invokes a URI on a remote service. If the context is null, then it will not be utilized. The response data is buffered into a data element on the returned object of type Response.
        Specified by:
        call in interface Connector
        Parameters:
        uri - the uri
        context - the context of the invoke
        Returns:
        the response
      • call

        public Response call​(java.lang.String uri,
                             ConnectorContext context,
                             java.io.InputStream in)
        Description copied from interface: Connector
        Invokes a URI on a remote service, passing the input as supplied via a POST/PUT. If the context is null, then it will not be utilized and POST will be assumed. The response data is buffered into a data element on the returned object of type Response.
        Specified by:
        call in interface Connector
        Parameters:
        uri - the uri
        context - the context of the invoke
        in - the input stream
        Returns:
        the response
      • call

        public Response call​(java.lang.String uri,
                             ConnectorContext context,
                             java.io.InputStream in,
                             java.io.OutputStream out)
        Description copied from interface: Connector
        Invokes a URI on a remote service. Data is streamed back from the response into the provided output stream. Headers and response state is maintained on the Response object. If the context is null, then it will not be utilized. The response data is not buffered
        Specified by:
        call in interface Connector
        Parameters:
        uri - the uri
        context - the context of the invoke
        in - the input stream
        out - the output stream
        Returns:
        the response
      • call

        public Response call​(java.lang.String uri,
                             ConnectorContext context,
                             javax.servlet.http.HttpServletRequest req,
                             javax.servlet.http.HttpServletResponse res)
        Description copied from interface: Connector
        Invokes a URI on a remote service and streams back results to the provided response object. This method makes sure that the full response is propagated into the servlet response, including headers, exception states and more. If the context is null, then it will not be utilized. The response data is not buffered.
        Specified by:
        call in interface Connector
        Parameters:
        uri - the uri
        context - the context of the invoke
        req - Request to proxy from
        res - Response to proxy onto
        Returns:
        the response
      • setCredentials

        public void setCredentials​(Credentials credentials)
        Description copied from interface: Connector
        Binds Credentials to this connector.
        Specified by:
        setCredentials in interface Connector
        Parameters:
        credentials - the new credentials
      • getCredentials

        public Credentials getCredentials()
        Description copied from interface: Connector
        Returns the credents for this connector.
        Specified by:
        getCredentials in interface Connector
        Returns:
        the credentials
      • setEndpoint

        public void setEndpoint​(java.lang.String endpoint)
        Description copied from interface: Connector
        Sets the endpoint.
        Specified by:
        setEndpoint in interface Connector
        Parameters:
        endpoint - the new endpoint
      • getEndpoint

        public java.lang.String getEndpoint()
        Description copied from interface: Connector
        Returns the endpoint to which this connector connects.
        Specified by:
        getEndpoint in interface Connector
        Returns:
        endpoint the endpoint
      • setConnectorSession

        public void setConnectorSession​(ConnectorSession connectorSession)
        Description copied from interface: Connector
        Sets the connector session
        Specified by:
        setConnectorSession in interface Connector
        Parameters:
        connectorSession - ConnectorSession
      • isAuthenticated

        protected boolean isAuthenticated()
        Returns whether the current session is authenticated already.
        Returns:
        true, if checks if is authenticated
      • handshake

        public final boolean handshake()
        Performs the authentication handshake.
        Returns:
        true, if successful
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object