2016-09-30 48 views
2

我想留在登錄,但春天權利人後,在同一個頁面u到重定向到defaultSuccessUrl 我的代碼是這樣的保持相同的網址登錄春季安全後

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .csrf().disable() 
      .authorizeRequests() 
      .antMatchers("/css/**","/fonts/**","/js/**","/app/**","/images/**","/partials/**").permitAll() 
       .anyRequest() 
        .authenticated() 
     .and() 
      .formLogin() 
       .loginPage("/login") 
        .defaultSuccessUrl("/index.html") 
        .failureUrl("/login?error=true") 
        .permitAll() 
        .and().logout().logoutSuccessUrl("/login?logout") 
        .and().exceptionHandling().accessDeniedPage("/pages/303.html"); 

    } 
+0

你解決它 –

回答

0

設置

總是使用-default目標=「真」

這將迫使彈簧安全去/index.html

+0

它被禁止與真正的 –

+0

http://stackoverflow.com/questions/14573654/spring-security-redirect-to-previous設置-page-after-succesful-login這個鏈接可以幫你根據你的問題:) –

+0

你試過'.loginPage(「/ login」) .defaultSuccessUrl(「/ login」)'? –

0

我想你應該添加一個認證成功處理

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); 
    successHandler.setUseReferer(true);//redirect to the previous page 
    http 
     .csrf().disable() 
     .authorizeRequests() 
     .antMatchers("/css/**","/fonts/**","/js/**","/app/**","/images/**","/partials/**").permitAll() 
      .anyRequest() 
       .authenticated() 
    .and() 
     .formLogin() 
      .loginPage("/login") 
       .defaultSuccessUrl("/index.html") 
       .failureUrl("/login?error=true") 
       .permitAll() 
       .successHandler(successHandler)//enable success handler 
       .and().logout().logoutSuccessUrl("/login?logout") 
       .and().exceptionHandling().accessDeniedPage("/pages/303.html"); 

} 
+0

它不起作用,它將我重定向到「/」 –

+0

您輸入的網址是什麼? – chomnoue

+0

這是網址:http:// localhost:8080/myApp /#/ request –