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.
Please help,
Thanks,
________________________________
From: Lukasz Lenart <[email protected]>
To: Struts Users Mailing List <[email protected]>
Sent: Wednesday, March 20, 2013 6:05 AM
Subject: Re: How to pass the current logged in username to struts2 action from
spring security 3
Thus defined in your mail ...
2013/3/20 Omar Ngarigari <[email protected]>:
> Which annotation type should I use in my actiom class to inject user object?
>
> Sent from my iPhone
>
> On Mar 20, 2013, at 2:14 AM, Lukasz Lenart <[email protected]> wrote:
>
>> 2013/3/20 Omar Ngarigari <[email protected]>:
>>> <s:textfield name="addCustomer.postUserId"
>>> value="%{springSecurity.currentUser}"/>
>>
>> You cannot call interceptor directly, it must be an action.
>>
>>> while (((actionClass = actionClass.getSuperclass()) != null) &&
>>> (!isDone))
>>> {
>>> for (Method method : actionClass.getDeclaredMethods())
>>> {
>>> if
>>> ((method.getAnnotation(SpringSecurityPrincipal.class) != null) &&
>>> ((currentUser.getPrincipal() instanceof User))) {
>>> method.invoke(action, new Object[] {
>>> currentUser.getPrincipal() });
>>
>> This part is looking for a method annotated with the below
>> @SpringSecurityPrincipal and if it will find it, inject User object.
>>
>>> public @interface SpringSecurityPrincipal
>>
>> You must annotate action's method to allow inject User object
>>
>>
>> Regards
>> --
>> Łukasz
>> + 48 606 323 122 http://www.lenart.org.pl/
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]