Reputation: 8772
I have implemented Active Directory authentication for my Struts 2 web application in Tomcat. I want to be able to use the username of the logged in user within the application. How can I read it within an action?
Upvotes: 0
Views: 425
Reputation: 24396
In Struts2 there is org.apache.struts2.interceptor.PrincipalAware
interface which sets org.apache.struts2.interceptor.PrincipalProxy
into your action. Implement it in your action and use this object to get user principal.
Using PrincipalAware
interface is preferable way to get user principal. From javadoc:
This interface is only relevant if the Action is used in a servlet environment. By using this interface you will not become tied to servlet environment.
Upvotes: 1
Reputation: 1757
Does it not integrate with the Servlet Context? You should be able to get it with:
ServletActionContext.getRequest().getUserPrincipal().getName();
Upvotes: 0