【问题标题】:PicketLink EL methods not found未找到 PicketLink EL 方法
【发布时间】:2016-03-18 10:00:47
【问题描述】:

我们在一个带有 Wildfly 的 EE7 CDI/JSF 应用程序中使用 PicketLink 2.7。

根据 PicketLink 文档,有一些 EL 方法 比如#{hasRole('ROLE_NAME')}。当我们尝试在 JSF 页面中使用这些时

<ui:fragment rendered="#{hasRole('ROLE_NAME')}">

我们得到

原因:javax.el.E​​LException: Function 'hasRole' not found

当我们在 CDI bean 上使用 EL 表达式时

@Restrict("#{hasRole('ROLE_NAME')}")
public void doWhatEver(){}

它工作正常(当它没有角色时抛出异常)。

所以在 beans.xml 中配置了 PicketLink 拦截器,我们在 pom 文件中使用 PicketLink 的 uber 依赖项。 我们缺少什么?

方法由 org.picketlink.internal.el.E​​LFunctionMethods 提供 据我所知:

    public static boolean hasRole(String roleName)
Checks if an authenticated user is granted with a role with the given name.

This method requires that valid ELEvaluationContext associated with the current invation thread.

【问题讨论】:

    标签: jsf cdi picketlink


    【解决方案1】:

    PicketLink 定义的 EL 表达式在 JSF 上下文中不可用。我遇到了同样的问题,并决定使用 @ApplicationScoped bean 和所需的方法:

    @Named("auth")
    @ApplicationScoped
    public class AuthorizationManager {
        @Inject Identity identity;
        @Inject PartitionManager partitionManager;
    
        public void hasRole(String roleName) {
            return AuthorizationUtil.hasRole(identity, this.partitionManager, roleName);
        }
    }
    

    然后你可以在 JSF 中使用它:

    <ui:fragment rendered="#{auth.hasRole('ROLE_NAME')}">
    

    【讨论】:

      猜你喜欢
      • 2015-02-15
      • 2012-01-07
      • 2012-04-30
      • 2015-09-19
      • 2016-01-16
      • 2021-05-01
      • 2019-03-07
      • 2021-02-02
      • 1970-01-01
      相关资源
      最近更新 更多