WebSecurityConfig.java
L .defaultSuccessUrl(“/test1/index”)でログイン後のURLを指定する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter{ @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers( "/" , "/home" ).permitAll() // 上記以外は認証が必要 .anyRequest().authenticated() .and() .formLogin() .loginPage( "/login" ) .permitAll() .defaultSuccessUrl( "/test1/index" ) .and() .logout() .permitAll(); } @Bean @Override public UserDetailsService userDetailsService() { UserDetails user = User.withDefaultPasswordEncoder() .username( "user" ) .password( "pass" ) .roles( "USER" ) .build(); return new InMemoryUserDetailsManager(user); } } |
なるほど。
ログイン認証をpostgresでやりたいな。