- 履歴一覧
- 現在との差分 を表示
- ソース を表示
- 履歴 を表示
- Spring Boot/特定のログインエラーで画面遷移する へ行く。
- 1 (2017-05-22 (月) 17:37:57)
- 2 (2017-05-23 (火) 09:18:19)
- 3 (2017-05-23 (火) 17:28:35)
- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2017-05-22T08:37:57+00:00","default:haruki","haruki") #author("2017-05-23T00:18:19+00:00","default:haruki","haruki") * キーワード [#i006efe6] - Spring Boot - Spring Security * したいこと [#r7a75f42] 特定のログインエラー時に画面遷移したい(ログイン画面には戻らずに)。 * どうやって [#b134fd8d] ** 認証失敗したときのハンドラを用意する [#h3a76cd1] public class SecurityConfigAuthenticationFailureHandler extends ExceptionMappingAuthenticationFailureHandler{ public SecurityConfigAuthenticationFailureHandler() { this.setDefaultFailureUrl("/"); this.setExceptionMappings(getFailureUrlMap()); } private Map<String, String> getFailureUrlMap() { Map<String, String> map = new HashMap<>(); map.put(CredentialsExpiredException.class.getName(), "/resetPassword"); map.put(CredentialsExpiredException.class.getName(), "/reset_password"); return map; } } - Mapは<String,String> -- 例外のクラス名 -- リダイレクト先(コンテキストパスは補ってくれる) ** ハンドラをセットする [#y7624398] http.formLogin() .loginPage("/") .failureHandler(new SecurityConfigAuthenticationFailureHandler()) // あといろいろ ** リダイレクト先を認証不要にする [#u7c0dbd2] http.authorizeRequests() // 認証不要 .antMatchers( // ログイン "/", // パスワードリセット "/resetPassword" "/reset_password" ) .permitAll() // あといろいろ * ノート [#jbe39217] こうだよとバシッと書いてくれてる記事が見つからなくて少してこずった。 * 参考 [#yd4963bd] - [[6.3. 認証 — TERASOLUNA Global Framework Development Guideline 1.0.0.publicreview documentation>https://terasolunaorg.github.io/guideline/public_review/Security/Authentication.html]]