WebSecurityConfigurerAdapter을 extends하여 spring security에 전반적인 설정을 셋팅하는 설정하는 SecurityConfiguration class를 구현.
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().mvcMatchers("/resources/**");
}
private final String[] ALLOW_AUTH_URI_PATTERN = {
"/login/**",
"/welcome"
};
@Override
protected void configure(HttpSecurity http) throws Exception {
// Spring Security Filter Chain
http.csrf().disable();
// 모든 리퀘스트에 대해 인증을 요구하는 설정
http.authorizeRequests(authorize -> {
// 로그인 관련 페이지는 권한 없는 유저도 사용할 수 있어야 함(비로그인 상태 유저도 가능해야함)
authorize.antMatchers("/login/**", "/signUp").anonymous();
// start uri 에 따라 필요한 권한 설정
authorize
.antMatchers(ALLOW_AUTH_URI_PATTERN).hasAnyRole("ADMIN", "USER", "ANONYMOUS")
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/user/**").hasRole("USER");
});