Class AuthService

java.lang.Object
com.axelor.auth.AuthService

@Singleton public class AuthService extends Object
The 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.

  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
  • Constructor Details

    • AuthService

      public AuthService()
  • Method Details

    • getInstance

      public static AuthService getInstance()
      Get the instance of the AuthService.
      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 engine
      context - 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 text
      saved - the saved password text (hashed)
      Returns:
      true if they match
    • changePassword

      public void changePassword(User user, String password)
      Changes user password.
      Parameters:
      user - the user whose password needs to be changed
      password - the new plain-text password
      Throws:
      ChangePasswordException - if unable to validate password policies
    • validatePasswordPolicies

      public InvalidPolicy validatePasswordPolicies(User user, String password)
      Validates the given password against the configured password policies for the specified user.
      Parameters:
      user - the user for whom the password policies need to be validated
      password - the password to validate against the policies
      Returns:
      InvalidPolicy if any policy is violated, null otherwise
    • getPasswordPolicyDescriptions

      public List<String> getPasswordPolicyDescriptions()
      Returns the translated descriptions of all currently enabled password policies, in evaluation order. Intended for display as requirements guidance on the login or change-password page.
      Returns:
      an ordered list of translated policy requirement strings