【问题标题】:I am getting "Full authentication is required to access this resource" response from Spring boot security setup我从 Spring Boot 安全设置中收到“访问此资源需要完全身份验证”响应
【发布时间】:2019-04-27 06:33:41
【问题描述】:

我正在使用内存授权服务器构建简单的密码授权类型,用于演示目的,然后与我现有的 Web 应用程序集成。

不确定我是否缺少任何配置。

还尝试了 base64 url​​、表单数据和其他选项,但仍然从服务器获得相同的响应。

spring boot 基本安全性被 management.security.enabled=false 禁用

授权服务器

@Configuration
@EnableAuthorizationServer
@EnableAutoConfiguration

public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
    @Autowired
    private AuthenticationManager authenticationManager;

    @Autowired
       private TokenStore tokenStore;

    @Override
      public void configure (AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
          endpoints
                  .authenticationManager (authenticationManager)        
                  .tokenStore (tokenStore);
      }
       @Bean
       public TokenStore tokenStore () {
           return new InMemoryTokenStore ();
       }


     @Bean
     public PasswordEncoder passwordEncoder () {
         return new BCryptPasswordEncoder ();
     }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory().withClient("java-client").secret(passwordEncoder (). encode ("java-secret"))
         .authorities ("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT", "USER")
         .autoApprove (true)
                .authorizedGrantTypes("authorization_code", "refresh_token", "password").scopes("read", "write");

    }
}

// Security Config

    @Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

      @Override
        protected void configure(HttpSecurity http) throws Exception { // @formatter:off
            http.authorizeRequests()
            .antMatchers("**").permitAll();

        } // @formatter:on


        @Bean
        public BCryptPasswordEncoder passwordEncoder(){
            return new BCryptPasswordEncoder();
        }

        @Autowired
        public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
            auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
        }

        public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {

            security.allowFormAuthenticationForClients();
        }
}

【问题讨论】:

    标签: java spring spring-boot oauth-2.0


    【解决方案1】:

    该错误基本上意味着您访问受身份验证保护的资源并且您没有正确提供用户名/密码。如果您访问 webbrwoser 上的 url,您将被要求输入用户名和密码。或者,如果您使用 curl,您可以在请求中添加用户名和密码。

    用户名:password@your_url,或添加带有“基本”的授权标头。

    【讨论】:

      猜你喜欢
      • 2016-10-03
      • 2018-09-11
      • 2019-01-01
      • 2020-11-21
      • 2020-10-25
      • 1970-01-01
      • 2016-11-11
      • 2015-01-08
      • 2020-03-30
      相关资源
      最近更新 更多