LoginSignup
1
1

More than 3 years have passed since last update.

timestamp status 999 error none message no message available

Last updated at Posted at 2020-01-31

状況

Spring boot でアプリを作っている。
Spring-security で認証機能の実装をする。

問題

submitを押して認証処理を行うと、ログインフォームから表題のエラーが発生したページへ遷移する。
(表題エラーはJSONで表示されていた。)

原因

認証処理で遷移するURLの許可がない場合に発生する。
認証に失敗した際に/login-errorに遷移するが、/login-errorへのアクセス許可がないため発生していた。

解決

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

        http
            .authorizeRequests()  // 認可の設定
                .antMatchers("/", "/find", "/login", "/signup", "/error", "/login-error").permitAll() // 全ユーザーアクセス許可
                .anyRequest().authenticated()  // それ以外は全て認証無しの場合アクセス不許可
                .and()
            .formLogin()  // ログイン設定
                .loginPage("/login")   
                .loginProcessingUrl("/login")   
                .usernameParameter("username")  
                .passwordParameter("password")  
                .failureUrl("/login-error")      // 認証失敗時のURL
                .defaultSuccessUrl("/")     // 認証成功時の遷移先
                .and()
            .logout()   // ログアウト設定
                .logoutRequestMatcher(new AntPathRequestMatcher("/logout**"))       // ログアウト処理のパス
                .logoutSuccessUrl("/")                                        // ログアウト完了時のパス
                .permitAll();

    }
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1