Re: Problem with LoginInterceptor

2009-07-20 Thread Nils-Helge Garli Hegvik
You need to include one of the framework interceptor stacks (e.g
defaultStack) in your defaultLoginStack stack. As you have
configured it, your interceptor is the only one that is being
executed, so none of the framework magic gets applied.

Nils-H

On Mon, Jul 20, 2009 at 10:09 AM, mathias-ewaldnitehoax...@gmx.net wrote:

 Hi,

 recently I was told using Interceptors was better than using a BaseAction
 object performing the login process. I agree. Still I have some trouble:

 This is what happens: I have a JSP that creates a button liked with another
 action:

 AgencyDetails.jsp
 -
 ...
 s:url id=url value=/rating/Rate
        s:param name=staffResourceIds:property value=staffResource.id
 //s:param
 /s:url
 s:a href=%{url}buttonPlace Rating!/button/s:abr
 ...
 -

 This is the struts.xml configuration for that Action:

 rating.xml
 -
 package name=rating namespace=/rating extends=default
        default-interceptor-ref name=defaultLoginStack /
        action name=Rate
 class=de.mathiasewald.projektseminar.action.rating.Rate
                result
                        /rating/Rate.jsp
                /result
        /action
 /package
 -

 This is the inteceptor stack in struts.xml

 -
 interceptors
    interceptor name=login
 class=de.mathiasewald.projektseminar.interceptor.LoginInterceptor

    /interceptor
    interceptor-stack name=defaultLoginStack
        interceptor-ref name=login /
    /interceptor-stack
 /interceptors
 -

 and finally the LoginInterceptor.java

 -
 public class LoginInterceptor extends AbstractInterceptor implements
 StrutsStatics {

        /**
         *
         */
        private static final long serialVersionUID = -6647897949084333127L;


        private LoginManager loginManager = new LoginManager();

        private static final Log log = 
 LogFactory.getLog(LoginInterceptor.class);

        private static final String USER_HANDLE = 
 QUADRAN_USER_SESSSION_HANDLE;
        private static final String LOGIN_ATTEMPT = QUADRAN_LOGIN_ATTEMPT;
        private static final String USERNAME = QUADRAN_USERNAME;
        private static final String PASSWORD = QUADRAN_PASSWORD;



        public void init () {
                log.info (Intializing LoginInterceptor);
        }

        public void destroy () {}

        public String intercept (ActionInvocation invocation) throws Exception 
 {
                // Get the action context from the invocation so we can access 
 the
                // HttpServletRequest and HttpSession objects.
                final ActionContext context = invocation.getInvocationContext 
 ();
                HttpServletRequest request = (HttpServletRequest)
 context.get(HTTP_REQUEST);
                HttpSession session =  request.getSession (true);

                // Is there a user object stored in the user's HttpSession?
                Object user = session.getAttribute (USER_HANDLE);
                if (user == null) {
                        // The user has not logged in yet.

                        // Is the user attempting to log in right now?
                        String loginAttempt = request.getParameter 
 (LOGIN_ATTEMPT);
                        if (loginAttempt != null  
 loginAttempt.trim().length()  0) { // The
 user is attempting to log in.

                                log.info(User tries to log in - processing 
 attempt...);

                                // Process the user's login attempt.
                                if (processLoginAttempt (request, session) ) {
                                        // The login succeeded send them the 
 login-success page.
                                        log.info(User  + loginAttempt +  
 logged in successfully.);
                                        return invocation.invoke ();
                                } else {
                                        // The login failed. Set an error if 
 we can on the action.
                                        log.info(Error authenticating user  
 + loginAttempt);
                                        Object action = invocation.getAction 
 ();
                                        if (action instanceof 
 com.opensymphony.xwork2.ValidationAware) {
                                                
 ((com.opensymphony.xwork2.ValidationAware) action).addActionError
 (Username or password incorrect.);
                                        }
                                }
                        }

                        // Either the login attempt failed or the user hasn't 
 tried to login yet,
                        // and we need to send the login form.
                        return login;
                } else {
                        return invocation.invoke ();
                }
        }

       

Re: Problem with LoginInterceptor

2009-07-20 Thread mathias-ewald

Thx for the reply! I checked the Login Intercepter Tutorial once again and
recognized I forgot some Interceptors as you told. This is what they suggest
to define:




You need to include one of the framework interceptor stacks (e.g
defaultStack) in your defaultLoginStack stack. As you have
configured it, your interceptor is the only one that is being
executed, so none of the framework magic gets applied.

-
interceptors
interceptor name=login
class=de.mathiasewald.projektseminar.interceptor.LoginInterceptor
   
/interceptor
interceptor-stack name=defaultLoginStack
interceptor-ref name=servlet-config /
interceptor-ref name=params /
interceptor-ref name=login /
interceptor-ref name=prepare /
interceptor-ref name=chain /
interceptor-ref name=model-driven /
interceptor-ref name=fileUpload /
interceptor-ref name=static-params /
interceptor-ref name=params /
interceptor-ref name=conversionError /
interceptor-ref name=validation /
interceptor-ref name=workflow /
/interceptor-stack

interceptor-stack name=defaultInsecureStack
interceptor-ref name=servlet-config /
interceptor-ref name=params /
interceptor-ref name=prepare /
interceptor-ref name=chain /
interceptor-ref name=model-driven /
interceptor-ref name=fileUpload /
interceptor-ref name=static-params /
interceptor-ref name=params /
interceptor-ref name=conversionError /
interceptor-ref name=validation /
interceptor-ref name=workflow /
/interceptor-stack
/interceptors
-


This brings up the following Exception as Tomcat starts:

-
Jul 20, 2009 12:38:50 PM org.apache.tomcat.util.digester.SetPropertiesRule
begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting
property 'source' to 'org.eclipse.jst.jee.server:projektseminar' did not
find a matching property.
Jul 20, 2009 12:38:50 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal
performance in production environments was not found on the
java.library.path:
/usr/lib/jvm/java-6-sun-1.6.0.14/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.14/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.14/jre/../lib/amd64:/usr/lib64/xulrunner-addons:/usr/java/packages/lib/amd64:/lib:/usr/lib
Jul 20, 2009 12:38:50 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jul 20, 2009 12:38:50 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 692 ms
Jul 20, 2009 12:38:50 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jul 20, 2009 12:38:50 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
12:38:51,865  INFO XmlConfigurationProvider:31 - Parsing configuration file
[struts-default.xml]
12:38:51,991  INFO XmlConfigurationProvider:31 - Parsing configuration file
[struts-plugin.xml]
12:38:52,075  INFO XmlConfigurationProvider:31 - Parsing configuration file
[struts.xml]
Jul 20, 2009 12:38:52 PM org.apache.catalina.core.StandardContext
filterStart
SEVERE: Exception starting filter struts2
Unable to load configuration. - interceptor-ref -
file:/home/mathias/.workspace_j2ee/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/projektseminar/WEB-INF/classes/struts.xml:23:46
at
com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at
org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
at
org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:48)
at

