自定义身份验证 - Spring boot 403禁止错误

时间:2017-02-20 04:11:18

标签: mongodb authentication spring-boot jwt http-status-code-403

我正在尝试实现自定义身份验证,身份验证工作正常,但在授权方面存在问题。我正在使用JWT令牌,我试图访问它的任何API给我一个403禁止错误。我不确定是什么问题。我在github上有完整的源代码。 https://github.com/vivdso/SpringAuthentication,Spring引导魔法不起作用。任何指针都是附带的。 使用MongoDb作为我的存储库来存储用户帐户和角色 InMemory身份验证工作正常,但自定义身份验证始终重新启动403,下面是我的扩展WebSecurityConfigurerAdapter

@Autowired
    public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
//        authenticationManagerBuilder.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN");
//        authenticationManagerBuilder.inMemoryAuthentication().withUser("user").password("user").roles("USER");

authenticationManagerBuilder.authenticationProvider(getCustomAuthenticationProvider());         }

@Override
protected void configure(HttpSecurity http) throws Exception {
 http
                .authorizeRequests()
                .antMatchers(HttpMethod.GET, "/customer").hasAuthority("ADMIN")
                .antMatchers(HttpMethod.GET, "/order").hasAuthority("USER").and()
                .csrf().disable();
    }

@Bean
    protected CustomAuthenticationProvider getCustomAuthenticationProvider(){
        return new CustomAuthenticationProvider();
    }

我没有任何自定义的授权实施。

1 个答案:

答案 0 :(得分:0)

问题已解决,我已更新Github存储库。 Spring引导安全性工作正常,问题是分配给用户集合的角色是一个Json字符串对象(例如{" role":" ROLE_ADMIN"})而不是sting对象& #34; ROLE_ADMIN"

由于

相关问题