public class ChangeUserAction extends GenericTemplateAction
An action that changes something about a user. Can either be used on its own as a GenericTemplateAction, or as part of a ChainedAction where this action just does the user modification and some other action in the chain sends the response. If you intend to use this in chain mode, set the initialisation parameter chainMode to true, that will suppress all output from this action.
What changes are done to the user are specified in the initialisation parameters. Thus this action is not suitable for situations where the change to be made to the user is specified in the HTTP request. You can use this for static changes to a user, for example to promote a user to the administrator role. The change is always the same, adding the administrator role.
Small dynamic behaviour however can be added using the replacements system. This is only applied to the property values to be set, not the property keys or any role changes. You can use this, for example, to set a time stamp in the user properties for every request and thus have the last user access time.
The changes to be made are specified using three initialisation parameters. These are addRoles, removeRoles and setProperties. addRoles and removeRoles specify roles which are to be added or removed, respectively. Each is a semicolon or line feed separated list of roles. The setProperties is list of key value pairs, separated by semicolons or line feeds. In each pair, the key and value are separated by an equals sign.
CachedAction.OutputProvider
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<java.lang.String> |
addRoles |
protected boolean |
chainMode |
protected java.util.ArrayList<java.lang.String> |
removeRoles |
protected java.util.HashMap<java.lang.String,java.lang.String> |
setProperties |
defaultRequestParameters, forwardRequestParameters, requestContextKey, staticContext, templateKey, templateManager
cache, caching, threadPool
actionParamKey, handledActions, httpHeaders, isDefaultAction, replacements, replacementsInitialized, servletModule
engine, initScript, persistentObjects, scriptManager, startScript, stopScript
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
ChangeUserAction() |
Modifier and Type | Method and Description |
---|---|
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
protected java.util.HashMap<java.lang.String,java.lang.Object> |
getTemplateContext(Template template,
javax.servlet.http.HttpServletRequest req,
ModulesServlet.HttpMethod method,
java.lang.String action,
User user)
Gets the template context used for a request.
|
boolean |
handleAction(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
ModulesServlet.HttpMethod method,
java.lang.String action,
User user)
Handles this action.
|
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
doOutput, getCacheKey, getCacheKeyParams, getForwardedParameters, getStaticTemplateContext, getTemplate, putStaticContext, returnOutput, start, stop
buildCacheKey, readMetadata, writeMetadata
addHandledAction, doReplacements, handleRequest, isHandleAction, setActionParamKey, setHttpHeaders
getScriptEngine
isInitialized, isRunning, requireLogging, toString
protected java.util.HashMap<java.lang.String,java.lang.String> setProperties
protected java.util.ArrayList<java.lang.String> removeRoles
protected java.util.ArrayList<java.lang.String> addRoles
protected boolean chainMode
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
getDependencies
in class GenericTemplateAction
manager
- The module manager handling this module.ModuleException
protected java.util.HashMap<java.lang.String,java.lang.Object> getTemplateContext(Template template, javax.servlet.http.HttpServletRequest req, ModulesServlet.HttpMethod method, java.lang.String action, User user) throws ActionException
GenericTemplateAction
Gets the template context used for a request. Contains the static context as well forwarded request parameters. The static context contains both action specific context items and the template manager default context. In addition, the logged in user, if applicable, is added with the variable name user. Usually you don't want anything user specific cached so as a safety measure, the user variable is not added if caching is turned on. If you for some reason do, you will have to override this method.
This should be the main overriding point for extending classes. You can perform any tasks needed and then add things in the context. Often you don't need to override anything else besides this and the basic Module methods.
getTemplateContext
in class GenericTemplateAction
template
- The template to be used.req
- The HTTP request.method
- The method of the HTTP request.action
- The action parameter parsed from the HTTP request.user
- The logged in user, or null if not logged in.ActionException
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
init
in class GenericTemplateAction
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
public boolean handleAction(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, ModulesServlet.HttpMethod method, java.lang.String action, User user) throws javax.servlet.ServletException, java.io.IOException, ActionException
AbstractAction
handleAction
in class CachedAction
req
- The HTTP Request.resp
- The HTTP response.method
- The HTTP method of the request.action
- The parsed action id.user
- The logged in user, or null if not applicable.javax.servlet.ServletException
java.io.IOException
ActionException
Copyright 2004-2015 Wandora Team