【问题标题】:SpEL - access session object in spring securitySpEL - 在 Spring Security 中访问会话对象
【发布时间】:2013-10-19 06:16:51
【问题描述】:

有没有办法在 SpEL 表达式中访问会话对象?具体来说,我在 Spring Security 中需要它,比如

<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 但它没有回答我的问题。

不接受具有安全角色的解决方案。

【问题讨论】:

  • 提供的代码不适合您?
  • 不,它返回 SpelEvaluationException

标签: java spring spring-security spring-el


【解决方案1】:

我认为您不能直接访问会话对象,但您可以访问请求对象并从中获取会话。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-03
    • 2011-01-20
    • 2013-10-27
    • 2013-01-12
    • 2017-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多