Re: Problem with LoginInterceptor

2009-07-20 Thread Dave Newton

mathias-ewald wrote:

the additions Interceptors cannot be found. Where are they defined??


My first guess would be that you're using Struts 2.1+ and the reference 
material you're using is for Struts 2.0. Interceptors are now named 
using camelCase: modelDriven, servletConfig, etc. (or whatever they're 
called).


Dave

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Problem with LoginInterceptor

2009-07-20 Thread mathias-ewald

Hi,

yes I am using the latest version of struts2. Most likely the tutorials I
used refer to other versions. I set the struts.xml as follows:

---
interceptors
interceptor name=login
class=de.mathiasewald.projektseminar.interceptor.LoginInterceptor /

interceptor-stack name=defaultLoginStack
interceptor-ref name=servletConfig /
interceptor-ref name=params /
interceptor-ref name=login /
interceptor-ref name=prepare /
interceptor-ref name=chain /
interceptor-ref name=modelDriven /
interceptor-ref name=fileUpload /
interceptor-ref name=staticParams /
interceptor-ref name=params /
interceptor-ref name=conversionError /
interceptor-ref name=validation /
interceptor-ref name=workflow /
/interceptor-stack

interceptor-stack name=defaultInsecureStack
interceptor-ref name=servletConfig /
interceptor-ref name=params /
interceptor-ref name=prepare /
interceptor-ref name=chain /
interceptor-ref name=modelDriven /
interceptor-ref name=fileUpload /
interceptor-ref name=staticParams /
interceptor-ref name=params /
interceptor-ref name=conversionError /
interceptor-ref name=validation /
interceptor-ref name=workflow /
/interceptor-stack
/interceptors
---

