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
  • 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 allClients
    • setAllClients

      public void setAllClients(ClientApplication allClients)
      Parameters:
      allClients - the allClients to set
    • registerClientInSession

      public boolean registerClientInSession(ClientApplication client, javax.servlet.http.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(javax.servlet.http.HttpSession session)
      Get 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(javax.servlet.http.HttpServletRequest request)
      Get 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
      Get the client with the given ClientApplication.getClientIdentifier() from the database
      Parameters:
      clientIdentifier -
      Returns:
      An optional containing the client if one matches the identifier
      Throws:
      DAOException
    • getClientIdentifier

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

      public ClientApplication persistNewClient(String clientIdentifier, javax.servlet.http.HttpServletRequest request) throws DAOException
      Create 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 -
      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 -
      Returns:
      true if the client represents all clients
    • getAllClientsFromDatabase

      public ClientApplication getAllClientsFromDatabase()
      Load the "all clients" ClientApplication directly from the database, so it comes with all licenses
      Returns:
      the client