Class AuthenticatingConnector
- java.lang.Object
-
- org.springframework.extensions.webscripts.connector.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 Summary
Fields Modifier and Type Field Description protected Authenticatorauthenticatorprotected Connectorconnectorprotected static org.apache.commons.logging.Loglogger
-
Constructor Summary
Constructors Constructor Description AuthenticatingConnector(Connector connector, Authenticator authenticator)Instantiates a new authenticating connector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Responsecall(java.lang.String uri)Invokes a URI on a remote service.Responsecall(java.lang.String uri, ConnectorContext context)Invokes a URI on a remote service.Responsecall(java.lang.String uri, ConnectorContext context, java.io.InputStream in)Invokes a URI on a remote service, passing the input as supplied via a POST/PUT.Responsecall(java.lang.String uri, ConnectorContext context, java.io.InputStream in, java.io.OutputStream out)Invokes a URI on a remote service.Responsecall(java.lang.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.ConnectorSessiongetConnectorSession()Returns the connector sessionCredentialsgetCredentials()Returns the credents for this connector.java.lang.StringgetEndpoint()Returns the endpoint to which this connector connects.booleanhandshake()Performs the authentication handshake.protected booleanisAuthenticated()Returns whether the current session is authenticated already.voidsetConnectorSession(ConnectorSession connectorSession)Sets the connector sessionvoidsetCredentials(Credentials credentials)Binds Credentials to this connector.voidsetEndpoint(java.lang.String endpoint)Sets the endpoint.java.lang.StringtoString()
-
-
-
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 connectorauthenticator- the authenticator
-
-
Method Detail
-
call
public Response call(java.lang.String uri)
Description copied from interface:ConnectorInvokes a URI on a remote service. The response data is buffered into a data element on the returned object of type Response.
-
call
public Response call(java.lang.String uri, ConnectorContext context)
Description copied from interface:ConnectorInvokes 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.
-
call
public Response call(java.lang.String uri, ConnectorContext context, java.io.InputStream in)
Description copied from interface:ConnectorInvokes 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.
-
call
public Response call(java.lang.String uri, ConnectorContext context, java.io.InputStream in, java.io.OutputStream out)
Description copied from interface:ConnectorInvokes 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
-
call
public Response call(java.lang.String uri, ConnectorContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
Description copied from interface:ConnectorInvokes 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.
-
setCredentials
public void setCredentials(Credentials credentials)
Description copied from interface:ConnectorBinds Credentials to this connector.- Specified by:
setCredentialsin interfaceConnector- Parameters:
credentials- the new credentials
-
getCredentials
public Credentials getCredentials()
Description copied from interface:ConnectorReturns the credents for this connector.- Specified by:
getCredentialsin interfaceConnector- Returns:
- the credentials
-
setEndpoint
public void setEndpoint(java.lang.String endpoint)
Description copied from interface:ConnectorSets the endpoint.- Specified by:
setEndpointin interfaceConnector- Parameters:
endpoint- the new endpoint
-
getEndpoint
public java.lang.String getEndpoint()
Description copied from interface:ConnectorReturns the endpoint to which this connector connects.- Specified by:
getEndpointin interfaceConnector- Returns:
- endpoint the endpoint
-
setConnectorSession
public void setConnectorSession(ConnectorSession connectorSession)
Description copied from interface:ConnectorSets the connector session- Specified by:
setConnectorSessionin interfaceConnector- Parameters:
connectorSession- ConnectorSession
-
getConnectorSession
public ConnectorSession getConnectorSession()
Description copied from interface:ConnectorReturns the connector session- Specified by:
getConnectorSessionin interfaceConnector- 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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-