表題についてです。
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"; } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。