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 mostPasswordProviderimplementations, 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.OmeroContextctxprotected java.lang.StringhashHash implementation to use for encoding passwords to check and changed passwords.protected booleanignoreUnknownIf true, this implementation should return a null oncheckPassword(String, String, boolean)if the user is unknown, otherwise aBoolean.FALSE.protected PasswordUtillegacyUtilPossibly nullPasswordUtilinstance which will be used as a fallback for password checks if theutilinstance fails.protected org.slf4j.Loggerlogprotected booleansaltWhether or not salting based on the user ID should be attempted.protected PasswordUtilutil
-
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 voidchangePassword(java.lang.String user, java.lang.String password)Throws by default.java.lang.BooleancheckPassword(java.lang.String user, java.lang.String password, boolean readOnly)If this was constructed with theignoreUnknownargument set totrue, returnsnull, since the base class knows no users.java.lang.BooleancomparePasswords(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 booleancomparePasswords(java.lang.Long userId, java.lang.String trusted, java.lang.String provided, PasswordUtil util)java.lang.BooleancomparePasswords(java.lang.String trusted, java.lang.String provided)Compares the password provided by the user (unhashed) against the given trusted password.protected java.lang.StringencodePassword(java.lang.Long userId, java.lang.String newPassword, boolean salt, PasswordUtil util)java.lang.StringencodePassword(java.lang.String newPassword)Encodes the password as it would be encoded for a check bycomparePasswords(String, String)java.lang.StringencodeSaltedPassword(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.booleanhasPassword(java.lang.String user)Always returns false, override with specific logic.protected java.lang.BooleanloginAttempt(java.lang.String user, java.lang.Boolean success)voidsetApplicationContext(org.springframework.context.ApplicationContext ctx)voidsetLegacyUtil(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 nullPasswordUtilinstance which will be used as a fallback for password checks if theutilinstance 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 returnnullrather thanBoolean.FALSEfor 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:
setApplicationContextin 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:
hasPasswordin interfacePasswordProvider
-
checkPassword
public java.lang.Boolean checkPassword(java.lang.String user, java.lang.String password, boolean readOnly)If this was constructed with theignoreUnknownargument set totrue, returnsnull, since the base class knows no users. Otherwise, returnsBoolean.FALSEspecifying that authentication should fail.- Specified by:
checkPasswordin interfacePasswordProvider
-
changePassword
public void changePassword(java.lang.String user, java.lang.String password) throws PasswordChangeExceptionThrows by default.- Specified by:
changePasswordin 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:
encodePasswordin 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:
comparePasswordsin 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)
-
-