Interface UserAccountService


public interface UserAccountService
Administrator operations on user accounts, reached by the REST resources of this module at call time through the container, since its implementation lives in the web security module, above this one in the module graph.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The creation source stamped on an account created by an administrator from the users-management screen: such an account keeps the self-service deactivation option
    static final String
    Code answered as 400 when the super user's account is deactivated
    static final String
    Code of an email already held by an account, answered as 400
    static final String
    Code of a language that is not a supported locale, answered as 400
    static final String
    Name of the one-time-password method that confirms an administrator session: a code sent by email, generated and validated for this purpose only, so that a code issued for another flow never confirms a session
    static final String
     
    static final String
     
    static final String
    The parts a read-back reports missing, in this order
    static final String
    Code of an invalid role value, answered as 400
    static final String
    Code answered as 400 when an administrator deactivates their own account
    static final String
    Prefix of the code answered as 500 when the account was created but some of its parts were not stored, and the account was deactivated: USER:CREATED_INCOMPLETE:<username>:<parts>
    static final String
    Prefix of the code answered as 500 when the account was created, some of its parts were not stored, and the deactivation did not hold either: USER:CREATED_INCOMPLETE_ENABLED:<username>:<parts>
    static final String
    Code answered as 500 when nothing was created: the store refused the insert, or the read-back found no account of this request
    static final String
    Code answered as 500 when the new password of an internal-store account does not authenticate after its change; nothing else is written
    static final String
    Code answered as 500 when the new password of a deactivated internal-store account cannot be checked by the user handler in place; nothing else is written
    static final String
    Code answered as 500 when the read-back after an update found a field other than requested: the names, the email, the enabled flag, or the language when the update carried one
    static final String
    Code answered as 500 when every generated login collided and nothing was created
    static final String
    Code of a login already held by a live account, answered as 400
    static final String
    Code of a login once held by a deleted account, which is never created again, answered as 400
    static final String
    Code answered as 400 when the username policy of the platform refuses the form of a generated login, so that the administrator types one instead
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    confirmSession(String username, String otpCode)
    Validates and consumes a one-time-password code sent to the user by the OTP_METHOD method.
    createUser(UserAccount account, Locale locale)
    Creates an account as an administrator described it: the login is the one given, validated, or a generated one; the password is optional, and a blank one leaves the account with no credential until the user sets one from the onboarding email; the role decides the memberships; the language, when given, is stored as the user's preferred language.
     
    getLanguage(String username)
    Reads the preferred language stored for an account
    void
    updateUser(UserAccount account, Locale locale, String modifier)
    Updates an existing account as an administrator edited it: names, email, enabled flag, a password when given and a language when given.
  • Field Details

    • OTP_METHOD

      static final String OTP_METHOD
      Name of the one-time-password method that confirms an administrator session: a code sent by email, generated and validated for this purpose only, so that a code issued for another flow never confirms a session
      See Also:
    • CREATION_SOURCE_UI

      static final String CREATION_SOURCE_UI
      The creation source stamped on an account created by an administrator from the users-management screen: such an account keeps the self-service deactivation option
      See Also:
    • ROLE_INVALID

      static final String ROLE_INVALID
      Code of an invalid role value, answered as 400
      See Also:
    • LANGUAGE_INVALID

      static final String LANGUAGE_INVALID
      Code of a language that is not a supported locale, answered as 400
      See Also:
    • USERNAME_ALREADY_EXISTS

      static final String USERNAME_ALREADY_EXISTS
      Code of a login already held by a live account, answered as 400
      See Also:
    • USERNAME_ALREADY_EXISTS_AS_DELETED

      static final String USERNAME_ALREADY_EXISTS_AS_DELETED
      Code of a login once held by a deleted account, which is never created again, answered as 400
      See Also:
    • USERNAME_GENERATION_NOT_ALLOWED

      static final String USERNAME_GENERATION_NOT_ALLOWED
      Code answered as 400 when the username policy of the platform refuses the form of a generated login, so that the administrator types one instead
      See Also:
    • EMAIL_ALREADY_EXISTS

      static final String EMAIL_ALREADY_EXISTS
      Code of an email already held by an account, answered as 400
      See Also:
    • USER_CREATION_FAILED

      static final String USER_CREATION_FAILED
      Code answered as 500 when nothing was created: the store refused the insert, or the read-back found no account of this request
      See Also:
    • USER_USERNAME_GENERATION_EXHAUSTED

      static final String USER_USERNAME_GENERATION_EXHAUSTED
      Code answered as 500 when every generated login collided and nothing was created
      See Also:
    • USER_CREATED_INCOMPLETE

      static final String USER_CREATED_INCOMPLETE
      Prefix of the code answered as 500 when the account was created but some of its parts were not stored, and the account was deactivated: USER:CREATED_INCOMPLETE:<username>:<parts>
      See Also:
    • USER_CREATED_INCOMPLETE_ENABLED

      static final String USER_CREATED_INCOMPLETE_ENABLED
      Prefix of the code answered as 500 when the account was created, some of its parts were not stored, and the deactivation did not hold either: USER:CREATED_INCOMPLETE_ENABLED:<username>:<parts>
      See Also:
    • USER_UPDATE_INCOMPLETE

      static final String USER_UPDATE_INCOMPLETE
      Code answered as 500 when the read-back after an update found a field other than requested: the names, the email, the enabled flag, or the language when the update carried one
      See Also:
    • USER_PASSWORD_NOT_STORED

      static final String USER_PASSWORD_NOT_STORED
      Code answered as 500 when the new password of an internal-store account does not authenticate after its change; nothing else is written
      See Also:
    • USER_PASSWORD_NOT_VERIFIABLE

      static final String USER_PASSWORD_NOT_VERIFIABLE
      Code answered as 500 when the new password of a deactivated internal-store account cannot be checked by the user handler in place; nothing else is written
      See Also:
    • SELF_DISABLE

      static final String SELF_DISABLE
      Code answered as 400 when an administrator deactivates their own account
      See Also:
    • DISABLE_SUPER_USER

      static final String DISABLE_SUPER_USER
      Code answered as 400 when the super user's account is deactivated
      See Also:
    • PART_MEMBERSHIPS

      static final String PART_MEMBERSHIPS
      The parts a read-back reports missing, in this order
      See Also:
    • PART_LANGUAGE

      static final String PART_LANGUAGE
      See Also:
    • PART_ENABLED

      static final String PART_ENABLED
      See Also:
  • Method Details

    • confirmSession

      void confirmSession(String username, String otpCode) throws IllegalAccessException
      Validates and consumes a one-time-password code sent to the user by the OTP_METHOD method. A code validates once: a second validation of the same code, even within its validity window, is refused.
      Parameters:
      username - user who received the code
      otpCode - code typed by the user
      Throws:
      IllegalAccessException - when the code is blank, wrong, expired, already consumed, or when the user exceeded the allowed attempts
    • createUser

      String createUser(UserAccount account, Locale locale) throws UserAccountCreationException
      Creates an account as an administrator described it: the login is the one given, validated, or a generated one; the password is optional, and a blank one leaves the account with no credential until the user sets one from the onboarding email; the role decides the memberships; the language, when given, is stored as the user's preferred language. Once written, the persisted state is read back in a new transaction, and an account whose parts were not all stored is deactivated.
      Parameters:
      account - the account to create
      locale - the locale of the validation messages
      Returns:
      the login of the created account, generated or given
      Throws:
      IllegalArgumentException - with the code of the refused field as message: USERNAME:, PASSWORD:, FIRSTNAME:, LASTNAME: or EMAIL: followed by the validation message, or one of USERNAME_ALREADY_EXISTS, USERNAME_ALREADY_EXISTS_AS_DELETED, USERNAME_GENERATION_NOT_ALLOWED, EMAIL_ALREADY_EXISTS, ROLE_INVALID, LANGUAGE_INVALID
      UserAccountCreationException - when the store did not complete the creation as requested, with the code as message
    • updateUser

      void updateUser(UserAccount account, Locale locale, String modifier) throws UserAccountUpdateException
      Updates an existing account as an administrator edited it: names, email, enabled flag, a password when given and a language when given. Every refusal is checked before the first write. The password is changed first, through the active change-password connector, and an internal-store account's new password is then proven to authenticate. The other writes follow; they are then read back in a new transaction.
      Parameters:
      account - the account as edited, identified by its login
      locale - the locale of the validation messages
      modifier - the login of the administrator who edits it
      Throws:
      IllegalArgumentException - with the code of the refused field as message: PASSWORD:, FIRSTNAME:, LASTNAME: or EMAIL: followed by the validation message, or one of EMAIL_ALREADY_EXISTS, LANGUAGE_INVALID, SELF_DISABLE, DISABLE_SUPER_USER, USER:EMPTY or USER:NOT_FOUND; nothing is written then
      UserAccountUpdateException - when the store did not complete the update as requested, with the code as message
      IllegalStateException - with no code when the connector refuses the password (an external store's account) or a store read before any write fails; nothing is written then
    • getLanguage

      String getLanguage(String username)
      Reads the preferred language stored for an account
      Parameters:
      username - the login of the account
      Returns:
      the preferred language stored for the account, which may no longer be a supported locale; null when none is stored
    • generateUsername

      String generateUsername()
      Returns:
      a candidate login that is not guessable from the user's name, email or creation order: a letter followed by eleven characters drawn at random from lowercase letters and digits