java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.password.JdbcUserAccountRepository
All Implemented Interfaces:
UserAccountRepository

@Repository public class JdbcUserAccountRepository extends Object implements UserAccountRepository
UserAccountRepository reading user accounts from the users, user_authorities and user_passwords tables.
  • Field Details

    • SELECT_USER

      private static final String SELECT_USER
      Columns selected for an account.
      See Also:
    • FIND_USER

      private static final String FIND_USER
      Query returning the user and its encoded password by username.
      See Also:
    • FIND_USER_BY_ID

      private static final String FIND_USER_BY_ID
      Query returning the user and its encoded password by id.
      See Also:
    • FIND_USER_BY_EMAIL

      private static final String FIND_USER_BY_EMAIL
      Query returning the user and its encoded password by e-mail address, ignoring case.
      See Also:
    • UPSERT_USER

      private static final String UPSERT_USER
      Statement inserting a user, or replacing the columns of the user that has the same id.
      See Also:
    • UPSERT_PASSWORD

      private static final String UPSERT_PASSWORD
      Statement inserting an encoded password, or replacing the stored one.
      See Also:
    • FIND_AUTHORITIES

      private static final String FIND_AUTHORITIES
      Query returning the authorities of a user by user id.
      See Also:
    • MARK_EMAIL_VERIFIED

      private static final String MARK_EMAIL_VERIFIED
      Statement that verifies the e-mail address and enables the account, only while the address is still unverified: a verification link is effective once, so replaying it cannot re-enable an account that was disabled afterwards.
      See Also:
    • jdbcClient

      private final org.springframework.jdbc.core.simple.JdbcClient jdbcClient
      JDBC client used to run the queries.
    • userAccountRowMapper

      private final UserAccountRowMapper userAccountRowMapper
      Maps a user row, without its authorities.
  • Constructor Details

    • JdbcUserAccountRepository

      public JdbcUserAccountRepository()
  • Method Details

    • findByUsername

      public Optional<UserAccount> findByUsername(String username)
      Description copied from interface: UserAccountRepository
      Finds a user account by the name the user signs in with.
      Specified by:
      findByUsername in interface UserAccountRepository
      Parameters:
      username - name the user signs in with.
      Returns:
      the account, or an empty optional when no account has that username.
    • findById

      public Optional<UserAccount> findById(UUID id)
      Description copied from interface: UserAccountRepository
      Finds a user account by its identifier.
      Specified by:
      findById in interface UserAccountRepository
      Parameters:
      id - identifier of the account.
      Returns:
      the account, or an empty optional when there is none.
    • findByEmail

      public Optional<UserAccount> findByEmail(String email)
      Description copied from interface: UserAccountRepository
      Finds a user account by its e-mail address.
      Specified by:
      findByEmail in interface UserAccountRepository
      Parameters:
      email - e-mail address of the user.
      Returns:
      the account, or an empty optional when no account has that address.
    • existsByUsername

      public boolean existsByUsername(String username)
      Description copied from interface: UserAccountRepository
      Tells whether an account with a username exists.
      Specified by:
      existsByUsername in interface UserAccountRepository
      Parameters:
      username - name the user signs in with.
      Returns:
      true when an account has that username.
    • save

      public void save(UserAccount account)
      Stores a new account, with its authorities.

      Several statements: runs in the caller's transaction, which the use case opens (transactions are demarcated by the use cases, never by the adapters).

      Specified by:
      save in interface UserAccountRepository
      Parameters:
      account - the account to create.
    • updatePassword

      public void updatePassword(UUID userId, String encodedPassword)
      Description copied from interface: UserAccountRepository
      Replaces the encoded password of an account.
      Specified by:
      updatePassword in interface UserAccountRepository
      Parameters:
      userId - identifier of the account.
      encodedPassword - the new encoded password.
    • markEmailVerified

      public boolean markEmailVerified(UUID userId)
      Description copied from interface: UserAccountRepository
      Marks the e-mail address of an account as verified and enables the account, but only while the address is still unverified: the transition happens once, so a replayed verification never re-enables an account that was disabled after its address had been verified.
      Specified by:
      markEmailVerified in interface UserAccountRepository
      Parameters:
      userId - identifier of the account.
      Returns:
      true when the address was unverified and is now verified, false when the account does not exist or its address had already been verified (nothing changes then).
    • findOne

      private Optional<UserAccount> findOne(String sql, Object value)
      Loads one account, with its authorities.
      Parameters:
      sql - query selecting the user row by one parameter.
      value - value of the parameter.
      Returns:
      the account, or an empty optional when no row matches.