Class ClientApplicationManager
java.lang.Object
io.goobi.viewer.model.security.clients.ClientApplicationManager
Class managing registration and log-in of
ClientApplication
s- Author:
- florian
-
Field Summary
-
Constructor Summary
ConstructorDescriptionInternal use for mockingGeneral constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
To be called on server startup.Get theClientApplication
representing all clients created inaddGeneralClientApplicationToDB()
Load the "all clients" ClientApplication directly from the database, so it comes with all licensesgetClientByClientIdentifier
(String clientIdentifier) Get the client with the givenClientApplication.getClientIdentifier()
from the databasestatic Optional<ClientApplication>
getClientFromRequest
(javax.servlet.http.HttpServletRequest request) Get the client stored in the given request callinggetClientFromSession(HttpSession)
on the requests session, if anystatic Optional<ClientApplication>
getClientFromSession
(javax.servlet.http.HttpSession session) Get the client stored in the given session byregisterClientInSession(ClientApplication, HttpSession)
, if anystatic String
getClientIdentifier
(javax.servlet.http.HttpServletRequest request) The the client identifier from a request headerboolean
isAllClients
(ClientApplication client) check if the given client is the client instance representing all clientsboolean
isNotAllClients
(ClientApplication client) check if the given client is the client instance representing all clientspersistNewClient
(String clientIdentifier, javax.servlet.http.HttpServletRequest request) Create a newClientApplication
with the given identifier and IP of the given request and store it in the databaseboolean
registerClientInSession
(ClientApplication client, javax.servlet.http.HttpSession session) Store the given client in the given session to consider it for access condition checks.void
setAllClients
(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 theClientApplication
s- Throws:
DAOException
-
ClientApplicationManager
public ClientApplicationManager()Internal use for mocking
-
-
Method Details
-
addGeneralClientApplicationToDB
To be called on server startup. If the database contains noClientApplication
representing all clients, add it to the database- Throws:
DAOException
-
getAllClients
Get theClientApplication
representing all clients created inaddGeneralClientApplicationToDB()
- Returns:
- the allClients
-
setAllClients
- 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, 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
public static Optional<ClientApplication> getClientFromSession(javax.servlet.http.HttpSession session) Get 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
public static Optional<ClientApplication> getClientFromRequest(javax.servlet.http.HttpServletRequest request) Get 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 Get the client with the givenClientApplication.getClientIdentifier()
from the database- Parameters:
clientIdentifier
-- Returns:
- An optional containing the client if one matches the identifier
- Throws:
DAOException
-
getClientIdentifier
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 newClientApplication
with 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
-- 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
-- Returns:
- true if the client represents all clients
-
getAllClientsFromDatabase
Load the "all clients" ClientApplication directly from the database, so it comes with all licenses- Returns:
- the client
-