springsecurity hasAuthority没有生效

我的spingsecurity配置是这样的:

protected void configure(HttpSecurity http) throws Exception {
        http
                // 关闭CSRF
                .csrf().disable()
                // 允许跨域
                .cors().and()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests()
                // 对于登录接口,允许匿名访问
                .antMatchers("/user/login").permitAll()
                .antMatchers(
                        "/sys-user/create",
                        "/sys-user/update",
                        "/sys-user/delete*",
                        "/sys-user/set-roles").hasAuthority("ROLE_ADMIN")
                // 除上面外的所有请求全部需要认证
                .anyRequest().authenticated();

        // 把token认证过滤器添加到过滤器链中
        http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);

        // 配置异常处理器
        http.exceptionHandling()
                // 认证失败处理器
                .authenticationEntryPoint(authenticationEntryPoint)
                .accessDeniedHandler(accessDeniedHandler);
    }

其中hasAuthority("ROLE_ADMIN")这一项没有生效,前面对应的接口只要登录就能访问,没有判断"ROLE_ADMIN"权限

阅读 1.8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题