SecurityConfig 코드
http.csrf().disable().headers().frameOptions().disable()
.and()
.authorizeRequests()
.antMatchers("/","/css/**","/images/**","/js/**","/h2-console/**").permitAll()
.antMatchers("/api/v1/**").hasRole(Role.USER.name())
.anyRequest().authenticated()
.and()
.logout()
.logoutSuccessUrl("/")
.and()
.oauth2Login()
.userInfoEndpoint()
.userService(customOauth2UserService);
}
User 클래스
Annotation
Optional
null이 올 수 있는 값을 감싸는 Wrapper 클래스로 NullPointerException을 방지해준다. 그래서 null이더라도 NPE가 발생하지 않는다.
의존성
CustomOAuth2UserService
OAuthAttributes