struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukasz Lenart <lukaszlen...@apache.org>
Subject Re: How to pass the current logged in username to struts2 action from spring security 3
Date Thu, 21 Mar 2013 06:20:13 GMT
It doesn't work that way, check once again Hernán's mail, he showed
you interceptor, annotation and how to define a stack. You just must
add annotation into your action.

2013/3/20 Omar Ngarigari <ngarigarius@yahoo.com>:
> I annotated my action class as follow:
>
> @Target({java.lang.annotation.ElementType.METHOD})
> @Retention(RetentionPolicy.RUNTIME)
> public @interface SpringSecurityPrincipal {
>     public String getUsername();
> }
>
> in my action class
>
> public class AddAction extends ActionSupport implements ModelDriven<AddCustomer>{
>
> private String username;
>
> @SpringSecurityPrincipal (getUsername = "username")
> public void setUsername(String username){
> this.username = username;
> }
>
> public String getUsername(){
> return username;
> }
>
> JSP
> <s:textfield name="addCustomer.username" value="%{username}/>
>
> I debug my SpringSecurityPrincipal class is returning null, and the username does not
display in JPS.

Absolutely wrong, interceptor will look for method annotated with
@SpringSecurityPrincipal (you did it wrong), and then call that method
with parameter User, so you must have a setter setUser(User user) in
your action. Then you can call it from jsp <s:property
value="user.username"/> (you need a getter)


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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


Mime
View raw message