org.springframework.extensions.webscripts.connector
Class AuthenticatingConnector

java.lang.Object
  extended by org.springframework.extensions.webscripts.connector.AuthenticatingConnector
All Implemented Interfaces:
Connector

public class AuthenticatingConnector
extends Object
implements Connector

A special 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 (or something is incorrect about the handshake model).

Author:
muzquiano

Field Summary
protected  Authenticator authenticator
           
protected  Connector connector
           
protected static org.apache.commons.logging.Log logger
           
 
Constructor Summary
AuthenticatingConnector(Connector connector, Authenticator authenticator)
          Instantiates a new authenticating connector.
 
Method Summary
 Response call(String uri)
          Invokes a URI on a remote service.
 Response call(String uri, ConnectorContext context)
          Invokes a URI on a remote service.
 Response call(String uri, ConnectorContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Invokes a URI on a remote service and streams back results to the provided response object.
 Response call(String uri, ConnectorContext context, InputStream in)
          Invokes a URI on a remote service, passing the input as supplied via a POST/PUT.
 Response call(String uri, ConnectorContext context, InputStream in, OutputStream out)
          Invokes a URI on a remote service.
 ConnectorSession getConnectorSession()
          Returns the connector session
 Credentials getCredentials()
          Returns the credents for this connector.
 String getEndpoint()
          Returns the endpoint to which this connector connects.
 boolean handshake()
          Performs the authentication handshake.
protected  boolean isAuthenticated()
          Returns whether the current session is authenticated already.
 void setConnectorSession(ConnectorSession connectorSession)
          Sets the connector session
 void setCredentials(Credentials credentials)
          Binds Credentials to this connector.
 void setEndpoint(String endpoint)
          Sets the endpoint.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static org.apache.commons.logging.Log logger

connector

protected Connector connector

authenticator

protected Authenticator authenticator
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(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(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(String uri,
                     ConnectorContext context,
                     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(String uri,
                     ConnectorContext context,
                     InputStream in,
                     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(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(String endpoint)
Description copied from interface: Connector
Sets the endpoint.

Specified by:
setEndpoint in interface Connector
Parameters:
endpoint - the new endpoint

getEndpoint

public 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

getConnectorSession

public ConnectorSession getConnectorSession()
Description copied from interface: Connector
Returns the connector session

Specified by:
getConnectorSession in interface Connector
Returns:
the connector session

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 String toString()
Overrides:
toString in class Object


Copyright © 2009 SpringSource, Inc. All Rights Reserved.