2011-11-17 226 views
0

我對此感到困惑。我已經成功地設置了Spring Security(基於角色的訪問等),但是我不明白的是如何向Spring創建的會話添加內容?或者我應該使用另一個會話來存儲DTO屬性?如果我使用自己的會話,Spring Security會保護它嗎?它不是透明的,我在所有:春季安全會議

<p id="layoutdims"> 
    <strong> 
     Logged in as <security:authentication property="principal.username" /> 
    </strong> 
    <strong> 
     Logged in as <% HttpSession hs = request.getSession();   %> 
     <%=hs.getAttribute("principal.username") %> 
    </strong> 
</p> 

如果Spring Security使用主會議,爲什麼hs.getAttribute給我空?我覺得這很愚蠢,尤其是當我完成了最複雜的一點時。

回答

0

嘗試獲取會話對象遵循

ServletRequestAttributes attr = (ServletRequestAttributes) 
     RequestContextHolder.currentRequestAttributes(); 
HttpSession session= attr.getRequest().getSession(true); // true == allow create 
+0

我能夠挺過與名SECURITY_CONTEXT一些東西。我覺得這種方法就像挖掘膽量,請你省略我的具體例子,告訴我你是如何做到的?與處理者說? @RequestMapping(method = RequestMethod.GET,params =「reg」) \t public String blablaBlabla(Model model)在這裏說? – Aubergine