Package org.restlet.security
Class Authenticator
java.lang.Object
org.restlet.Restlet
org.restlet.routing.Filter
org.restlet.security.Authenticator
- All Implemented Interfaces:
Uniform
- Direct Known Subclasses:
CertificateAuthenticator,ChallengeAuthenticator
Filter authenticating the client sending the inbound request. Its main role
is to inspect various credentials provided by the client and to add related
application roles to the request's
ClientInfo property.- Author:
- Jerome Louvel
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionAuthenticator(Context context) Constructor setting the mode to "required".Authenticator(Context context, boolean optional) Constructor using the context's default enroler.Authenticator(Context context, boolean multiAuthenticating, boolean optional, Enroler enroler) Constructor.Authenticator(Context context, boolean optional, Enroler enroler) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanauthenticate(Request request, Response response) Attempts to authenticate the subject sending the request.protected intauthenticated(Request request, Response response) Invoked upon successful authentication.protected intbeforeHandle(Request request, Response response) Handles the authentication by first invoking theauthenticate(Request, Response)method, only ifisMultiAuthenticating()returns true and ifClientInfo.isAuthenticated()returns false.Returns the enroler invoked upon successful authentication to update the subject with new principals.booleanIndicates if the authenticator should attempt to authenticate an already authenticated client.booleanIndicates if the authenticator is not required to succeed.voidsetEnroler(Enroler enroler) Sets the enroler invoked upon successful authentication.voidsetMultiAuthenticating(boolean multiAuthenticating) Indicates if the authenticator should attempt to authenticate an already authenticated client.voidsetOptional(boolean optional) Indicates if the authenticator is not required to succeed.protected intunauthenticated(Request request, Response response) Invoked upon failed authentication.Methods inherited from class org.restlet.routing.Filter
afterHandle, doHandle, getNext, handle, hasNext, setNext, setNext, start, stopMethods inherited from class org.restlet.Restlet
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner
-
Constructor Details
-
Authenticator
Constructor setting the mode to "required".- Parameters:
context- The context.- See Also:
-
Authenticator
Constructor using the context's default enroler.- Parameters:
context- The context.optional- Indicates if the authenticator is not required to succeed.- See Also:
-
Authenticator
public Authenticator(Context context, boolean multiAuthenticating, boolean optional, Enroler enroler) Constructor.- Parameters:
context- The context.multiAuthenticating- Indicates if the authenticator should attempt to authenticate an already authenticated client.optional- Indicates if the authenticator is not required to succeed.enroler- The enroler to invoke upon successful authentication.
-
Authenticator
Constructor.- Parameters:
context- The context.optional- Indicates if the authenticator is not required to succeed.enroler- The enroler to invoke upon successful authentication.
-
-
Method Details
-
authenticate
Attempts to authenticate the subject sending the request.- Parameters:
request- The request sent.response- The response to update.- Returns:
- True if the authentication succeeded.
-
authenticated
Invoked upon successful authentication. By default, it updates the request's clientInfo and challengeResponse "authenticated" properties, clears the existing challenge requests on the response, calls the enroler and finally returnsFilter.CONTINUE.- Parameters:
request- The request sent.response- The response to update.- Returns:
- The filter continuation code.
-
beforeHandle
Handles the authentication by first invoking theauthenticate(Request, Response)method, only ifisMultiAuthenticating()returns true and ifClientInfo.isAuthenticated()returns false. If the method is invoked and returns true, theauthenticated(Request, Response)is called. Otherwise, ifisOptional()returns true it continues to the next Restlet or if it returns false it calls theunauthenticated(Request, Response)method.- Overrides:
beforeHandlein classFilter- Parameters:
request- The request to handle.response- The response to update.- Returns:
- The continuation status. Either
Filter.CONTINUEorFilter.SKIPorFilter.STOP.
-
getEnroler
Returns the enroler invoked upon successful authentication to update the subject with new principals. Typically newRoleare added based on the availableUserinstances available.- Returns:
- The enroler invoked upon successful authentication
-
isMultiAuthenticating
public boolean isMultiAuthenticating()Indicates if the authenticator should attempt to authenticate an already authenticated client. The client is considered authenticated ifClientInfo.isAuthenticated()returns true. By default, it is set to true.- Returns:
- True if the authenticator should attempt to authenticate an already authenticated client.
-
isOptional
public boolean isOptional()Indicates if the authenticator is not required to succeed. In those cases, the attached Restlet is invoked. Note that authentication will be attempted independently of this property unless the client is already authenticated and theisMultiAuthenticating()prevents multiple authentications.- Returns:
- True if the authentication success is optional.
-
setEnroler
Sets the enroler invoked upon successful authentication.- Parameters:
enroler- The enroler invoked upon successful authentication.
-
setMultiAuthenticating
public void setMultiAuthenticating(boolean multiAuthenticating) Indicates if the authenticator should attempt to authenticate an already authenticated client. The client is considered authenticated ifClientInfo.isAuthenticated()returns true. By default, it is set to true.- Parameters:
multiAuthenticating- True if the authenticator should attempt to authenticate an already authenticated client.
-
setOptional
public void setOptional(boolean optional) Indicates if the authenticator is not required to succeed. In those cases, the attached Restlet is invoked. Note that authentication will be attempted independently of this property unless the client is already authenticated and theisMultiAuthenticating()prevents multiple authentications.- Parameters:
optional- True if the authentication success is optional.
-
unauthenticated
Invoked upon failed authentication. By default, it updates the request's clientInfo and challengeResponse "authenticated" properties, and returnsFilter.STOP.- Parameters:
request- The request sent.response- The response to update.- Returns:
- The filter continuation code.
-