我们正在使用PicketLink 2.7在一个EE7 CDI/JSF应用程序与野生苍蝇。
根据PicketLink文档,有一些EL方法,如#{hasRole('ROLE_NAME')}。当我们尝试在JSF页面中使用这些
<ui:fragment rendered="#{hasRole('ROLE_NAME')}">我们会得到
由: javax.el.ELException:函数“hasRole”未找到
当我们在CDI上使用EL表达式时
@Restrict("#{hasRole('ROLE_NAME')}")
public void doWhatEver(){}它工作正常(当它没有这个角色时抛出一个异常)。
因此,PicketLink拦截器是在beans.xml中配置的,我们在pom文件中使用PicketLink的uber依赖项。我们少了什么?
据我所知,这些方法由org.picketlink.internal.el.ELFunctionMethods提供:
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.发布于 2018-02-27 14:00:22
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')}">https://stackoverflow.com/questions/36081371
复制相似问题