2013-10-11 56 views
2

有沒有辦法在SpEL表達式中訪問會話對象?具體來說,我需要它在春季安全,像SpEL - 訪問彈簧安全會話對象

<intercept-url pattern="/somePage.html" access="session.getAttribute('someTemporaryFlag') != null" /> 

此代碼返回:EL1008E:(pos 0): Field or property 'session' cannot be found on object of type 'org.springframework.security.web.access.expression.WebSecurityExpressionRoot'。有一個相關的問題:List of Spring EL Variables但它不回答我的問題。

具有安全角色的解決方案是不可接受的。

+0

提供的代碼不適合您? –

+0

不,它返回SpelEvaluationException – lolotron

回答

1

我不認爲你直接訪問會話對象,但你可以訪問請求對象並從中獲取會話。

<intercept-url pattern="/somePage.html" 
     access="request.session.getAttribute('someTemporaryFlag') != null" /> 
+0

它的工作原理!謝謝 – lolotron