Class AbstractUsernamePasswordAuthHandler
- All Implemented Interfaces:
AuthenticationHandler
- Direct Known Subclasses:
DbAuthenticationHandler
Abstract implementation of an AuthenticationHandler
that supports authentication of
UsernamePasswordCredentials
.
It leaves the retrieval of the principal to the PrincipalDetailService
that needs
to be injected into implementations of this class. It delegates to methods of subclasses
to finalize authentication.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected List
<UsernamePasswordAuthenticator> Fields inherited from interface ch.tocco.nice2.security.spi.auth.AuthenticationHandler
ANONYMOUS_HANDLER_ORDER, API_KEY_PK_ATTRIBUTE, PRINCIPAL_PK_ATTRIBUTE, SESSION_HASH_HANDLER_ORDER, SESSION_ID_ATTRIBUTE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
authenticate
(Challenge challenge, Credentials credentials) Authenticates the given challenge by voting for or against it.protected abstract void
doAuthenticate
(Challenge challenge, @Nullable PrincipalDetails principalDetails, UsernamePasswordCredentials credentials) After the principal is retrieved using the configuredPrincipalDetailService
, this method is invoked right afterwards to let subclasses do further authentication checks and finally call theChallenge.vote(Challenge.State)
method.protected abstract boolean
doSetCredentials
(PrincipalDetails principalDetails, UsernamePasswordCredentials oldCredentials, Credentials newCredentials) Set new credentials for the passed principal.protected PrincipalDetailService
void
void
setAuthenticators
(List<UsernamePasswordAuthenticator> authenticators) void
setPrincipalService
(PrincipalDetailService principalService) final boolean
updateCredentials
(Credentials oldCredentials, Credentials newCredentials) Updates the credentials for this handler.Methods inherited from class ch.tocco.nice2.security.spi.auth.AuthenticationHandlerAdapter
getName, postAuthenticate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.tocco.nice2.security.spi.auth.AuthenticationHandler
postEventListeners
-
Field Details
-
ATTR_PRINCIPAL_DETAILS
- See Also:
-
authenticators
-
-
Constructor Details
-
AbstractUsernamePasswordAuthHandler
public AbstractUsernamePasswordAuthHandler()
-
-
Method Details
-
setAuthenticators
-
authenticate
Description copied from interface:AuthenticationHandler
Authenticates the given challenge by voting for or against it.
If the supplied credentials are unknown to this handler, it may not vote at all, indicating no meaningful knowledge about the challenge.
- Specified by:
authenticate
in interfaceAuthenticationHandler
- Overrides:
authenticate
in classAuthenticationHandlerAdapter
- Parameters:
challenge
- the authentication challengecredentials
- the credentials supplied by client in case of non-recoverable error. An exception will immediately stop authentication process to failed state.
-
doAuthenticate
protected abstract void doAuthenticate(Challenge challenge, @Nullable @Nullable PrincipalDetails principalDetails, UsernamePasswordCredentials credentials) After the principal is retrieved using the configuredPrincipalDetailService
, this method is invoked right afterwards to let subclasses do further authentication checks and finally call theChallenge.vote(Challenge.State)
method.As subclasses configure its instance with their concrete
PrincipalDetailService
you are safe to cast thePrincipalDetails
argument to your specific type.- Parameters:
challenge
- the challenge to be authenticatedprincipalDetails
- the principal details just loaded (may be null if principal could not be found)credentials
- the concrete username and password credentials
-
updateCredentials
Description copied from interface:AuthenticationHandler
Updates the credentials for this handler.If this handler is not supporting this, return
.false
In case of an exception, the whole process is stopped immediately.
- Specified by:
updateCredentials
in interfaceAuthenticationHandler
- Overrides:
updateCredentials
in classAuthenticationHandlerAdapter
- Parameters:
oldCredentials
- the old credentials are used to get the principalnewCredentials
- the new credentials to set. authentication handlers should only support their sepcific type of credentials- Returns:
- true if credentials were updated successfully, false if skipped
-
doSetCredentials
protected abstract boolean doSetCredentials(PrincipalDetails principalDetails, UsernamePasswordCredentials oldCredentials, Credentials newCredentials) Set new credentials for the passed principal. This is only invoked for any instance ofUsernamePasswordCredentials
that were used to get the principal. The old credentials are also passed in together with new credentials.The type of argument
newCredentials
should be used to check if this handler supports setting new credentials. Returnfalse
if the type ofnewCredentials
is not supported.- Parameters:
principalDetails
- details about the principal that wants to set new credentialsoldCredentials
- the old credentials of the principalnewCredentials
- new credentials to set.- Returns:
true
if setting was successful,false
if action was skipped
-
initializeService
@PostConstruct public void initializeService() -
setPrincipalService
-
getPrincipalDetailService
-