The errors about unfindable interceptors disappeard. But still, the
parameter is not preserved.

Any suggestions?

cu
mathias
-- 
View this message in context: 
http://www.nabble.com/Problem-with-LoginInterceptor-tp24565562p24570331.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Problem with LoginInterceptor

2009-07-20 Thread mailtolouis2020-struts
I don't think it will preserve your parameter by default, I might be wrong, if 
it do, then that is another magic in S2 I didn't know that.

For what I understand is there are 2 request from the user,
1) http://localhost:8080/projektseminar/rating/Rate?staffResourceId=1
2) login submit

I don't think you store a staffResourceId as a hidden param in the login page, 
if its not there you won't expect to come into your url.

Regards
Louis



From: mathias-ewald nitehoax...@gmx.net
To: user@struts.apache.org
Sent: Monday, July 20, 2009 2:53:39 PM
Subject: Re: Problem with LoginInterceptor


Hi,

yes I am using the latest version of struts2. Most likely the tutorials I
used refer to other versions. I set the struts.xml as follows:

---
interceptors
interceptor name=login
class=de.mathiasewald.projektseminar.interceptor.LoginInterceptor /

interceptor-stack name=defaultLoginStack
interceptor-ref name=servletConfig /
interceptor-ref name=params /
interceptor-ref name=login /
interceptor-ref name=prepare /
interceptor-ref name=chain /
interceptor-ref name=modelDriven /
interceptor-ref name=fileUpload /
interceptor-ref name=staticParams /
interceptor-ref name=params /
interceptor-ref name=conversionError /
interceptor-ref name=validation /
interceptor-ref name=workflow /
/interceptor-stack

interceptor-stack name=defaultInsecureStack
interceptor-ref name=servletConfig /
interceptor-ref name=params /
interceptor-ref name=prepare /
interceptor-ref name=chain /
interceptor-ref name=modelDriven /
interceptor-ref name=fileUpload /
interceptor-ref name=staticParams /
interceptor-ref name=params /
interceptor-ref name=conversionError /
interceptor-ref name=validation /
interceptor-ref name=workflow /
/interceptor-stack
/interceptors
---

The errors about unfindable interceptors disappeard. But still, the
parameter is not preserved.

Any suggestions?

cu
mathias
-- 
View this message in context: 
http://www.nabble.com/Problem-with-LoginInterceptor-tp24565562p24570331.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Re: Problem with LoginInterceptor

2009-07-20 Thread mathias-ewald

Hi,

so what do you suggest? Isn't there any way to do that?

cu
mathias


