@EnableGlobalMethodSecurity(securedEnabled = true)
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private PrincipalOauth2UserService principalOauth2UserService;
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder(){
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/","/board/list","/board//detail","/display", "/auth/**", "/css/**", "/js/**", "/img/**")
.permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/auth/user/loginForm")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/")
.and()
.logout()
.logoutSuccessUrl("/")
.and()
.oauth2Login()
.loginPage("/auth/user/loginForm")
.userInfoEndpoint()
.userService(principalOauth2UserService);
}
}
@EnableGlobalMethodSecurity
@Bean
@loginProcessingUrl
login 주소가 호출되면 시큐리티가 낚아채서 대신 로그인을 진행한다.
(Controller에 "/login"을 만들 필요가 읍다.)