Package ome.security.auth
Class ConfigurablePasswordProvider
- java.lang.Object
-
- ome.security.auth.ConfigurablePasswordProvider
-
- All Implemented Interfaces:
PasswordProvider
,PasswordUtility
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
FilePasswordProvider
,JdbcPasswordProvider
,LdapPasswordProvider
,LdapPasswordProvider431
public abstract class ConfigurablePasswordProvider extends java.lang.Object implements PasswordProvider, PasswordUtility, org.springframework.context.ApplicationContextAware
Base class for mostPasswordProvider
implementations, providing configuration for default behaviors. There is no need for a subclass to use this implementation.- Since:
- 4.0
- See Also:
SecuritySystem
,Permissions
-
-
Field Summary
Fields Modifier and Type Field Description protected ome.system.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 oncheckPassword(String, String, boolean)
if the user is unknown, otherwise aBoolean.FALSE
.protected PasswordUtil
legacyUtil
Possibly nullPasswordUtil
instance which will be used as a fallback for password checks if theutil
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 Summary
Constructors Constructor Description ConfigurablePasswordProvider(PasswordUtil util)
CallConfigurablePasswordProvider(PasswordUtil, boolean)
with "ignoreUnknown" equal to false.ConfigurablePasswordProvider(PasswordUtil util, boolean ignoreUnknown)
CallConfigurablePasswordProvider(PasswordUtil, boolean, boolean)
with "salt" equal to false.ConfigurablePasswordProvider(PasswordUtil util, boolean ignoreUnknown, boolean salt)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 theignoreUnknown
argument set totrue
, returnsnull
, 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 bycomparePasswords(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 bycomparePasswords(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)
-
-
-
Field Detail
-
log
protected final org.slf4j.Logger log
-
hash
protected final java.lang.String hash
Hash implementation to use for encoding passwords to check and changed passwords. Default value: MD5 (For the moment, the only supported value!)
-
salt
protected final boolean salt
Whether or not salting based on the user ID should be attempted.
-
ignoreUnknown
protected final boolean ignoreUnknown
If true, this implementation should return a null oncheckPassword(String, String, boolean)
if the user is unknown, otherwise aBoolean.FALSE
. Default value: false
-
util
protected final PasswordUtil util
-
legacyUtil
protected PasswordUtil legacyUtil
Possibly nullPasswordUtil
instance which will be used as a fallback for password checks if theutil
instance fails.
-
ctx
protected ome.system.OmeroContext ctx
-
-
Constructor Detail
-
ConfigurablePasswordProvider
public ConfigurablePasswordProvider(PasswordUtil util)
CallConfigurablePasswordProvider(PasswordUtil, boolean)
with "ignoreUnknown" equal to false.- Parameters:
util
- an instance of the password utility class
-
ConfigurablePasswordProvider
public ConfigurablePasswordProvider(PasswordUtil util, boolean ignoreUnknown)
CallConfigurablePasswordProvider(PasswordUtil, boolean, boolean)
with "salt" equal to false.- Parameters:
util
- an instance of the password utility classignoreUnknown
- ifcheckPassword(String, String, boolean)
should returnnull
rather thanBoolean.FALSE
for unknown users
-
ConfigurablePasswordProvider
public ConfigurablePasswordProvider(PasswordUtil util, boolean ignoreUnknown, boolean salt)
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext ctx) throws org.springframework.beans.BeansException
- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
setLegacyUtil
public void setLegacyUtil(PasswordUtil legacy)
-
loginAttempt
protected java.lang.Boolean loginAttempt(java.lang.String user, java.lang.Boolean success)
-
hasPassword
public boolean hasPassword(java.lang.String user)
Always returns false, override with specific logic.- Specified by:
hasPassword
in interfacePasswordProvider
-
checkPassword
public java.lang.Boolean checkPassword(java.lang.String user, java.lang.String password, boolean readOnly)
If this was constructed with theignoreUnknown
argument set totrue
, returnsnull
, since the base class knows no users. Otherwise, returnsBoolean.FALSE
specifying that authentication should fail.- Specified by:
checkPassword
in interfacePasswordProvider
-
changePassword
public void changePassword(java.lang.String user, java.lang.String password) throws PasswordChangeException
Throws by default.- Specified by:
changePassword
in interfacePasswordProvider
- Throws:
PasswordChangeException
-
encodePassword
public java.lang.String encodePassword(java.lang.String newPassword)
Encodes the password as it would be encoded for a check bycomparePasswords(String, String)
- Specified by:
encodePassword
in interfacePasswordUtility
-
encodeSaltedPassword
public java.lang.String encodeSaltedPassword(java.lang.Long userId, java.lang.String newPassword)
Encodes the password as it would be encoded for a check bycomparePasswords(String, String)
salting the password with the given userId if it's provided.- Parameters:
userId
- a user ID (may benull
)newPassword
- a password- Returns:
- the encoded password
-
encodePassword
protected java.lang.String encodePassword(java.lang.Long userId, java.lang.String newPassword, boolean salt, PasswordUtil util)
-
comparePasswords
public 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. A return value of null, however, is also possible with the same semantics as a null fromcheckPassword(String, String, boolean)
. For this implementation, if the trusted password is null, returnBoolean.FALSE
. If the trusted password is empty (only whitespace), returnBoolean.TRUE
. Otherwise return the result ofString.equals(Object)
.- Specified by:
comparePasswords
in interfacePasswordUtility
-
comparePasswords
public 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. In general, if the trusted password is null, returnBoolean.FALSE
. If the trusted password is empty (only whitespace), returnBoolean.TRUE
. Otherwise return the results ofString.equals(Object)
. If necessary, falls back to using a legacy password utility class if one was set bysetLegacyUtil(PasswordUtil)
.- Parameters:
userId
- a user IDtrusted
- the user's trusted passwordprovided
- the provided password- Returns:
- if the provided password matches the trusted password (for which blank matches anything)
-
comparePasswords
protected boolean comparePasswords(java.lang.Long userId, java.lang.String trusted, java.lang.String provided, PasswordUtil util)
-
-