|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.opensymphony.xwork2.ActionSupport com.jfw.web.struts2.JFWAction
public abstract class JFWAction
All project actions using Struts 2.x must extend this class.
Offer methods for implement the authentication and authorization of actions
with automatically redirect to the relative jsps if user credentials is not
appropriate for action execution.
Any project must have a class that implements methods
isAuthenticated(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
andisAuthorized(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, com.jfw.authentication.UserData)
.
This class must be extended by all others project actions who will
implement only method myExecute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
.
Example of project super class
public abstract class PrototypeProjectAction extends com.jfw.web.struts2.JFWAction
{
protected boolean isAuthenticated(HttpServletRequest request, HttpServletResponse response, HashMap outputData)
{
boolean result = true;
if(isSimulateAuthentication())
{
//code for simulation
result = true;
}
else
{
// real code, use class com.jfw.authentication.Authentication
// for standard authentication
Authentication authentication = new Authentication();
UserData userData = authentication.authenticate(request, response);
if(userData != null)
result = true;
else
result = false;
}
return result;
}
protected int isAuthorized(HttpServletRequest request, HttpServletResponse response, UserData userData)
{
int result = Authorization.AUTHORIZE_ALL;
if(isSimulateAuthorization())
{
//code for simulation
result = Authorization.AUTHORIZE_ALL;
}
else
{
// real code, use class com.jfw.authentication.Authorization
// for standard authorization
Authorization authorization = new Authorization();
result = authorization.authorize(request, response, userData);
}
return result;
}
}
Field Summary | |
---|---|
protected java.lang.String |
className
Used for logging. |
static java.lang.String |
LOCALE_KEY
The key to use for Locale when is set as an attribute in
response. |
static java.lang.String |
LOCALE_STRUTS2_SESSION_KEY
The key used in Struts2 for save the locale in session. |
Fields inherited from class com.opensymphony.xwork2.ActionSupport |
---|
LOG |
Fields inherited from interface com.opensymphony.xwork2.Action |
---|
ERROR, INPUT, LOGIN, NONE, SUCCESS |
Constructor Summary | |
---|---|
JFWAction()
Create a new instance. |
Method Summary | |
---|---|
protected java.lang.String |
afterMyExecute(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.util.HashMap outputData)
This method is execute after the method myExecute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap) is executed. |
protected void |
beforeMyExecute(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.util.HashMap outputData)
This method is execute before the method myExecute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap) is executed. |
java.lang.String |
execute()
This is the execute method of a struts Action. |
protected java.util.Locale |
getLocale(javax.servlet.http.HttpServletRequest request)
Get locale. |
protected java.lang.String |
getLocaleLanguage(javax.servlet.http.HttpServletRequest request)
Get locale language. |
java.lang.Object |
getModel()
Used for save the data of an html form in a bean. |
javax.servlet.http.HttpServletRequest |
getServletRequest()
Get attribute request . |
javax.servlet.http.HttpServletResponse |
getServletResponse()
Get attribute response . |
protected UserData |
getUser(javax.servlet.http.HttpServletRequest request)
Get UserData from session. |
protected void |
initLocale(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Set the locale. |
protected abstract boolean |
isAuthenticated(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.util.HashMap outputdata)
Implements the authentication process. |
protected abstract int |
isAuthorized(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
UserData userData)
Implements the authorization process. |
protected boolean |
isSimulateAuthentication()
Get attribute simulateAuthentication . |
protected boolean |
isSimulateAuthorization()
Get attribute simulateAuthorization . |
protected abstract java.lang.String |
myExecute(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.util.HashMap outputData)
This method must be implement by project actions. |
protected java.lang.String |
security(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.util.HashMap outputData)
Check if the user can execute an action. |
protected void |
setLocale(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.util.Locale locale)
Set the locale. |
protected void |
setLocale(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String language,
java.lang.String country)
Set the locale. |
void |
setServletRequest(javax.servlet.http.HttpServletRequest request)
Set attribute request . |
void |
setServletResponse(javax.servlet.http.HttpServletResponse response)
Set attribute response . |
protected void |
setUserDataInOutputData(java.util.HashMap outputdata,
UserData userData)
Set the UserData and
UserProfile in outputdata under keys
JFWCommonAction.USER_DATA_IN_REQUEST_KEY and JFWCommonAction.USER_PROFILE_IN_REQUEST_KEY . |
Methods inherited from class com.opensymphony.xwork2.ActionSupport |
---|
addActionError, addActionMessage, addFieldError, clearErrorsAndMessages, clone, doDefault, getActionErrors, getActionMessages, getErrorMessages, getErrors, getFieldErrors, getLocale, getText, getText, getText, getText, getText, getText, getText, getText, getText, getTexts, getTexts, hasActionErrors, hasActionMessages, hasErrors, hasFieldErrors, input, pause, setActionErrors, setActionMessages, setFieldErrors, validate |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String className
public static final java.lang.String LOCALE_KEY
Locale
when is set as an attribute in
response. Also, if exist a request parameter with this name is used for set
the locale. The value is get from attribute
I18nInterceptor.DEFAULT_PARAMETER ("request_locale");
public static final java.lang.String LOCALE_STRUTS2_SESSION_KEY
Constructor Detail |
---|
public JFWAction()
initialize()
Method Detail |
---|
public final java.lang.String execute() throws java.lang.Exception
JFWCommonAction.OUTPUT_DATA_KEY
.JFWCommonAction.SERVICE_NAME_KEY
the name of the requested action.JFWCommonAction.REQUEST_KEY
the request object.JFWCommonAction.RESPONSE_KEY
the response object.initLocale(HttpServletRequest,HttpServletResponse)
security(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
beforeMyExecute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
myExecute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
afterMyExecute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
JFWCommonAction.ERROR_KEY
.
execute
in interface com.opensymphony.xwork2.Action
execute
in class com.opensymphony.xwork2.ActionSupport
java.lang.Exception
protected void initLocale(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
LOCALE_KEY
exist in request then this value is
used. Call method setLocale(HttpServletRequest,HttpServletResponse,Locale)
.
LOCALE_KEY
then
the locale is already set.
LocaleCookie.COOKIE_NAME
exist in
request then the value in cookie is used.
Call method setLocale(HttpServletRequest,HttpServletResponse,Locale)
.
JFWLocale.getLocale()
is used.
Call method setLocale(HttpServletRequest,HttpServletResponse,Locale)
.
setLocale(HttpServletRequest,HttpServletResponse,Locale)
.
request
- an HttpServletRequest object.response
- an HttpServletResponse object.
java.lang.Exception
protected java.lang.String security(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.HashMap outputData) throws java.lang.Exception
isAuthenticated(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
isAuthorized(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, com.jfw.authentication.UserData)
.
request
- an HttpServletRequest object.response
- an HttpServletResponse object.outputData
- the HashMap container of data to view in jsp.
java.lang.Exception
protected UserData getUser(javax.servlet.http.HttpServletRequest request)
UserData
from session. The object is
associated with key Authentication.USER_DATA_IN_SESSION_KEY
.Authentication
)
then method Authentication.addUserDataInSession(javax.servlet.http.HttpSession, com.jfw.authentication.UserData)
add the user data object in session.
request
- an HttpServletRequest object.
UserData
object or null if
not found in session.protected java.util.Locale getLocale(javax.servlet.http.HttpServletRequest request)
LOCALE_KEY
) and if
not found in session the default locale is returned.
request
- an HttpServletRequest object.
Locale
object.protected java.lang.String getLocaleLanguage(javax.servlet.http.HttpServletRequest request)
getLocale(javax.servlet.http.HttpServletRequest)
for get the locale.
request
- an HttpServletRequest object.
protected void setLocale(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.Locale locale)
request
- an HttpServletRequest object.response
- an HttpServletResponse object.locale
- an Locale object.protected void setLocale(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String language, java.lang.String country)
setLocale(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.Locale)
.
request
- an HttpServletRequest object.response
- an HttpServletResponse object.language
- the language to use for the locale.country
- the country to use for the locale.protected void setUserDataInOutputData(java.util.HashMap outputdata, UserData userData)
UserData
and
UserProfile
in outputdata under keys
JFWCommonAction.USER_DATA_IN_REQUEST_KEY
and JFWCommonAction.USER_PROFILE_IN_REQUEST_KEY
.
outputdata
- the HashMap container of data to view in jsp.userData
- a UserData
object.protected boolean isSimulateAuthentication()
simulateAuthentication
.
simulateAuthentication
.protected boolean isSimulateAuthorization()
simulateAuthorization
.
simulateAuthorization
.public void setServletRequest(javax.servlet.http.HttpServletRequest request)
request
.
setServletRequest
in interface org.apache.struts2.interceptor.ServletRequestAware
request
- the HttpServletRequest object.public javax.servlet.http.HttpServletRequest getServletRequest()
request
.
public void setServletResponse(javax.servlet.http.HttpServletResponse response)
response
.
setServletResponse
in interface org.apache.struts2.interceptor.ServletResponseAware
response
- the HttpServletResponse object.public javax.servlet.http.HttpServletResponse getServletResponse()
response
.
protected void beforeMyExecute(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.HashMap outputData) throws java.lang.Exception
myExecute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
is executed.
For default this method is empty.
request
- an HttpServletRequest object.response
- an HttpServletResponse object.outputData
- the HashMap container of data to view in jsp.
java.lang.Exception
protected java.lang.String afterMyExecute(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.HashMap outputData) throws java.lang.Exception
myExecute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
is executed.
For default this method is empty and return null.
request
- an HttpServletRequest object.response
- an HttpServletResponse object.outputData
- the HashMap container of data to view in jsp.
java.lang.Exception
public java.lang.Object getModel()
getModel
in interface com.opensymphony.xwork2.ModelDriven
protected abstract java.lang.String myExecute(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.HashMap outputData) throws java.lang.Exception
request
- an HttpServletRequest object.response
- an HttpServletResponse object.outputData
- the HashMap container of data to view in jsp. To show the
values added in this object a code like this can be used:<bean:write name="OUTPUT_DATA_KEY" property="my_key" scope="request"/>
java.lang.Exception
protected abstract boolean isAuthenticated(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.HashMap outputdata) throws java.lang.Exception
request
- an HttpServletRequest object.response
- an HttpServletResponse object.outputdata
- the HashMap container of data to view in jsp.
java.lang.Exception
protected abstract int isAuthorized(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, UserData userData) throws java.lang.Exception
request
- an HttpServletRequest object.response
- an HttpServletResponse object.userData
- a UserData
object.
Authorization.AUTHORIZED_NO
: user can
not execute the service.
Authorization.AUTHORIZED_YES
: user can
execute the service.
Authorization.AUTHORIZE_ALL
: all users
can execute the service.
Authorization.AUTHORIZE_AUTHENTICATED
:
all authenticated users can execute the service.
Authorization.SERVICE_NOT_FOUND
: service
name not exist in database.
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |