public class QueryAndEncodeDatabaseAuthenticationHandler extends AbstractJdbcUsernamePasswordAuthenticationHandler
This handler uses the hashing method defined by Apache Shiro's
DefaultHashService
. Refer to the Javadocs
to learn more about the behavior. If the hashing behavior and/or configuration
of private and public salts does nto meet your needs, a extension can be developed
to specify alternative methods of encoding and digestion of the encoded password.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
algorithmName
The Algorithm name.
|
protected long |
numberOfIterations
The number of iterations.
|
protected java.lang.String |
numberOfIterationsFieldName
The Number of iterations field name.
|
protected java.lang.String |
passwordFieldName
The Password field name.
|
protected java.lang.String |
saltFieldName
The Salt field name.
|
protected java.lang.String |
sql
The Sql statement to execute.
|
protected java.lang.String |
staticSalt
The static/private salt.
|
logger, principalFactory, servicesManager
SUCCESSFUL_AUTHENTICATION_HANDLERS
Constructor and Description |
---|
QueryAndEncodeDatabaseAuthenticationHandler() |
Modifier and Type | Method and Description |
---|---|
protected HandlerResult |
authenticateUsernamePasswordInternal(UsernamePasswordCredential transformedCredential)
Authenticates a username/password credential by an arbitrary strategy.
|
protected java.lang.String |
digestEncodedPassword(java.lang.String encodedPassword,
java.util.Map<java.lang.String,java.lang.Object> values)
Digest encoded password.
|
void |
setAlgorithmName(java.lang.String algorithmName) |
void |
setNumberOfIterations(long numberOfIterations) |
void |
setNumberOfIterationsFieldName(java.lang.String numberOfIterationsFieldName) |
void |
setPasswordFieldName(java.lang.String passwordFieldName) |
void |
setSaltFieldName(java.lang.String saltFieldName) |
void |
setSql(java.lang.String sql) |
void |
setStaticSalt(java.lang.String staticSalt)
Sets static/private salt to be combined with the dynamic salt retrieved
from the database.
|
getDataSource, getJdbcTemplate, setDataSource
doAuthentication, getPasswordPolicyConfiguration, setCredentialSelectionPredicate, setPasswordEncoder, setPasswordPolicyConfiguration, setPrincipalNameTransformer, supports
authenticate, createHandlerResult, postAuthenticate, preAuthenticate
getName, setName, setPrincipalFactory, setServicesManager
protected java.lang.String algorithmName
protected java.lang.String sql
protected java.lang.String passwordFieldName
protected java.lang.String saltFieldName
protected java.lang.String numberOfIterationsFieldName
protected long numberOfIterations
protected java.lang.String staticSalt
public QueryAndEncodeDatabaseAuthenticationHandler()
protected HandlerResult authenticateUsernamePasswordInternal(UsernamePasswordCredential transformedCredential) throws java.security.GeneralSecurityException, PreventedException
AbstractUsernamePasswordAuthenticationHandler
authenticateUsernamePasswordInternal
in class AbstractUsernamePasswordAuthenticationHandler
transformedCredential
- the credential object bearing the transformed username and password.java.security.GeneralSecurityException
- On authentication failure.PreventedException
- On the indeterminate case when authentication is prevented.protected java.lang.String digestEncodedPassword(java.lang.String encodedPassword, java.util.Map<java.lang.String,java.lang.Object> values)
encodedPassword
- the encoded passwordvalues
- the values retrieved from databasepublic void setAlgorithmName(java.lang.String algorithmName)
public void setSql(java.lang.String sql)
public void setStaticSalt(java.lang.String staticSalt)
If using this implementation as part of a password hashing strategy, it might be desirable to configure a private salt. A hash and the salt used to compute it are often stored together. If an attacker is ever able to access the hash (e.g. during password cracking) and it has the full salt value, the attacker has all of the input necessary to try to brute-force crack the hash (source + complete salt).
However, if part of the salt is not available to the attacker (because it is not stored with the hash), it is much harder to crack the hash value since the attacker does not have the complete inputs necessary. The privateSalt property exists to satisfy this private-and-not-shared part of the salt.
If you configure this attribute, you can obtain this additional very important safety feature.
staticSalt
- the static saltpublic void setPasswordFieldName(java.lang.String passwordFieldName)
public void setSaltFieldName(java.lang.String saltFieldName)
public void setNumberOfIterationsFieldName(java.lang.String numberOfIterationsFieldName)
public void setNumberOfIterations(long numberOfIterations)