3
我在我的web應用程序項目中使用了Spring Security和Struts2。我想將登錄用戶的用戶名值存儲在<s:hidden>
字段中。那可能嗎?如果不是,最好的選擇是什麼?如何在Struts2中訪問登錄用戶的用戶名?
<sec:authentication property="name" />
<s:hidden name="value" value="%{name}" />
非常感謝
我在我的web應用程序項目中使用了Spring Security和Struts2。我想將登錄用戶的用戶名值存儲在<s:hidden>
字段中。那可能嗎?如果不是,最好的選擇是什麼?如何在Struts2中訪問登錄用戶的用戶名?
<sec:authentication property="name" />
<s:hidden name="value" value="%{name}" />
非常感謝
你可以得到登陸用戶名,其實UserDetails
對象使用:
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
這將返回org.springframework.security.core.userdetails.UserDetails
對象。您可以從UserDetails
對象獲得username
,authorities
。
非常感謝 – Vladislav 2014-09-02 13:28:50