@Singleton public class AuthService extends Object
AuthService
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 user getInstance()
method to get the instance of the service.
Constructor and Description |
---|
AuthService() |
Modifier and Type | Method and Description |
---|---|
void |
changePassword(User user,
String password)
Changes user password.
|
void |
checkPassword(ActionRequest request,
ActionResponse response)
Helper action to check user password.
|
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.
|
User |
encrypt(User user)
Encrypt the password of the given user.
|
static AuthService |
getInstance()
Get the instance of the
AuthService . |
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.
|
@Inject public AuthService()
public static AuthService getInstance()
AuthService
.AuthService
instanceIllegalStateException
- if AuthService is not initializedpublic String encrypt(String password)
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.
password
- the password to encryptpublic User encrypt(User user)
user
- the user whose password needs to be encryptedpublic Object encrypt(Object user, Map context)
This method can be used as call="com.axelor.auth.AuthService:encrypt"
while
importing user data to ensure user passwords are encrypted.
user
- the object instance passed by data import enginecontext
- the data import contextpublic boolean match(String plain, String saved)
plain
- the plain password textsaved
- the saved password text (hashed)public void checkPassword(ActionRequest request, ActionResponse response)
request
- the request with username & password as context or dataresponse
- the response, with user details if password matchedpublic void changePassword(User user, String password)
user
- newPassword
- public boolean passwordMatchesPattern(String password)
password
- public String getPasswordPattern()
public String getPasswordPatternTitle()