質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Spring Security

Spring Securityは、Springのサブプロジェクトの一つでWebアプリケーションに必要な機能を追加します。正規ユーザーであるかを確認するための「認証機能」と、ユーザーのアクセスを制御する「認可機能」を簡単に追加することが可能です。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

5005閲覧

spring security セッションタイムアウトページを挟みたい

mk222222

総合スコア59

Spring Security

Spring Securityは、Springのサブプロジェクトの一つでWebアプリケーションに必要な機能を追加します。正規ユーザーであるかを確認するための「認証機能」と、ユーザーのアクセスを制御する「認可機能」を簡単に追加することが可能です。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2018/10/25 09:40

編集2018/10/29 02:16

表題についてです。

https://www.greptips.com/posts/847/
を参考に
以下の実装をしましたがうまくいきませんでした

2018/10/29更新
デバッグすると
/loginの処理を通ってログイン画面が表示されていました。
でも、urlを見るとhttp://localhost:8080/login?timeoutでした。
なのに、ログイン画面が表示されていました。
なぜ、

開発環境
eclipse201809
spring boot 2.1.0 BUILD-SNAPSHOT
spring-boot-starter-security

public class TimeoutUrlAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint{     //コンストラクタ省略 @Override protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { String redirectUrl = super.buildRedirectUrlToLoginPage(request,response,authException); if(isRequestedSessionInvalid(request)) { redirectUrl += redirectUrl.contains("?") ? "&" : "?"; redirectUrl += "timeout"; } return redirectUrl; } private boolean isRequestedSessionInvalid(HttpServletRequest request) { return request.getRequestedSessionId() != null && request.isRequestedSessionIdValid(); } }
@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter{ @Autowired MGDS0000_serviceImpl userDetailsService; @Override protected void configure(HttpSecurity http) throws Exception { // ログイン処理 http.authorizeRequests() .antMatchers("/js/**","css/**").permitAll() .antMatchers("/login/","login/**").permitAll() .antMatchers("/logout").permitAll() .antMatchers("/**").authenticated() .and().formLogin() .loginPage("/login") .usernameParameter("username") .passwordParameter("password") .failureUrl("/login").permitAll(); // ログアウト処理 http.logout() .logoutSuccessUrl("/login") .permitAll(); // タイムアウトページ http.exceptionHandling() .authenticationEntryPoint(authentcationEntryPoint()); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService); } @Bean protected AuthenticationEntryPoint authentcationEntryPoint() { return new TimeoutUrlAuthenticationEntryPoint("/login"); } }
@Controller public class test_controller { /* *初期ログイン画面 */ @RequestMapping(path="/login",method=RequestMethod.GET) String loginForm(Model model) { return "login"; } /* *セッションタイムアウト画面 */ @RequestMapping(path="/login?timeout",method=RequestMethod.GET) String timeout() { return "common/timeout"; } /* *セッションタイムアウト画面 */ @RequestMapping(path="http://localhost:8080/login?timeout",method=RequestMethod.GET) String timeouts() { return "common/timeout"; } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

?logoutでリダイレクトしてたとこを/logoutにしたらエラーページが正しく呼ばれましたずら。

投稿2018/11/05 06:18

mk222222

総合スコア59

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問