2017-01-10 2 views
0

REST APIを保護するための基本認証にSpring Securityを使用しています。基本認証後のSpringセキュリティスローイング

@Configuration 
@EnableWebSecurity 
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 

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

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 

     http 
      .csrf().disable() 
      .authorizeRequests() 
       .anyRequest().authenticated(); 
    } 
} 

私は、正しいユーザー名とパスワードを使用して自分自身を認証するには(403)エラーを禁じ取得しています:

は、以下の設定コードです。

enter image description here

それが働いて得るために変更を提案してください。

答えて

3

あなたはHttpSecurity.httpBasic()

@Configuration 
@EnableWebSecurity 
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{ 


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

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 

     http.csrf().disable() 
       .httpBasic() 
       .authorizeRequests() 
        .anyRequest().authenticated(); 
    } 

} 
を使用する必要がHTTP基本認証を有効にしていません