public abstract class ConfigurablePasswordProvider extends java.lang.Object implements PasswordProvider, PasswordUtility, org.springframework.context.ApplicationContextAware
PasswordProvider
implementations, providing
configuration for default behaviors. There is no need for a subclass to
use this implementation.SecuritySystem
,
Permissions
Modifier and Type | Field and Description |
---|---|
protected OmeroContext |
ctx |
protected java.lang.String |
hash
Hash implementation to use for encoding passwords to check and changed
passwords.
|
protected boolean |
ignoreUnknown
If true, this implementation should return a null on
checkPassword(String, String, boolean) if the user is unknown,
otherwise a Boolean.FALSE . |
protected PasswordUtil |
legacyUtil
Possibly null
PasswordUtil instance which will be used as a
fallback for password checks if the util instance fails. |
protected org.slf4j.Logger |
log |
protected boolean |
salt
Whether or not salting based on the user ID should be attempted.
|
protected PasswordUtil |
util |
Constructor and Description |
---|
ConfigurablePasswordProvider(PasswordUtil util)
Call
ConfigurablePasswordProvider(PasswordUtil, boolean)
with "ignoreUnknown" equal to false. |
ConfigurablePasswordProvider(PasswordUtil util,
boolean ignoreUnknown)
Call
ConfigurablePasswordProvider(PasswordUtil, boolean, boolean)
with "salt" equal to false. |
ConfigurablePasswordProvider(PasswordUtil util,
boolean ignoreUnknown,
boolean salt) |
Modifier and Type | Method and Description |
---|---|
void |
changePassword(java.lang.String user,
java.lang.String password)
Throws by default.
|
java.lang.Boolean |
checkPassword(java.lang.String user,
java.lang.String password,
boolean readOnly)
If this was constructed with the
ignoreUnknown argument set to
true , returns null , since the base class knows no users. |
java.lang.Boolean |
comparePasswords(java.lang.Long userId,
java.lang.String trusted,
java.lang.String provided)
Compares the password provided by the user (unhashed) against the given
trusted password.
|
protected boolean |
comparePasswords(java.lang.Long userId,
java.lang.String trusted,
java.lang.String provided,
PasswordUtil util) |
java.lang.Boolean |
comparePasswords(java.lang.String trusted,
java.lang.String provided)
Compares the password provided by the user (unhashed) against the given
trusted password.
|
protected java.lang.String |
encodePassword(java.lang.Long userId,
java.lang.String newPassword,
boolean salt,
PasswordUtil util) |
java.lang.String |
encodePassword(java.lang.String newPassword)
Encodes the password as it would be encoded for a check by
comparePasswords(String, String) |
java.lang.String |
encodeSaltedPassword(java.lang.Long userId,
java.lang.String newPassword)
Encodes the password as it would be encoded for a check by
comparePasswords(String, String) salting the password
with the given userId if it's provided. |
boolean |
hasPassword(java.lang.String user)
Always returns false, override with specific logic.
|
protected java.lang.Boolean |
loginAttempt(java.lang.String user,
java.lang.Boolean success) |
void |
setApplicationContext(org.springframework.context.ApplicationContext ctx) |
void |
setLegacyUtil(PasswordUtil legacy) |
protected final org.slf4j.Logger log
protected final java.lang.String hash
protected final boolean salt
protected final boolean ignoreUnknown
checkPassword(String, String, boolean)
if the user is unknown,
otherwise a Boolean.FALSE
. Default value: falseprotected final PasswordUtil util
protected PasswordUtil legacyUtil
PasswordUtil
instance which will be used as a
fallback for password checks if the util
instance fails.protected OmeroContext ctx
public ConfigurablePasswordProvider(PasswordUtil util)
ConfigurablePasswordProvider(PasswordUtil, boolean)
with "ignoreUnknown" equal to false.util
- an instance of the password utility classpublic ConfigurablePasswordProvider(PasswordUtil util, boolean ignoreUnknown)
ConfigurablePasswordProvider(PasswordUtil, boolean, boolean)
with "salt" equal to false.util
- an instance of the password utility classignoreUnknown
- if checkPassword(String, String, boolean)
should
return null
rather than Boolean.FALSE
for unknown userspublic ConfigurablePasswordProvider(PasswordUtil util, boolean ignoreUnknown, boolean salt)
public void setApplicationContext(org.springframework.context.ApplicationContext ctx) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
public void setLegacyUtil(PasswordUtil legacy)
protected java.lang.Boolean loginAttempt(java.lang.String user, java.lang.Boolean success)
public boolean hasPassword(java.lang.String user)
hasPassword
in interface PasswordProvider
public java.lang.Boolean checkPassword(java.lang.String user, java.lang.String password, boolean readOnly)
ignoreUnknown
argument set to
true
, returns null
, since the base class knows no users.
Otherwise, returns Boolean.FALSE
specifying that
authentication should fail.checkPassword
in interface PasswordProvider
public void changePassword(java.lang.String user, java.lang.String password) throws PasswordChangeException
changePassword
in interface PasswordProvider
PasswordChangeException
public java.lang.String encodePassword(java.lang.String newPassword)
comparePasswords(String, String)
encodePassword
in interface PasswordUtility
public java.lang.String encodeSaltedPassword(java.lang.Long userId, java.lang.String newPassword)
comparePasswords(String, String)
salting the password
with the given userId if it's provided.userId
- a user ID (may be null
)newPassword
- a passwordprotected java.lang.String encodePassword(java.lang.Long userId, java.lang.String newPassword, boolean salt, PasswordUtil util)
public java.lang.Boolean comparePasswords(java.lang.String trusted, java.lang.String provided)
checkPassword(String, String, boolean)
.
For this implementation, if the trusted password is null, return
Boolean.FALSE
. If the trusted password is empty (only
whitespace), return Boolean.TRUE
. Otherwise return the result of
String.equals(Object)
.comparePasswords
in interface PasswordUtility
public java.lang.Boolean comparePasswords(java.lang.Long userId, java.lang.String trusted, java.lang.String provided)
Boolean.FALSE
. If the trusted password is empty (only
whitespace), return Boolean.TRUE
. Otherwise return the results of
String.equals(Object)
.
If necessary, falls back to using a legacy password utility class if one was set by setLegacyUtil(PasswordUtil)
.userId
- a user IDtrusted
- the user's trusted passwordprovided
- the provided passwordprotected boolean comparePasswords(java.lang.Long userId, java.lang.String trusted, java.lang.String provided, PasswordUtil util)
Version: 5.4.6-ice35-b87
Copyright © 2018 The University of Dundee & Open Microscopy Environment. All Rights Reserved.