com.noelios.restlet.authentication
Class AuthenticationHelper

java.lang.Object
  extended by com.noelios.restlet.authentication.AuthenticationHelper
Direct Known Subclasses:
HttpAmazonS3Helper, HttpBasicHelper, HttpDigestHelper, SmtpPlainHelper

public abstract class AuthenticationHelper
extends java.lang.Object

Base class for authentication helpers.

Author:
Jerome Louvel

Constructor Summary
AuthenticationHelper(ChallengeScheme challengeScheme, boolean clientSide, boolean serverSide)
          Constructor.
 
Method Summary
 int authenticate(ChallengeResponse cr, Request request, Guard guard)
          Indicates if the call is properly authenticated.
 void challenge(Response response, boolean stale, Guard guard)
          Challenges the client by adding a challenge request to the response and by setting the status to CLIENT_ERROR_UNAUTHORIZED.
 java.lang.String format(ChallengeRequest request)
          Formats a challenge request as a HTTP header value.
 java.lang.String format(ChallengeResponse challenge, Request request, Series<Parameter> httpHeaders)
          Formats a challenge response as raw credentials.
abstract  void formatCredentials(java.lang.StringBuilder sb, ChallengeResponse challenge, Request request, Series<Parameter> httpHeaders)
          Formats a challenge response as raw credentials.
 void formatParameters(java.lang.StringBuilder sb, Series<Parameter> parameters, ChallengeRequest request)
          Formats the parameters of a challenge request, to be appended to the scheme technical name and realm.
 ChallengeScheme getChallengeScheme()
          Returns the supported challenge scheme.
 java.util.logging.Logger getLogger()
          Returns the context's logger.
 boolean isClientSide()
          Indicates if client side authentication is supported.
 boolean isServerSide()
          Indicates if server side authentication is supported.
 void parseRequest(ChallengeRequest cr, java.lang.String header)
          Parses an authenticate header into a challenge request.
 void parseResponse(ChallengeResponse cr, Request request)
          Parses an authorization header into a challenge response.
 void setChallengeScheme(ChallengeScheme challengeScheme)
          Sets the supported challenge scheme.
 void setClientSide(boolean clientSide)
          Indicates if client side authentication is supported.
 void setServerSide(boolean serverSide)
          Indicates if server side authentication is supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuthenticationHelper

public AuthenticationHelper(ChallengeScheme challengeScheme,
                            boolean clientSide,
                            boolean serverSide)
Constructor.

Parameters:
challengeScheme - The supported challenge scheme.
clientSide - Indicates if client side authentication is supported.
serverSide - Indicates if server side authentication is supported.
Method Detail

authenticate

public int authenticate(ChallengeResponse cr,
                        Request request,
                        Guard guard)
Indicates if the call is properly authenticated. You are guaranteed that the request has a challenge response with a scheme matching the one supported by the plugin.

Parameters:
cr - The challenge response in the request.
request - The request to authenticate.
guard - The associated guard to callback.
Returns:
-1 if the given credentials were invalid, 0 if no credentials were found and 1 otherwise.
See Also:
Guard.checkSecret(Request, String, char[])

challenge

public void challenge(Response response,
                      boolean stale,
                      Guard guard)
Challenges the client by adding a challenge request to the response and by setting the status to CLIENT_ERROR_UNAUTHORIZED.

Parameters:
response - The response to update.
stale - Indicates if the new challenge is due to a stale response.
guard - The associated guard to callback.

format

public java.lang.String format(ChallengeRequest request)
Formats a challenge request as a HTTP header value.

Parameters:
request - The challenge request to format.
Returns:
The authenticate header value.

format

public java.lang.String format(ChallengeResponse challenge,
                               Request request,
                               Series<Parameter> httpHeaders)
Formats a challenge response as raw credentials.

Parameters:
challenge - The challenge response to format.
request - The parent request.
httpHeaders - The current request HTTP headers.
Returns:
The authorization header value.

formatCredentials

public abstract void formatCredentials(java.lang.StringBuilder sb,
                                       ChallengeResponse challenge,
                                       Request request,
                                       Series<Parameter> httpHeaders)
Formats a challenge response as raw credentials.

Parameters:
sb - The String builder to update.
challenge - The challenge response to format.
request - The parent request.
httpHeaders - The current request HTTP headers.

formatParameters

public void formatParameters(java.lang.StringBuilder sb,
                             Series<Parameter> parameters,
                             ChallengeRequest request)
Formats the parameters of a challenge request, to be appended to the scheme technical name and realm.

Parameters:
sb - The string builder to update.
parameters - The parameters to format.
request - The challenger request.

getChallengeScheme

public ChallengeScheme getChallengeScheme()
Returns the supported challenge scheme.

Returns:
The supported challenge scheme.

getLogger

public java.util.logging.Logger getLogger()
Returns the context's logger.

Returns:
The context's logger.

isClientSide

public boolean isClientSide()
Indicates if client side authentication is supported.

Returns:
True if client side authentication is supported.

isServerSide

public boolean isServerSide()
Indicates if server side authentication is supported.

Returns:
True if server side authentication is supported.

parseRequest

public void parseRequest(ChallengeRequest cr,
                         java.lang.String header)
Parses an authenticate header into a challenge request.

Parameters:
header - The HTTP header value to parse.

parseResponse

public void parseResponse(ChallengeResponse cr,
                          Request request)
Parses an authorization header into a challenge response.

Parameters:
request - The request.

setChallengeScheme

public void setChallengeScheme(ChallengeScheme challengeScheme)
Sets the supported challenge scheme.

Parameters:
challengeScheme - The supported challenge scheme.

setClientSide

public void setClientSide(boolean clientSide)
Indicates if client side authentication is supported.

Parameters:
clientSide - True if client side authentication is supported.

setServerSide

public void setServerSide(boolean serverSide)
Indicates if server side authentication is supported.

Parameters:
serverSide - True if server side authentication is supported.


Copyright © 2005-2008 Noelios Technologies.