public class TenantHandler
extends org.eclipse.jetty.server.handler.AbstractHandler
| Modifier and Type | Class and Description |
|---|---|
private class |
TenantHandler.UpdateTenantBody
Class responsible with storing the information required by a tenant update operation.
|
org.eclipse.jetty.server.handler.AbstractHandler.ErrorDispatchHandlerorg.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListenerorg.eclipse.jetty.util.component.LifeCycle.Listener| Modifier and Type | Field and Description |
|---|---|
private static java.util.Set<java.lang.String> |
acceptedKeys
A set of accepted keys for the update list.
|
private WebAuthHandler |
authHandler
The handler used for authentication and authorization.
|
private static org.eclipse.jetty.server.handler.ContextHandler |
handler
The context handler.
|
private static TenantHandler |
instance
The singleton instance for this handler.
|
private static CentralLogger |
LOG
Logger
|
private java.lang.ThreadLocal<com.fasterxml.jackson.databind.ObjectMapper> |
mapper
Used to parse the HTTP body as a JSON object.
|
private LegacyWebSecurityManager |
wsm
Instance used for executing requests in a context.
|
| Constructor and Description |
|---|
TenantHandler(int timeout)
Constructor that initializes the authentication handler and the web security manager.
|
| Modifier and Type | Method and Description |
|---|---|
private boolean |
checkTenantEnabled(java.lang.String token,
javax.servlet.http.HttpServletResponse response,
java.lang.String tenantName)
Check if a specific tenant is enabled.
|
private boolean |
checkUpdateListKeys(java.util.Map<java.lang.String,java.lang.String> updateList)
Check if the mapping contains other keys than the accepted ones.
|
private boolean |
executeAndWriteResponse(java.lang.String token,
javax.servlet.http.HttpServletResponse response,
java.lang.Runnable task,
java.lang.Boolean[] result)
Execute the given task and assign a message to the HTTP response.
|
private boolean |
executeAndWriteResponse(java.lang.String token,
javax.servlet.http.HttpServletResponse response,
java.lang.Runnable task,
java.lang.String message,
java.lang.Boolean[] result)
Execute the given task and assign a message to the HTTP response.
|
void |
handle(java.lang.String target,
org.eclipse.jetty.server.Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Method for handling the requests.
|
private void |
handleDelete(java.lang.String target,
java.lang.String body,
javax.servlet.http.HttpServletResponse response,
java.lang.String token)
Method for handling the DELETE requests.
|
private void |
handleGet(java.lang.String target,
javax.servlet.http.HttpServletResponse response,
java.lang.String token)
Method for handling the GET requests.
|
private void |
handlePost(java.lang.String target,
java.lang.String body,
javax.servlet.http.HttpServletResponse response,
java.lang.String token)
Method for handling the POST requests.
|
private void |
handlePut(java.lang.String target,
java.lang.String body,
javax.servlet.http.HttpServletResponse response,
java.lang.String token)
Method for handling the PUT requests.
|
static org.eclipse.jetty.server.handler.AbstractHandler |
initialize(int timeout)
Function used for initializing the instance of this class.
|
private TenantDatabaseDescriptor |
parseAddDatabaseToTenantBody(java.lang.String body)
Parse a JSON and extract the required values for adding a database to a tenant.
|
private java.util.List<TenantDatabaseDescriptor> |
parseAddTenantBody(java.lang.String body,
java.lang.String[] tenantName)
Parse a JSON and extract the required values for adding a tenant.
|
private java.lang.Object |
parseBody(java.lang.String body,
java.lang.String fieldName,
java.lang.Class<?> cls)
Parse a JSON and extract the value (String or boolean for the moment) of a given field.
|
private TenantHandler.UpdateTenantBody |
parseUpdateTenantBody(java.lang.String body)
Parse a JSON and extract the required values for updating a tenant or a database assigned to a tenant.
|
private java.lang.String |
printTenants(java.util.List<TenantManager.Tenant> tenants)
List all the tenants from the given list in a JSON format.
|
static boolean |
useWebServiceAuthentication()
Determine if this service is configured to use authentication.
|
destroy, doError, doStart, doStop, getServer, setServeraddBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansaddLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, start, stop, stopprivate static final CentralLogger LOG
private static TenantHandler instance
private static org.eclipse.jetty.server.handler.ContextHandler handler
private static java.util.Set<java.lang.String> acceptedKeys
private final java.lang.ThreadLocal<com.fasterxml.jackson.databind.ObjectMapper> mapper
private WebAuthHandler authHandler
private LegacyWebSecurityManager wsm
public TenantHandler(int timeout)
timeout - The timeout used when generating tokens.public static org.eclipse.jetty.server.handler.AbstractHandler initialize(int timeout)
timeout - The timeout used when generating tokens.public static boolean useWebServiceAuthentication()
true if this service uses authentication, false otherwise.public void handle(java.lang.String target,
org.eclipse.jetty.server.Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws java.io.IOException,
javax.servlet.ServletException
handle in interface org.eclipse.jetty.server.Handlerhandle in class org.eclipse.jetty.server.handler.AbstractHandlerjava.io.IOExceptionjavax.servlet.ServletExceptionprivate void handleGet(java.lang.String target,
javax.servlet.http.HttpServletResponse response,
java.lang.String token)
private void handlePost(java.lang.String target,
java.lang.String body,
javax.servlet.http.HttpServletResponse response,
java.lang.String token)
private void handlePut(java.lang.String target,
java.lang.String body,
javax.servlet.http.HttpServletResponse response,
java.lang.String token)
private void handleDelete(java.lang.String target,
java.lang.String body,
javax.servlet.http.HttpServletResponse response,
java.lang.String token)
private boolean executeAndWriteResponse(java.lang.String token,
javax.servlet.http.HttpServletResponse response,
java.lang.Runnable task,
java.lang.Boolean[] result)
token - The token used in the request.response - The HTTP response.task - The task to be executed.result - The field that will contain the result after the execution is performed.true if the operations finish successfully, false otherwise.private boolean executeAndWriteResponse(java.lang.String token,
javax.servlet.http.HttpServletResponse response,
java.lang.Runnable task,
java.lang.String message,
java.lang.Boolean[] result)
token - The token used in the request.response - The HTTP response.task - The task to be executed.message - The key value that will be written in the JSON response.result - The field that will contain the result after the execution is performed.true if the operations finish successfully, false otherwise.private java.util.List<TenantDatabaseDescriptor> parseAddTenantBody(java.lang.String body, java.lang.String[] tenantName)
body - The JSON data.tenantName - An array that will hold the tenant name, after it is discovered in the body.private TenantDatabaseDescriptor parseAddDatabaseToTenantBody(java.lang.String body)
body - The JSON data.TenantDatabaseDescriptor instance that contains the database information.private TenantHandler.UpdateTenantBody parseUpdateTenantBody(java.lang.String body)
body - The JSON data.UpdateTenantBody instance that holds the information required by the update.private boolean checkUpdateListKeys(java.util.Map<java.lang.String,java.lang.String> updateList)
updateList - The mapping of updates.true if the mapping is correct, meaning that no unknown keys are found,
false if there is at least an unknown key.private java.lang.Object parseBody(java.lang.String body,
java.lang.String fieldName,
java.lang.Class<?> cls)
body - The JSON data.fieldName - The field for which the value is extracted.cls - The expected type of value that is retrieved.private java.lang.String printTenants(java.util.List<TenantManager.Tenant> tenants)
tenants - The list with the tenants.private boolean checkTenantEnabled(java.lang.String token,
javax.servlet.http.HttpServletResponse response,
java.lang.String tenantName)
token - The token used in this request.response - The response for the request.tenantName - The tenant to be checked.true if the tenant is enabled, false otherwise.
null if the caller does not have sufficient rights or performs a bad request.