2017-06-04 5 views
0

私の春のセキュリティ設定:春のセキュリティのカスタマイズされた形でのログイン

@EnableWebSecurity 
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter{ 

     @Autowired 
     private ClientDetailsService clientDetailsService; 

     @Autowired 
     public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception { 
      auth.inMemoryAuthentication() 
       .withUser("username").password("password") 
       .authorities("USER"); 
     } 

     @Override 
     protected void configure(HttpSecurity http) throws Exception { 
      http 
      .authorizeRequests() 
       .anyRequest().authenticated() 
       .and() 
      .formLogin() 
       .loginPage("/login") 
       .permitAll() 
       .and().csrf().disable(); 
     } 

     .... 
} 

私の春のブートコントローラ:

@Controller 
@RequestMapping("/") 
public class IndexController extends BaseController { 

    @RequestMapping(value = "/login", method = RequestMethod.GET) 
    public String login() { 
     return "login"; 
    } 
.... 
} 

こんにちは、私はカスタマイズされたログインフォームと春のセキュリティを使用するようにしようとしています。 私の問題は、次のとおりです。

  1. 私はブラウザが私のlogin.jspに直接しないlocalhost:8080/loginを入力すると、それだけで、ユーザー名とパスワードを入力するテキストボックスでデフォルトのフォームを飛び出します。

  2. ユーザ名として「username」、パスワードとして「password」を入力した後、認証に失敗しました。

トレースバック:

Request '/login' matched by universal pattern '/**' 
DEBUG - matched 
DEBUG - /login at position 1 of 11 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter' 
DEBUG - /login at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' 
DEBUG - /login at position 3 of 11 in additional filter chain; firing Filter: 'HeaderWriterFilter' 
DEBUG - /login at position 4 of 11 in additional filter chain; firing Filter: 'LogoutFilter' 
DEBUG - Trying to match using Ant [pattern='/logout', GET] 
DEBUG - Checking match of request : '/login'; against '/logout' 
DEBUG - Trying to match using Ant [pattern='/logout', POST] 
DEBUG - Request 'GET /login' doesn't match 'POST /logout 
DEBUG - Trying to match using Ant [pattern='/logout', PUT] 
DEBUG - Request 'GET /login' doesn't match 'PUT /logout 
DEBUG - Trying to match using Ant [pattern='/logout', DELETE] 
DEBUG - Request 'GET /login' doesn't match 'DELETE /logout 
DEBUG - No matches found 
DEBUG - /login at position 5 of 11 in additional filter chain; firing Filter: 'BasicAuthenticationFilter' 
DEBUG - Basic Authentication Authorization header found for user 'username' 
DEBUG - Authentication attempt using org.springframework.security.authentication.dao.DaoAuthenticationProvider 
DEBUG - User 'username' not found 
DEBUG - Returning cached instance of singleton bean 'delegatingApplicationListener' 
DEBUG - Authentication request for failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials 

答えて

-1

は、/ログイン

http 
    .authorizeRequests() 
     .antMatchers("/login").anonymous() 
     .anyRequest().authenticated() 
     .and() 
    .formLogin() 
     .loginPage("/login") 
     .permitAll() 
     .and().csrf().disable(); 

Overmoreにアクセスしていない匿名ユーザーのように見えますが、Authorizationヘッダーを使用してサーバーに対して要求を行っているように見えます基本認証のために。

DEBUG - Basic Authentication Authorization header found for user 'username'

関連する問題