2014-09-02 80 views
3

我在我的web應用程序項目中使用了Spring Security和Struts2。我想將登錄用戶的用戶名值存儲在<s:hidden>字段中。那可能嗎?如果不是,最好的選擇是什麼?如何在Struts2中訪問登錄用戶的用戶名?

<sec:authentication property="name" /> 
<s:hidden name="value" value="%{name}" /> 

非常感謝

回答

3

你可以得到登陸用戶名,其實UserDetails對象使用:

SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 

這將返回org.springframework.security.core.userdetails.UserDetails對象。您可以從UserDetails對象獲得usernameauthorities

+0

非常感謝 – Vladislav 2014-09-02 13:28:50

相關問題