내 인증 구현이 완료되었다고 생각했지만 UserDetails 객체를 검색하려고 시도 할 때 사용자 이름이 모두 나타납니다.스프링 보안이 UserDetails 객체를 반환하지 않고 사용자 이름 만
다음 내용과 함께 oauth를 사용하고 있습니다.
AuthenticationManager에 구성이 완료로
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
을, 내 경우 UserDetailsService으로 디버깅 할 수 있습니다 :이 잘 완료하고 내 클라이언트가 JWT를 돌아 오기
@Service
public class UserServiceImpl implements UserService, UserDetailsService {
@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
MyUser persistedUser = userRepository.findByEmail(email);
if (persistedUser == null) {
throw new UsernameNotFoundException(String.format("The email %s doesn't exist", email));
}
List<GrantedAuthority> authorities = new ArrayList<>();
MyUser inMemoryUser = new MyUser(persistedUser.getEmail(), null, persistedUser.getEnabled(), false,
false, false, authorities);
return inMemoryUser;
}
}
. 하지만 나중에 컨트롤러 메서드를 디버깅 할 때 다음과 같은 문제점을 발견했습니다. 이 경우
@GetMapping
public @ResponseBody Iterable<Curriculum> getMyCurriculums(@AuthenticationPrincipal MyUser injectedUser) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
MyUser principle = (MyUser) auth.getPrincipal();
return curriculumService.findByUser(principle);
}
는 injectedUser = null가, 인증은 OAuth2Authentication이며, 원리는 문자열입니다 - 사용자 이름. MyUser이어야합니다.
그리고 문제는 ...... ??? –