You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by mathias-ewald <ni...@gmx.net> on 2009/07/20 10:09:43 UTC

Problem with LoginInterceptor

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="staffResourceId"><s:property value="staffResource.id"
/></s:param>
</s:url>
<s:a href="%{url}"><button>Place Rating!</button></s:a><br>
...
---------------------------------

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 ();
		}
	}

	/**
	 * Attempt to process the user's login attempt delegating the work to the 
	 * SecurityManager.
	 */
	public boolean processLoginAttempt (HttpServletRequest request, HttpSession
session) {
		// Get the username and password submitted by the user from the
HttpRequest.
		String username = request.getParameter (USERNAME);
		String password = request.getParameter (PASSWORD);

		// Use the security manager to validate the user's username and password.
		Object user = loginManager.login(username, password);

		if (user != null) {
			// The user has successfully logged in. Store their user object in 
			// their HttpSession. Then return true.
			session.setAttribute (USER_HANDLE, user);
			return true;
		} else {
			// The user did not successfully log in. Return false.
			return false;
		}
	}
	
}
---------------------------------

Clicking the button I showed ealier, the Rate action is invoked and
intercepted by LoginInterceptor. As you can see the Action gets a parameter
"staffResourceId". As I click it the login page shows up and the address bar
of my browser tells
"http://localhost:8080/projektseminar/rating/Rate?staffResourceId=1".
Next, I enter my login credentials, the log tells me I was logged in
successfully, the browser address bar says
"http://localhost:8080/projektseminar/rating/Rate" and the log messages from
the Rate action say that there was no staffResourceId parameter set.

Why is that?

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


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


Re: Problem with LoginInterceptor

Posted by Paweł Wielgus <po...@gmail.com>.
Hi all,
You can prepare comeback link and put it to session or whereever You like:
Map<String, String[]> parameters =
ServletActionContext.getRequest().getParameterMap();
String redirectLink = namespace+"/"+actionMapping.getName();
if (parameters.size() > 0) {
	redirectLink += "?";
	for (Entry<String, 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  <ma...@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 <ni...@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 <ni...@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-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

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


Re: Problem with LoginInterceptor

Posted by ma...@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 <ni...@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 <ni...@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

Re: Problem with LoginInterceptor

Posted by mathias-ewald <ni...@gmx.net>.
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 <ni...@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem with LoginInterceptor

Posted by ma...@yahoo.com.
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 <ni...@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

Re: Problem with LoginInterceptor

Posted by mathias-ewald <ni...@gmx.net>.
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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem with LoginInterceptor

Posted by Dave Newton <ne...@yahoo.com>.
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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem with LoginInterceptor

Posted by mathias-ewald <ni...@gmx.net>.
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
org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
	at
org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
	at
org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
	at
org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3800)
	at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4450)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: Unable to find interceptor class referenced by ref-name
servlet-config - 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.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:52)
	at
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.lookupInterceptorReference(XmlConfigurationProvider.java:1092)
	at
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptorStack(XmlConfigurationProvider.java:798)
	at
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptorStacks(XmlConfigurationProvider.java:811)
	at
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptors(XmlConfigurationProvider.java:834)
	at
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:441)
	at
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:265)
	at
org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
	at
com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:189)
	at
com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
	... 22 more
Jul 20, 2009 12:38:52 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Jul 20, 2009 12:38:52 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/projektseminar] startup failed due to previous errors
log4j:ERROR LogMananger.repositorySelector was null likely due to error in
class reloading, using NOPLoggerRepository.
Jul 20, 2009 12:38:52 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jul 20, 2009 12:38:52 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jul 20, 2009 12:38:52 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/46  config=null
Jul 20, 2009 12:38:52 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1942 ms
---------------------------------------------------------------------------------

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

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


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


Re: Problem with LoginInterceptor

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
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-ewald<ni...@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="staffResourceId"><s:property value="staffResource.id"
> /></s:param>
> </s:url>
> <s:a href="%{url}"><button>Place Rating!</button></s:a><br>
> ...
> ---------------------------------
>
> 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 ();
>                }
>        }
>
>        /**
>         * Attempt to process the user's login attempt delegating the work to the
>         * SecurityManager.
>         */
>        public boolean processLoginAttempt (HttpServletRequest request, HttpSession
> session) {
>                // Get the username and password submitted by the user from the
> HttpRequest.
>                String username = request.getParameter (USERNAME);
>                String password = request.getParameter (PASSWORD);
>
>                // Use the security manager to validate the user's username and password.
>                Object user = loginManager.login(username, password);
>
>                if (user != null) {
>                        // The user has successfully logged in. Store their user object in
>                        // their HttpSession. Then return true.
>                        session.setAttribute (USER_HANDLE, user);
>                        return true;
>                } else {
>                        // The user did not successfully log in. Return false.
>                        return false;
>                }
>        }
>
> }
> ---------------------------------
>
> Clicking the button I showed ealier, the Rate action is invoked and
> intercepted by LoginInterceptor. As you can see the Action gets a parameter
> "staffResourceId". As I click it the login page shows up and the address bar
> of my browser tells
> "http://localhost:8080/projektseminar/rating/Rate?staffResourceId=1".
> Next, I enter my login credentials, the log tells me I was logged in
> successfully, the browser address bar says
> "http://localhost:8080/projektseminar/rating/Rate" and the log messages from
> the Rate action say that there was no staffResourceId parameter set.
>
> Why is that?
>
> cu
> mathias
> --
> View this message in context: http://www.nabble.com/Problem-with-LoginInterceptor-tp24565562p24565562.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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