diff --git a/src/main/java/com/mpnp/baechelin/login/oauth/entity/UserPrincipal.java b/src/main/java/com/mpnp/baechelin/login/oauth/entity/UserPrincipal.java index 6ee2e0a..a8f87c5 100644 --- a/src/main/java/com/mpnp/baechelin/login/oauth/entity/UserPrincipal.java +++ b/src/main/java/com/mpnp/baechelin/login/oauth/entity/UserPrincipal.java @@ -87,12 +87,19 @@ public OidcIdToken getIdToken() { // spring security -> userService(CustomOAuth2UserService)에서 사용자의 속성을 가져오기 위한 전처리. // spring security -> userDetailService 설정을 위해 사용 public static UserPrincipal create(User user) { + SimpleGrantedAuthority simpleGrantedAuthority; + if (user.getRoleType().getCode().equals("ROLE_ADMIN")) { + simpleGrantedAuthority = new SimpleGrantedAuthority(RoleType.ADMIN.getCode()); + } else { + simpleGrantedAuthority = new SimpleGrantedAuthority(RoleType.USER.getCode()); + } + return UserPrincipal.builder() .userId(user.getSocialId()) .password(user.getPassword()) .providerType(user.getProviderType()) .roleType(user.getRoleType()) - .authorities(Collections.singletonList(new SimpleGrantedAuthority(RoleType.USER.getCode()))) + .authorities(Collections.singletonList(simpleGrantedAuthority)) .build(); } diff --git a/src/main/java/com/mpnp/baechelin/login/oauth/service/CustomOAuth2UserService.java b/src/main/java/com/mpnp/baechelin/login/oauth/service/CustomOAuth2UserService.java index f9179ca..fecee38 100644 --- a/src/main/java/com/mpnp/baechelin/login/oauth/service/CustomOAuth2UserService.java +++ b/src/main/java/com/mpnp/baechelin/login/oauth/service/CustomOAuth2UserService.java @@ -86,7 +86,7 @@ private User createUser(OAuth2UserInfo userInfo, ProviderType providerType) { return userRepository.saveAndFlush(user); } - private User updateUser(User user, OAuth2UserInfo userInfo) { + private void updateUser(User user, OAuth2UserInfo userInfo) { // DB에 있는 user name과 소셜에서 보내준 user name이 다를 시 DB 업데이트 // 즉, 소셜에서 이름을 바꿨으면 업데이트 if (userInfo.getName() != null && !user.getName().equals(userInfo.getName())) { @@ -98,7 +98,6 @@ private User updateUser(User user, OAuth2UserInfo userInfo) { user.setProfileImageUrl(userInfo.getImageUrl()); } - return user; } }