mailtolouis2020-struts wrote:
 
 I don't think it will preserve your parameter by default, I might be
 wrong, if it do, then that is another magic in S2 I didn't know that.
 
 For what I understand is there are 2 request from the user,
 1) http://localhost:8080/projektseminar/rating/Rate?staffResourceId=1
 2) login submit
 
 I don't think you store a staffResourceId as a hidden param in the login
 page, if its not there you won't expect to come into your url.
 
 Regards
 Louis
 
 
 
 From: mathias-ewald nitehoax...@gmx.net
 To: user@struts.apache.org
 Sent: Monday, July 20, 2009 2:53:39 PM
 Subject: Re: Problem with LoginInterceptor
 
 
 Hi,
 
 yes I am using the latest version of struts2. Most likely the tutorials I
 used refer to other versions. I set the struts.xml as follows:
 
 ---
 interceptors
 interceptor name=login
 class=de.mathiasewald.projektseminar.interceptor.LoginInterceptor /
 
 interceptor-stack name=defaultLoginStack
 interceptor-ref name=servletConfig /
 interceptor-ref name=params /
 interceptor-ref name=login /
 interceptor-ref name=prepare /
 interceptor-ref name=chain /
 interceptor-ref name=modelDriven /
 interceptor-ref name=fileUpload /
 interceptor-ref name=staticParams /
 interceptor-ref name=params /
 interceptor-ref name=conversionError /
 interceptor-ref name=validation /
 interceptor-ref name=workflow /
 /interceptor-stack
 
 interceptor-stack name=defaultInsecureStack
 interceptor-ref name=servletConfig /
 interceptor-ref name=params /
 interceptor-ref name=prepare /
 interceptor-ref name=chain /
 interceptor-ref name=modelDriven /
 interceptor-ref name=fileUpload /
 interceptor-ref name=staticParams /
 interceptor-ref name=params /
 interceptor-ref name=conversionError /
 interceptor-ref name=validation /
 interceptor-ref name=workflow /
 /interceptor-stack
 /interceptors
 ---
 
 The errors about unfindable interceptors disappeard. But still, the
 parameter is not preserved.
 
 Any suggestions?
 
 cu
 mathias
 -- 
 View this message in context:
 http://www.nabble.com/Problem-with-LoginInterceptor-tp24565562p24570331.html
 Sent from the Struts - User mailing list archive at Nabble.com.
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 

-- 
View this message in context: 
http://www.nabble.com/Problem-with-LoginInterceptor-tp24565562p24570714.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Problem with LoginInterceptor

2009-07-20 Thread mailtolouis2020-struts
I'm new in S2, so not much suggestion I can give u now.

May be your interceptor store the entire action in the session. Once login 
success,  you get back the action and invoke it again.

May be someone can give more better suggestion?

Regards
Louis




From: mathias-ewald nitehoax...@gmx.net
To: user@struts.apache.org
Sent: Monday, July 20, 2009 3:17:47 PM
Subject: Re: Problem with LoginInterceptor


Hi,

so what do you suggest? Isn't there any way to do that?

cu
mathias


mailtolouis2020-struts wrote:
 
 I don't think it will preserve your parameter by default, I might be
 wrong, if it do, then that is another magic in S2 I didn't know that.
 
 For what I understand is there are 2 request from the user,
 1) http://localhost:8080/projektseminar/rating/Rate?staffResourceId=1
 2) login submit
 
 I don't think you store a staffResourceId as a hidden param in the login
 page, if its not there you won't expect to come into your url.
 
 Regards
 Louis
 
 
 
 From: mathias-ewald nitehoax...@gmx.net
 To: user@struts.apache.org
 Sent: Monday, July 20, 2009 2:53:39 PM
 Subject: Re: Problem with LoginInterceptor
 
 
 Hi,
 
 yes I am using the latest version of struts2. Most likely the tutorials I
 used refer to other versions. I set the struts.xml as follows:
 
 ---
 interceptors
 interceptor name=login
 class=de.mathiasewald.projektseminar.interceptor.LoginInterceptor /

 interceptor-stack name=defaultLoginStack
 interceptor-ref name=servletConfig /
 interceptor-ref name=params /
 interceptor-ref name=login /
 interceptor-ref name=prepare /
 interceptor-ref name=chain /
 interceptor-ref name=modelDriven /
 interceptor-ref name=fileUpload /
 interceptor-ref name=staticParams /
 interceptor-ref name=params /
 interceptor-ref name=conversionError /
 interceptor-ref name=validation /
 interceptor-ref name=workflow /
 /interceptor-stack
 
 interceptor-stack name=defaultInsecureStack
 interceptor-ref name=servletConfig /
 interceptor-ref name=params /
 interceptor-ref name=prepare /
 interceptor-ref name=chain /
 interceptor-ref name=modelDriven /
 interceptor-ref name=fileUpload /
 interceptor-ref name=staticParams /
 interceptor-ref name=params /
 interceptor-ref name=conversionError /
 interceptor-ref name=validation /
 interceptor-ref name=workflow /
 /interceptor-stack
 /interceptors
 ---
 
 The errors about unfindable interceptors disappeard. But still, the
 parameter is not preserved.
 
 Any suggestions?
 
 cu
 mathias
 -- 
 View this message in context:
 http://www.nabble.com/Problem-with-LoginInterceptor-tp24565562p24570331.html
 Sent from the Struts - User mailing list archive at Nabble.com.
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 

