【问题标题】:Spring Boot 2.0 OAuth2 throws 401 UnauthorizedSpring Boot 2.0 OAuth2 抛出 401 Unauthorized
【发布时间】:2018-05-16 13:20:44
【问题描述】:

我使用 Spring Boot 2.0 创建了一个 OAuth2 服务器。我正在使用 Bcrypt 加密所有密码,包括客户端和用户;但我仍然收到 401 Unauthorized 错误。源码位于https://github.com/saurin-tech/demo-jwt

为了测试这一点,我正在使用 Postman。

提前致谢!

【问题讨论】:

    标签: java spring spring-boot spring-security spring-security-oauth2


    【解决方案1】:

    如果您希望“/getAllUsers”端点是公开的,那么在您的 ResourceServerConfig.configure 方法中,您应该包括:

     http.anonymous().disable()
                    .authorizeRequests()
                    .antMatchers("/users/**").authenticated()
                    .antMatchers("/getallusers").permitAll()
    .and().exceptionHandling().accessDeniedHandler(new OAuth2AccessDeniedHandler());
    

    【讨论】:

    • 我知道这一点。但是,当我尝试通过服务器进行身份验证时,我想要做的是得到一个 200 响应。但身份验证失败。
    猜你喜欢
    • 2018-06-20
    • 2017-08-31
    • 2019-07-12
    • 1970-01-01
    • 2016-04-17
    • 2018-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多