Class ClientApplicationManager
java.lang.Object
io.goobi.viewer.model.security.clients.ClientApplicationManager
Class managing registration and log-in of
ClientApplications.- Author:
- Florian Alpers
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInternal use for mocking.General constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidTo be called on server startup.Get theClientApplicationrepresenting all clients created inaddGeneralClientApplicationToDB().Loads the "all clients" ClientApplication directly from the database, so it comes with all licenses.getClientByClientIdentifier(String clientIdentifier) Gets the client with the givenClientApplication.getClientIdentifier()from the database.static Optional<ClientApplication> getClientFromRequest(HttpServletRequest request) Gets the client stored in the given request callinggetClientFromSession(HttpSession)on the requests session, if any.static Optional<ClientApplication> getClientFromSession(HttpSession session) Gets the client stored in the given session byregisterClientInSession(ClientApplication, HttpSession), if any.static StringgetClientIdentifier(HttpServletRequest request) The the client identifier from a request header.booleanisAllClients(ClientApplication client) Check if the given client is the client instance representing all clients.booleanisNotAllClients(ClientApplication client) Check if the given client is the client instance representing all clients.persistNewClient(String clientIdentifier, HttpServletRequest request) Creates a newClientApplicationwith the given identifier and IP of the given request and store it in the database.booleanregisterClientInSession(ClientApplication client, HttpSession session) Store the given client in the given session to consider it for access condition checks.voidsetAllClients(ClientApplication allClients)
-
Field Details
-
GENERAL_CLIENT_IDENTIFIER
Client identifier for the core clientApplication representing all clients.- See Also:
-
CLIENT_SESSION_ATTRIBUTE
- See Also:
-
CLIENT_IDENTIFIER_HEADER
- See Also:
-
CLIENT_RESPONSE_HEADER
- See Also:
-
-
Constructor Details
-
ClientApplicationManager
General constructor.- Parameters:
dao- The database storing theClientApplications- Throws:
DAOException
-
ClientApplicationManager
public ClientApplicationManager()Internal use for mocking.
-
-
Method Details
-
addGeneralClientApplicationToDB
To be called on server startup. If the database contains noClientApplicationrepresenting all clients, add it to the database- Throws:
DAOException
-
getAllClients
Get theClientApplicationrepresenting all clients created inaddGeneralClientApplicationToDB().- Returns:
- the
ClientApplicationrepresenting all clients
-
setAllClients
-
registerClientInSession
Store the given client in the given session to consider it for access condition checks. If the session doesn't contain the client yet, itsClientApplication.getDateLastAccess()is updated and the client saved to database- Parameters:
client- the client to registersession- the session to store the client- Returns:
- true if the client is granted access rights, else false
-
getClientFromSession
Gets the client stored in the given session byregisterClientInSession(ClientApplication, HttpSession), if any.- Parameters:
session- the session possibly containing the client- Returns:
- An optional containing the client if one exists
-
getClientFromRequest
Gets the client stored in the given request callinggetClientFromSession(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 givenClientApplication.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
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 newClientApplicationwith the given identifier and IP of the given request and store it in the database.- Parameters:
clientIdentifier- the identifier transmitted by the clientrequest- the request made by the client- Returns:
- The newly persisted client
- Throws:
DAOException
-
isNotAllClients
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
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
Loads the "all clients" ClientApplication directly from the database, so it comes with all licenses.- Returns:
- the
ClientApplicationrepresenting all clients, loaded fresh from the database
-