2016-09-19 6 views
0

私は、Spring Securityを使用して、ロールに基づいてユーザーを認証しています。 /**のために認証は与えている:私はSpring Securityで認証を行うことができますか?

Page load failed with error: too many HTTP redirects

エラーとログインページが表示されません。

protected void configure(HttpSecurity http) throws Exception { 
      http.authorizeRequests() 
      .antMatchers("/login*").authenticated() 
      .antMatchers("/**").authenticated() 
      .and() 
      .formLogin().loginPage("/login").failureUrl("/login?error").defaultSuccessUrl("/welcome") 
      .usernameParameter("username").passwordParameter("password") 
      .and() 
      .logout().logoutSuccessUrl("/login?logout").logoutUrl("/login?logout") 
      .and() 
      .exceptionHandling().accessDeniedPage("/accessDenied") 
      .and() 
      .csrf(); 
     } 

しかし、このような私が行う場合:/** URLの認証に、このコードで間違って何

protected void configure(HttpSecurity http) throws Exception { 
     http.authorizeRequests() 
     .antMatchers("/login").authenticated() 
     .antMatchers("/").authenticated() 
     .and() 
     .formLogin().loginPage("/login").failureUrl("/login?error").defaultSuccessUrl("/welcome") 
     .usernameParameter("username").passwordParameter("password") 
     .and() 
     .logout().logoutSuccessUrl("/login?logout").logoutUrl("/login?logout") 
     .and() 
     .exceptionHandling().accessDeniedPage("/accessDenied") 
     .and() 
     .csrf(); 
    } 

答えて

1

あなたのログインページが認証されていないユーザーのためにアクセスすることはできません。

.antMatchers("/login*").authenticated() 

春のセキュリティは、あなたのlogingページにリダイレクトするログインページ、にリダイレクトするよう...

あなたが認証されていないユーザーを許可する必要がありますあなたのログインページを取得するには、Spring Security Referenceを参照してください。

While the automatically generated log in page is convenient to get up and running quickly, most applications will want to provide their own log in page. To do so we can update our configuration as seen below:

protected void configure(HttpSecurity http) throws Exception { 
    http 
     .authorizeRequests() 
      .anyRequest().authenticated() 
      .and() 
     .formLogin() 
      .loginPage("/login") 1 
      .permitAll();  2 
} 

1 The updated configuration specifies the location of the log in page.

2 We must grant all users (i.e. unauthenticated users) access to our log in page. The formLogin().permitAll() method allows granting access to all users for all URLs associated with form based log in.

あなたはワイルドカード(*)を削除すると、すべてのページがアーカンソーe login/以外の認証されていないユーザーがアクセスできます。

関連する問題