【问题标题】:Access managed JSF beans in authorize tag of Spring security在 Spring 安全的授权标签中访问托管 JSF bean
【发布时间】:2018-05-24 22:56:01
【问题描述】:

我实现了 Spring security 4.2.3。在 JSF-2.2 Web 应用程序中,到目前为止它工作正常。现在我从spring security的授权标签访问jsf bean方法时遇到问题。

这是我的 xhtml 数据表,我需要根据项目数据拒绝某些行的访问:

<p:dataTable var="item" value="#{itemService.items}">
    <p:column headerText="Id">
        <h:outputText value="#{item.id}" />
    </p:column>

    <p:column headerText="Name">
        <h:outputText value="#{item.name}" />
    </p:column>

    <p:column headerText="Security">
        <sec:authorize access="#{securityService.checkAccessByItemId(item.id)}">
            <h:outputLabel value="#{helloWorld.secure}"/>
        </sec:authorize>
    </p:column>
</p:dataTable>

这里我的 bean 只是为了测试:

@ManagedBean(name="securityService")
@RequestScoped
public class SecurityService {

    public boolean checkAccessByItemId(int id) {
        if(id==5) {
            return false;
        } else {
            return true;
        }
    }
}

这里是我的 taglib.xml:

<facelet-taglib>
   <namespace>http://www.springframework.org/security/tags</namespace>
    <tag>
        <tag-name>authorize</tag-name>
        <handler class>org.springframework.faces.security.FaceletsAuthorizeTagHandler</handler-class>
    </tag>
</facelet-taglib>

我遇到了这个异常:

org.springframework.expression.spel.SpelParseException: Expression [#{securityService.checkAccessByItemId(item.id)}] @1: EL1043E: Unexpected token. Expected 'identifier' but was 'lcurly({)'
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.raiseInternalException(InternalSpelExpressionParser.java:1006)

有人知道解决办法吗?

【问题讨论】:

标签: spring security jsf el authorize


【解决方案1】:

如果我正确阅读了Spring-Security documentation for the authorize tag,它似乎不支持其中的 EL(如果您想调用自己的 bean 来“验证”事物,为什么还要使用授权标签?只需使用 rendered然后在 outputLabel 上添加属性。

【讨论】:

  • 是的,在这个简单的例子中,渲染属性将是一个解决方案。我只想知道是否有一种方法可以通过使用管理 bean 来动态控制访问或必要的权限。但是好像不支持这个。
猜你喜欢
  • 2016-10-24
  • 1970-01-01
  • 2012-03-24
  • 1970-01-01
  • 2014-12-11
  • 2012-08-27
  • 1970-01-01
  • 2014-07-06
  • 2011-06-22
相关资源
最近更新 更多