oauth 로그인 후 UserDetails를 가져오려 하면 예외가 터짐
@GetMapping("/social/oauth/login")
public PrincipalDetails loginOauth(@AuthenticationPrincipal PrincipalDetails principalDetails){
if(principalDetails != null) {
return userService.loadUserByUsername(principalDetails.getUser().getUserId());
}
return null;
}
@Override
public PrincipalDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
PrincipalDetails principalDetails = new PrincipalDetails(userRepository.findByUserStrId(userId));
return principalDetails;
}
@Data
public class PrincipalDetails implements UserDetails, OAuth2User{
private User user;
private Map<String ,Object> attributes;
public PrincipalDetails(User user) {
this.user = user;
}
public PrincipalDetails(User user, Map<String, Object> attributes) {
this.user = user;
this.attributes = attributes;
}
@Override
public Map<String, Object> getAttributes() {
return attributes;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return null;
}
@Override
public String getPassword() {
return user.getPassword();
}
@Override
public String getUsername() {
return user.getUsername();
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public String getName() {
return null;
}
}
PrincipalDetails에 @NoArgsConstructor를 붙여준다.
@Data
@NoArgsConstructor
public class PrincipalDetails implements UserDetails, OAuth2User{