Combining Spring Security Tags and Struts2 Tags

╄→尐↘猪︶ㄣ 提交于 2019-12-13 02:37:02

问题


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}">


回答1:


How about just using information from session:

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


来源:https://stackoverflow.com/questions/16444220/combining-spring-security-tags-and-struts2-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!