我有一个简单的球衣 2.4 资源:
@RolesAllowed("admin")
public List<Folder> list(){}
我还有一个 ContainerRequestFilter,它设置自定义安全上下文:
public void filter(ContainerRequestContext requestContext) throws IOException {
requestContext.setSecurityContext(new MySecurityContext(...));
}
在 list() 函数中,我确实获得了正确的安全上下文:MySecurityContext。并且调用“securityContext.isUserInRole(“admin”)”有效。
但是注解@RolesAllowed似乎没有做任何事情,MySecurityContext的函数isUserInRole从未被调用过。
我需要做一些特别的事情才能让@RolesAllowed 工作吗?
找到了:-)
@RolesAllowed(“admin”)而不是@RolesAllowed(“{admin}”)
还有最重要的一点:
注册(RolesAllowedDynamicFeature.class);
您可以在下面的 web.xml 中使用它
<context-param>
<param-name>resteasy.role.based.security</param-name>
<param-value>true</param-value>
</context-param>