Felipe Leão
Felipe Leão

Reputation: 925

Combining Spring Security Tags and Struts2 Tags

I'm currently using Spring Security to manage login and sessions on my Struts2 application. To retrieve the logged user in a JSP page I'm using the sec tag lib by importing the following to my jsp.

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

So to print my logged user i use <sec:authentication property="principal.username" />.

I'm iterating through a java.util.List received through the action called, so a iterate it through something like this:

<s:iterator value="#request.myList" var="userEmail">
    My value: <s:property value="#userEmail"/>
</s:iterator>

I'm looking for a way to test the list item to check if is the same as the logged user, but I can't manage to retrieve sec inside a <s:if> tag.

Does anyone know how to combine both? and do something like

<s:if test="%{<sec:authentication property="principal.username" /> == #userEmail}">

Upvotes: 1

Views: 667

Answers (1)

Aleksandr M
Aleksandr M

Reputation: 24396

How about just using information from session:

<s:if test="#session.SPRING_SECURITY_CONTEXT.authentication.principal.username == #userEmail">

Upvotes: 1

Related Questions