Package com.axelor.auth
Class AuthService
- java.lang.Object
-
- com.axelor.auth.AuthService
-
@Singleton public class AuthService extends Object
TheAuthService
class provides various utility services including password encryption, password match and saving user password in encrypted form.The
AuthService
should not be manually instantiated but either injected or usergetInstance()
method to get the instance of the service.
-
-
Constructor Summary
Constructors Constructor Description AuthService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changePassword(User user, String password)
Changes user password.void
checkPassword(ActionRequest request, ActionResponse response)
Helper action to check user password.User
encrypt(User user)
Encrypt the password of the given user.Object
encrypt(Object user, Map context)
This is an adapter method to be used with data import.String
encrypt(String password)
Encrypt the given password text if it's not encrypted yet.static AuthService
getInstance()
Get the instance of theAuthService
.String
getPasswordPattern()
Gets configured user password pattern.String
getPasswordPatternTitle()
Gets configured user password pattern description.boolean
match(String plain, String saved)
Match the given plain and saved passwords.boolean
passwordMatchesPattern(String password)
Checks whether the password matches the configured pattern.
-
-
-
Method Detail
-
getInstance
public static AuthService getInstance()
Get the instance of theAuthService
.- Returns:
- the
AuthService
instance - Throws:
IllegalStateException
- if AuthService is not initialized
-
encrypt
public String encrypt(String password)
Encrypt the given password text if it's not encrypted yet.The method tests the password for a special format to check if it is already encrypted, and In that case the password is returned as it is to avoid multiple encryption.
- Parameters:
password
- the password to encrypt- Returns:
- encrypted password
-
encrypt
public User encrypt(User user)
Encrypt the password of the given user.- Parameters:
user
- the user whose password needs to be encrypted- Returns:
- the same user instance
-
encrypt
public Object encrypt(Object user, Map context)
This is an adapter method to be used with data import.This method can be used as
call="com.axelor.auth.AuthService:encrypt"
while importing user data to ensure user passwords are encrypted.- Parameters:
user
- the object instance passed by data import enginecontext
- the data import context- Returns:
- the same instance passed
-
match
public boolean match(String plain, String saved)
Match the given plain and saved passwords.- Parameters:
plain
- the plain password textsaved
- the saved password text (hashed)- Returns:
- true if they match
-
checkPassword
public void checkPassword(ActionRequest request, ActionResponse response)
Helper action to check user password.- Parameters:
request
- the request with username and password as context or dataresponse
- the response, with user details if password matched
-
changePassword
public void changePassword(User user, String password)
Changes user password.- Parameters:
user
-password
-
-
passwordMatchesPattern
public boolean passwordMatchesPattern(String password)
Checks whether the password matches the configured pattern.- Parameters:
password
-- Returns:
-
getPasswordPattern
public String getPasswordPattern()
Gets configured user password pattern.- Returns:
-
getPasswordPatternTitle
public String getPasswordPatternTitle()
Gets configured user password pattern description.- Returns:
-
-