Class ClientApplicationManager

java.lang.Object
io.goobi.viewer.model.security.clients.ClientApplicationManager

public class ClientApplicationManager extends Object
Class managing registration and log-in of ClientApplications.
Author:
Florian Alpers
  • Field Details

  • Constructor Details

    • ClientApplicationManager

      public ClientApplicationManager(IDAO dao) throws DAOException
      General constructor.
      Parameters:
      dao - The database storing the ClientApplications
      Throws:
      DAOException
    • ClientApplicationManager

      public ClientApplicationManager()
      Internal use for mocking.
  • Method Details

    • addGeneralClientApplicationToDB

      public void addGeneralClientApplicationToDB() throws DAOException
      To be called on server startup. If the database contains no ClientApplication representing all clients, add it to the database
      Throws:
      DAOException
    • getAllClients

      public ClientApplication getAllClients()
      Get the ClientApplication representing all clients created in addGeneralClientApplicationToDB().
      Returns:
      the ClientApplication representing all clients
    • setAllClients

      public void setAllClients(ClientApplication allClients)
    • registerClientInSession

      public boolean registerClientInSession(ClientApplication client, HttpSession session)
      Store the given client in the given session to consider it for access condition checks. If the session doesn't contain the client yet, its ClientApplication.getDateLastAccess() is updated and the client saved to database
      Parameters:
      client - the client to register
      session - the session to store the client
      Returns:
      true if the client is granted access rights, else false
    • getClientFromSession

      public static Optional<ClientApplication> getClientFromSession(HttpSession session)
      Gets the client stored in the given session by registerClientInSession(ClientApplication, HttpSession), if any.
      Parameters:
      session - the session possibly containing the client
      Returns:
      An optional containing the client if one exists
    • getClientFromRequest

      public static Optional<ClientApplication> getClientFromRequest(HttpServletRequest request)
      Gets the client stored in the given request calling getClientFromSession(HttpSession) on the requests session, if any.
      Parameters:
      request - the request from which to get the client. If null, an empty Optional will be returned
      Returns:
      An optional containing the client if one exists
    • getClientByClientIdentifier

      public Optional<ClientApplication> getClientByClientIdentifier(String clientIdentifier) throws DAOException
      Gets the client with the given ClientApplication.getClientIdentifier() from the database.
      Parameters:
      clientIdentifier - the client identifier string to look up
      Returns:
      An optional containing the client if one matches the identifier
      Throws:
      DAOException
    • getClientIdentifier

      public static String getClientIdentifier(HttpServletRequest request)
      The the client identifier from a request header.
      Parameters:
      request - HTTP servlet request to read the client identifier header from
      Returns:
      The identifier or null if non is in the header
    • persistNewClient

      public ClientApplication persistNewClient(String clientIdentifier, HttpServletRequest request) throws DAOException
      Creates a new ClientApplication with the given identifier and IP of the given request and store it in the database.
      Parameters:
      clientIdentifier - the identifier transmitted by the client
      request - the request made by the client
      Returns:
      The newly persisted client
      Throws:
      DAOException
    • isNotAllClients

      public boolean isNotAllClients(ClientApplication client)
      Check if the given client is the client instance representing all clients.
      Parameters:
      client - the client application to check
      Returns:
      true if the client does not represent all clients
    • isAllClients

      public boolean isAllClients(ClientApplication client)
      Check if the given client is the client instance representing all clients.
      Parameters:
      client - the client application to check
      Returns:
      true if the client represents all clients
    • getAllClientsFromDatabase

      public ClientApplication getAllClientsFromDatabase()
      Loads the "all clients" ClientApplication directly from the database, so it comes with all licenses.
      Returns:
      the ClientApplication representing all clients, loaded fresh from the database