-- 
View this message in context: 
http://www.nabble.com/Problem-with-LoginInterceptor-tp24565562p24570714.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Re: Problem with LoginInterceptor

2009-07-20 Thread Paweł Wielgus
Hi all,
You can prepare comeback link and put it to session or whereever You like:
MapString, String[] parameters =
ServletActionContext.getRequest().getParameterMap();
String redirectLink = namespace+/+actionMapping.getName();
if (parameters.size()  0) {
redirectLink += ?;
for (EntryString, String[] entry : parameters.entrySet()) {
for (String value : entry.getValue()) {
redirectLink += entry.getKey()+=+value+;
}
}
}
ServletActionContext.getRequest().getSession().setAttribute(REDIRECT_AFTER_LOGIN,
redirectLink);

That's quick and dirty solution and won't work for many parameters but
should get You started.

Best greetings,
Paweł Wielgus.


2009/7/20  mailtolouis2020-str...@yahoo.com:
 I'm new in S2, so not much suggestion I can give u now.

 May be your interceptor store the entire action in the session. Once login 
 success,  you get back the action and invoke it again.

 May be someone can give more better suggestion?

 Regards
 Louis



 
 From: mathias-ewald nitehoax...@gmx.net
 To: user@struts.apache.org
 Sent: Monday, July 20, 2009 3:17:47 PM
 Subject: Re: Problem with LoginInterceptor


 Hi,

 so what do you suggest? Isn't there any way to do that?

 cu
 mathias


 mailtolouis2020-struts wrote:

 I don't think it will preserve your parameter by default, I might be
 wrong, if it do, then that is another magic in S2 I didn't know that.

 For what I understand is there are 2 request from the user,
 1) http://localhost:8080/projektseminar/rating/Rate?staffResourceId=1
 2) login submit

 I don't think you store a staffResourceId as a hidden param in the login
 page, if its not there you won't expect to come into your url.

 Regards
 Louis


 
 From: mathias-ewald nitehoax...@gmx.net
 To: user@struts.apache.org
 Sent: Monday, July 20, 2009 2:53:39 PM
 Subject: Re: Problem with LoginInterceptor


 Hi,

 yes I am using the latest version of struts2. Most likely the tutorials I
 used refer to other versions. I set the struts.xml as follows:

 ---
         interceptors
             interceptor name=login
 class=de.mathiasewald.projektseminar.interceptor.LoginInterceptor /

             interceptor-stack name=defaultLoginStack
                 interceptor-ref name=servletConfig /
                 interceptor-ref name=params /
                 interceptor-ref name=login /
                 interceptor-ref name=prepare /
                 interceptor-ref name=chain /
                 interceptor-ref name=modelDriven /
                 interceptor-ref name=fileUpload /
                 interceptor-ref name=staticParams /
                 interceptor-ref name=params /
                 interceptor-ref name=conversionError /
                 interceptor-ref name=validation /
                 interceptor-ref name=workflow /
             /interceptor-stack

             interceptor-stack name=defaultInsecureStack
                 interceptor-ref name=servletConfig /
                 interceptor-ref name=params /
                 interceptor-ref name=prepare /
                 interceptor-ref name=chain /
                 interceptor-ref name=modelDriven /
                 interceptor-ref name=fileUpload /
                 interceptor-ref name=staticParams /
                 interceptor-ref name=params /
                 interceptor-ref name=conversionError /
                 interceptor-ref name=validation /
                 interceptor-ref name=workflow /
             /interceptor-stack
         /interceptors
 ---

 The errors about unfindable interceptors disappeard. But still, the
 parameter is not preserved.

 Any suggestions?

 cu
 mathias
 --
 View this message in context:
 http://www.nabble.com/Problem-with-LoginInterceptor-tp24565562p24570331.html
 Sent from the Struts - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org


 --
 View this message in context: 
 http://www.nabble.com/Problem-with-LoginInterceptor-tp24565562p24570714.html
 Sent from the Struts - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org