2016-07-06 10 views
0

私はSpringでRESTサービスを構築しており、Spring Securityを使用しています。 loginformを使ったデフォルトの解決策は私には合格しません。ここに私のWebSecurityConfig:カスタムloginProcessingUrlでログインできません

public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 
class PostAuthSuccessHandler implements AuthenticationSuccessHandler { 
     @Override 
     public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException { 
      httpServletResponse.setStatus(200); 
     } 

    } 
    class PostAuthFailureHandler implements AuthenticationFailureHandler { 
     @Override 
     public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException { 
      httpServletResponse.setStatus(403); 
      e.printStackTrace(new PrintWriter(httpServletResponse.getOutputStream())); 
     } 

    } 

    @Autowired 
    private MySQLUserDetailsManager mySQLUserDetailsManager; 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .authorizeRequests() 
      .antMatchers("/login", "/registration", "/checkUser", "/").permitAll() 
      .anyRequest().authenticated() 
     .and().formLogin() 
      .loginProcessingUrl("/login") 
      .successHandler(new PostAuthSuccessHandler()) 
      .failureHandler(new PostAuthFailureHandler()) 
      .permitAll() 
     .and().logout() 
      .permitAll() 
     .and().exceptionHandling() 
      .authenticationEntryPoint(new Http403ForbiddenEntryPoint()); 
    } 

    @Override 
    public void configure(WebSecurity web) throws Exception { 
     web.ignoring().antMatchers("/scripts/**"); 
     web.ignoring().antMatchers("/styles/**"); 
     web.ignoring().antMatchers("/jquery-validate/**"); 
     web.ignoring().antMatchers("/bootstrap-3.3.6/**"); 
    } 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
     auth.userDetailsService(mySQLUserDetailsManager); 
    } 
} 

しかし、/ログイン要求は常に403禁止されています。私は理解しています、何かが/ errorに私をリダイレクトします。 UPD:すべてのページが応答しています403禁止されていても "/"、 "/ checkuser"です。

答えて

0

私は忘れていますが、標準的な形式では隠された入力にcsrfキーがあります。したがって:

http 
    .csrf().disable() 
関連する問題