Class AuthServiceBD

java.lang.Object
com.cloud.serverpak.services.AuthServiceBD
All Implemented Interfaces:
AuthService

public class AuthServiceBD extends Object implements AuthService
A class that works with a user Database. Designed to perform CRUD operations on user records.
  • Field Details

    • LOGGER

      private static final org.apache.logging.log4j.Logger LOGGER
      The logger variable.
    • listUser

      private final List<AuthServiceBD.User> listUser
      A list that stores a list of all users from the database.
    • mainHandlerList

      private static List<MainHandler> mainHandlerList
    • connection

      private static Connection connection
      Connection to the database.
    • stmt

      private static Statement stmt
      A variable for working with the database.
    • encoder

      private final Base64.Encoder encoder
      Data encryption algorithm.
  • Constructor Details

    • AuthServiceBD

      public AuthServiceBD()
      The constructor starts a connection to the Database and loads the list of users. Uses start() and loadUsers() methods.
  • Method Details

    • registerNewUser

      public boolean registerNewUser(String nickName, String login, String pass)
      Registers a new user, and throws an exception if it is impossible.
      Specified by:
      registerNewUser in interface AuthService
      Parameters:
      nickName - Username..
      login - User login.
      pass - The user's password.
      Returns:
      true if the registration was successful.
    • loadUsers

      public void loadUsers() throws SQLException
      Loads all users from the Database to the list of users on the server.
      Throws:
      SQLException - при ошибке запроса.
    • start

      public void start()
      Connects the connection to the Database, and creates a statement object.
      Specified by:
      start in interface AuthService
    • stop

      public void stop()
      Closes the Database connection.
      Specified by:
      stop in interface AuthService
    • getNickByLoginPass

      public String getNickByLoginPass(String login, String pass)
      Returns the user's Name by his Username and Password.
      Specified by:
      getNickByLoginPass in interface AuthService
      Parameters:
      login - User login.
      pass - The user's password.
      Returns:
      Username.
    • getMainHandlerList

      public static List<MainHandler> getMainHandlerList()