Authorization with RolesAllowedDynamicFeature and Jersey

核能气质少年 提交于 2019-12-05 06:32:46

You need to define a priority for your authentication filter, otherwise the RolesAllowedRequestFilter in RolesAllowedDynamicFeature will be executed before your AuthenticationFilter. If you look at the source code, the RolesAllowedRequestFilter has the annotation @Priority(Priorities.AUTHORIZATION), so if you assign @Priority(Priorities.AUTHENTICATION) to your authentication filter it will be executed before the RolesAllowedRequestFilter. Like this:

@Provider
@Priority(Priorities.AUTHENTICATION)
public class AuthenticationFilter implements ContainerRequestFilter {

You might also need to actually register the AuthenticationFilter using register(AuthenticationFilter.class), depending on if your server scans for annotations or not.

I guess it is because of

 @Override
  public boolean isUserInRole(String string) {
    return false;
  }

Which states, that the user has not the required role @RolesAllowed("user") to even enter the execution of the annotated method.

You should implement a more sophisticated isUserInRole Method that checks, wheter a User has a specific Role or not :)

regards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!