2016-05-20 6 views
-1

私はアプリケーションにSpring Security Kerberosを追加しました。ユーザーがドメインにログインしていないかブラウザがSSOをサポートしていない場合にフォームのログインを実装しました。この問題の唯一の問題は、ログインに成功した後、ユーザーは元のページにリダイレクトされず、代わりにデフォルトの「/」にリダイレクトされることです。私の設定を見つけることができます、私は何を逃してください?春のセキュリティはいつでもログイン後に "/"にリダイレクト

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .headers().frameOptions().disable() 
       .and() 
       .exceptionHandling().accessDeniedPage("/login") 
       .authenticationEntryPoint(spnegoEntryPoint()) 
       .and() 
       .authorizeRequests() 
       .regexMatchers("^\\S*.js|\\S*.css$").permitAll() 
       .anyRequest().hasAnyAuthority("APP USER") 
       .and() 
       .logout() 
       .permitAll() 
       .and() 
       .formLogin().loginPage("login").loginProcessingUrl("/spnego_login").permitAll() 
       .and() 
       .rememberMe().rememberMeServices(rememberMeServices()).key(KEY) 
       .and() 
       .addFilterBefore(
         spnegoAuthenticationProcessingFilter(authenticationManagerBean()), 
         BasicAuthenticationFilter.class) 
       .csrf().disable(); 
    } 

ログインページ

<form class="form-signin" action="/spnego_login" method="post" accept-charset=utf-8> 
      <h2 class="form-signin-heading">Please Log In Manually</h2> 
      <label for="inputEmail" class="sr-only">Username</label> 
      <input type="text" id="inputEmail" class="form-control" placeholder="username" name="username" required autofocus> 
      <label for="inputPassword" class="sr-only">Password</label> 
      <input type="password" id="inputPassword" class="form-control" placeholder="Password" name="password" required> 
      <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button> 
     </form> 

UPDATE 推奨されているように私はSavedRequestAwareAuthenticationSuccessHandlerを使用してみましたが、それは以前のURLがキャッシュ内に見つからないことが判明。したがって、成功ハンドラは常にデフォルトになります。

+1

[ログインが成功した後に前のページにリダイレクトされる]の可能性のある重複の可能な複製(http://stackoverflow.com/questions/14573654/spring-security-redirect-to-previous-page-after-succesful-login) – OrangeDog

答えて

0

同じURLとしてログインページのURLとログインプロセスのURLを設定した後のリダイレクトが正しく

作業開始
-1

この構成は

@Configuration 
@EnableWebSecurity 
@EnableWebMvcSecurity 
public class SecurityConfigurations extends WebSecurityConfigurerAdapter { 

    @Autowired 
    DataSource dataSource; 

    @Autowired 
    public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception { 

      auth.jdbcAuthentication().dataSource(dataSource) 
      .usersByUsernameQuery(
       "select login,password,enabled from users where login=?") 
      .authoritiesByUsernameQuery(
       "select u.login,r.role from roles as r , users as u where u.id=r.user_id and u.login=?"); 
     } 

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

     http.authorizeRequests() 
     .antMatchers("/index").access("hasRole('ROLE_USER')") 
     .and() 
      .formLogin().loginProcessingUrl("/j_spring_security_check").loginPage("/login").failureUrl("/login?error") 
      .usernameParameter("login").passwordParameter("password") 
     .and() 
      .logout().logoutSuccessUrl("/login").and() 
      .csrf(); 
    } 

} 

私にとってとてもうまく動作JSPフォーム:

<form method="POST" action="j_spring_security_check" > 

       <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" /> 

       <div class="form-group"> 
        <input type="text" class="form-control material" name="login" autofocus="autofocus"> 
       </div> 
       <div class="form-group"> 
        <input type="password" class="form-control material" name="password" > 
       </div> 

       <button type="submit" class="btn btn-block btn-info text-uppercase waves waves-effect waves-float">Login</button> 

       </form> 
関連する問題