You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ståle Undheim <me...@gmail.com> on 2007/03/28 15:52:10 UTC
Handling login for struts 2.0
I am currently using Struts 2.0 using guice for dependency injection.
I have a goal to have a minimum amount of xml in my project.
I want to handle all login in 1 place. So if a user isn't
authenticated, he will be sent to the login page.
I first tried this with a base action class that I extended, in the
base class I defined @Result for Action.LOGIN, while the subclasses
would define @Result for Action.SUCCESS. This didn't seem to work as
only the @Result annotation on the subclass was found by struts.
Then I tried to create an interceptor, but it seems that the only
thing I can do here is to change the result String, not actually
affect which page the user gets sent to.
Currently it seems to me that I have to define both Action.LOGIN and
Action.SUCCESS @Result annotations for all Actions I define. This is
clearly not according to the DRY principles, and not what I want.
I also now have to set @Package on all my actions, so they are in the
package I have defined my interceptor.
What I really want, is to not have anything in my Actions that
indicate that they require authentication (all of the do), or just a
marker interface/annotation to enable authentication.
How can I achieve this? Is Action chaining something I should look at?
I don't really know anything about it except that it exists. And is it
something that can be configured from my guice module loading, or does
it require definitions in struts.xml?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Handling login for struts 2.0
Posted by cilquirm <aa...@gmail.com>.
I think the answer is a 2 part solution, but you're on the right track.
1) Create the interceptor that returns Action.LOGIN ( or whatever it is when
the user isn't authenticated ).
2) set up your login page in your global results type. See this page for
more information :
http://struts.apache.org/2.x/docs/result-configuration.html
That should really be all that needs be done.
Ståle Undheim wrote:
>
> I am currently using Struts 2.0 using guice for dependency injection.
> I have a goal to have a minimum amount of xml in my project.
>
> I want to handle all login in 1 place. So if a user isn't
> authenticated, he will be sent to the login page.
>
> I first tried this with a base action class that I extended, in the
> base class I defined @Result for Action.LOGIN, while the subclasses
> would define @Result for Action.SUCCESS. This didn't seem to work as
> only the @Result annotation on the subclass was found by struts.
>
> Then I tried to create an interceptor, but it seems that the only
> thing I can do here is to change the result String, not actually
> affect which page the user gets sent to.
>
> Currently it seems to me that I have to define both Action.LOGIN and
> Action.SUCCESS @Result annotations for all Actions I define. This is
> clearly not according to the DRY principles, and not what I want.
>
> I also now have to set @Package on all my actions, so they are in the
> package I have defined my interceptor.
>
> What I really want, is to not have anything in my Actions that
> indicate that they require authentication (all of the do), or just a
> marker interface/annotation to enable authentication.
>
> How can I achieve this? Is Action chaining something I should look at?
> I don't really know anything about it except that it exists. And is it
> something that can be configured from my guice module loading, or does
> it require definitions in struts.xml?
>
> ---------------------------------------------------------------------
> 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/Handling-login-for-struts-2.0-tf3480451.html#a9718422
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