|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.struts.action.Action com.jfw.web.struts.JFWAction
public abstract class JFWAction
All project actions using Struts 1.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(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionMessages, java.util.HashMap)
.
Example of project super class
public abstract class PrototypeProjectAction extends com.jfw.web.struts.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. |
Fields inherited from class org.apache.struts.action.Action |
---|
servlet |
Constructor Summary | |
---|---|
JFWAction()
Create a new instance. |
Method Summary | |
---|---|
protected org.apache.struts.action.ActionForward |
afterMyExecute(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.apache.struts.action.ActionMessages messages,
java.util.HashMap outputData)
This method is execute after the method myExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionMessages, java.util.HashMap) is executed. |
protected void |
beforeMyExecute(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.apache.struts.action.ActionMessages messages,
java.util.HashMap outputData)
This method is execute before the method myExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionMessages, java.util.HashMap) is executed. |
org.apache.struts.action.ActionForward |
execute(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
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. |
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 org.apache.struts.action.ActionForward |
myExecute(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.apache.struts.action.ActionMessages messages,
java.util.HashMap outputData)
This method must be implement by project actions. |
protected void |
myInit()
The method is execute in the constructor and by method update(java.util.Observable, java.lang.Object) . |
protected org.apache.struts.action.ActionForward |
security(org.apache.struts.action.ActionMapping mapping,
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. |
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 . |
void |
update(java.util.Observable observable,
java.lang.Object obj)
Call methods initialize() and myInit() . |
Methods inherited from class org.apache.struts.action.Action |
---|
addErrors, addMessages, execute, generateToken, getErrors, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet |
Methods inherited from class java.lang.Object |
---|
clone, 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.
Constructor Detail |
---|
public JFWAction()
UpdateObservable.addObserver(java.lang.Object, java.lang.String, java.lang.String)
initialize()
myInit()
Method Detail |
---|
protected void myInit()
update(java.util.Observable, java.lang.Object)
.
public final org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) 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(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.HashMap)
beforeMyExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionMessages, java.util.HashMap)
myExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionMessages, java.util.HashMap)
afterMyExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionMessages, java.util.HashMap)
JFWCommonAction.ERROR_KEY
in a ActionMessages object. The ActionMessages is send to Action.saveErrors(javax.servlet.http.HttpServletRequest, org.apache.struts.action.ActionMessages)
so is possible to display it in jsp using the html:errors tag.JFWCommonAction.ERROR_KEY
.
execute
in class org.apache.struts.action.Action
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)
.
getLocale(HttpServletRequest)
is called. Call method setLocale(HttpServletRequest,HttpServletResponse,Locale)
.
request
- an HttpServletRequest object.response
- an HttpServletResponse object.
java.lang.Exception
protected org.apache.struts.action.ActionForward security(org.apache.struts.action.ActionMapping mapping, 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)
.
mapping
- an ActionMapping object.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 Action.getLocale(javax.servlet.http.HttpServletRequest)
method is called.
getLocale
in class org.apache.struts.action.Action
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 update(java.util.Observable observable, java.lang.Object obj)
initialize()
and myInit()
.
update
in interface java.util.Observer
protected void beforeMyExecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.apache.struts.action.ActionMessages messages, java.util.HashMap outputData) throws java.lang.Exception
myExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionMessages, java.util.HashMap)
is executed.
For default this method is empty.
mapping
- an ActionMapping object.form
- an ActionForm object.request
- an HttpServletRequest object.response
- an HttpServletResponse object.messages
- an ActionMessages object.outputData
- the HashMap container of data to view in jsp.
java.lang.Exception
protected org.apache.struts.action.ActionForward afterMyExecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.apache.struts.action.ActionMessages messages, java.util.HashMap outputData) throws java.lang.Exception
myExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionMessages, java.util.HashMap)
is executed.
For default this method is empty and return null.
mapping
- an ActionMapping object.form
- an ActionForm object.request
- an HttpServletRequest object.response
- an HttpServletResponse object.messages
- an ActionMessages object.outputData
- the HashMap container of data to view in jsp.
java.lang.Exception
protected abstract org.apache.struts.action.ActionForward myExecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.apache.struts.action.ActionMessages messages, java.util.HashMap outputData) throws java.lang.Exception
mapping
- an ActionMapping object.form
- an ActionForm object.request
- an HttpServletRequest object.response
- an HttpServletResponse object.messages
- an ActionMessages 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 |