-
[UserDetail] InternalAuthenticationServiceException 에러Health-Genie 2023. 6. 4. 16:18728x90
내가 겪은 에러
InternalAuthenticationServiceException: class com.example.healthgenie.entity.User cannot be cast to class org.springframework.security.core.userdetails.UserDetails
이 에러는 Entity안에 User라는 파일에서 UserDetails를 implement하지 않아서 생기는 문제이다.
그럼으로써, UserDetails형식으로 반환되야 하는 loadUserByUsername 메소드가 {}이 return되는 문제가 생긴다
내가 해결한 방법은
public class User extends BaseEntity implements UserDetails { @Override public Collection<? extends GrantedAuthority> getAuthorities() { return List.of(new SimpleGrantedAuthority(role.name())); } }
이렇게 UserDetails를 implement해주고, getAuthorities() 메소드를 추가함으로써 해결했다
'Health-Genie' 카테고리의 다른 글
[이메일 인증] 이메일 인증 구현 & 코드 검증! (2) 2023.11.18 [symbol 에러] error: cannot find symbol log.info (1) 2023.06.12 [mail] Authentication Fail 문제 (0) 2023.06.04 [MySQL 1822 에러] Failed to add the foreign key constraint (0) 2023.06.02 [DB설계] ERD 설계 (0) 2023.05.24