user1277546
user1277546

Reputation: 8772

Active directory auth Tomcat - Read username in Action?

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

Answers (2)

Aleksandr M
Aleksandr M

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

Matthijs Bierman
Matthijs Bierman

Reputation: 1757

Does it not integrate with the Servlet Context? You should be able to get it with:

ServletActionContext.getRequest().getUserPrincipal().getName();

Upvotes: 0

Related Questions