Spring Securityを使ってログインを実装しています。
ログイン画面を設定していますが、ログイン画面のみ以下のような画面になってしまいます。
SecurityConfigは以下のようになっています。
SecurityCOnfig
1 2@Configuration 3@EnableWebSecurity 4public class SecurityConfig extends WebSecurityConfigurerAdapter { 5 6 @Autowired 7 DataSource dataSource; 8 9 @Autowired 10 UserDetailsService userDetailsService; 11 12 @Bean 13 public PasswordEncoder passwordEncoder() { 14 return new BCryptPasswordEncoder(); 15 } 16 17 18 /** 19 * 静的ファイルには認証をかけない 20 * @param web 21 * @throws Exception 22 */ 23 @Override 24 public void configure(WebSecurity web) throws Exception { 25 web.ignoring().antMatchers("/favicon.ico", "/css/**", "/js/**", "/images/**", "/fonts/**", "/shutdown" /* for Demo */); 26 } 27 28 /** 29 * UserDetailsServiceインターフェースを実装した独自の認証レルムを使用する設定 30 * @param auth 31 * @throws Exception 32 */ 33 @Override 34 protected void configure(AuthenticationManagerBuilder auth) throws Exception { 35 auth.userDetailsService(userDetailsService) 36 .passwordEncoder(passwordEncoder()); 37 } 38 39 @Override 40 protected void configure(HttpSecurity http) throws Exception { 41 http.authorizeRequests() 42 .antMatchers("/user/**").permitAll() 43 .antMatchers("/new").permitAll()//test用(ユーザ登録) 44 .antMatchers("/index").permitAll()//test用(ユーザ登録後の遷移画面) 45 .antMatchers("/user/create").permitAll()//test用機能 46 .anyRequest().authenticated(); 47 http.formLogin() 48 .loginPage("/loginFrom") 49 .loginProcessingUrl("/login") 50 .failureUrl("/login?error") 51 .successForwardUrl("/success") 52 .usernameParameter("email") 53 .passwordParameter("password"); 54 http.logout() 55 .logoutUrl("/logout**") 56 .logoutSuccessUrl("/login"); 57 } 58 59 60 @Bean 61 public AccessDeniedHandler accessDeniedHandler() { 62 return new DefaultAccessDeniedHandler(); 63 } 64 65 @Bean 66 public AuthenticationEntryPoint authenticationEntryPoint() { 67 return new DefaultAuthenticationEntryPoint("/loginFrom", LOGIN_TIMEOUT_URL); 68 } 69 70 71 72} 73
LoginController
1 2@Controller 3public class LoginController extends AbstractHtmlController { 4 5 6 @Override 7 public String getFunctionName() { 8 return "A_LOGIN"; 9 } 10 11 @ModelAttribute 12 LoginForm loginForm(){return new LoginForm();} 13 /** 14 * ログイン画面表示 15 * @return getメソッドの時はログイン画面を表示する 16 */ 17 @GetMapping("/loginForm") 18 public String loginFrom(){ 19 return "login/login"; 20 } 21 22...以下省略 23
templatesの下にlogin/login.htmlを作成しているためHTMLへのパスの指定もあっていると思います。
###やってみたこと
authorizeRequestsにログインページのURLを追加してみましたが、同じ表示になります。
その他のURLのページには遷移できます。
ご意見をください。お願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。