feat: spring security OAuth2 관련 설정 추가

This commit is contained in:
kimjunseo
2021-07-23 00:28:51 +09:00
parent eebd3a9585
commit 9832ae0b76
2 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package com.example.oauthspringsecurity.config;
import com.example.oauthspringsecurity.service.OAuthService;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity // spring security 설정을 활성화시켜주는 어노테이션
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final OAuthService oAuthService;
public SecurityConfig(OAuthService oAuthService) {
this.oAuthService = oAuthService;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.oauth2Login() // OAuth2 로그인 설정 시작점
.userInfoEndpoint() // OAuth2 로그인 성공 이후 사용자 정보를 가져올 때 설정 담당
.userService(oAuthService); // OAuth2 로그인 성공 시, 후작업을 진행할 UserService 인터페이스 구현체 등록
}
}

View File

@@ -0,0 +1,15 @@
package com.example.oauthspringsecurity.service;
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService;
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.stereotype.Service;
@Service
public class OAuthService implements OAuth2UserService<OAuth2UserRequest, OAuth2User> {
@Override
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
return null;
}
}