-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomUserDetailsService.java
30 lines (25 loc) · 1.2 KB
/
CustomUserDetailsService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package team05.integrated_feed_backend.module.auth.security;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import team05.integrated_feed_backend.common.code.StatusCode;
import team05.integrated_feed_backend.module.member.entity.Member;
import team05.integrated_feed_backend.module.member.repository.MemberRepository;
@Slf4j
@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class CustomUserDetailsService implements UserDetailsService {
private final MemberRepository memberRepository;
@Override
public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
Member member = memberRepository.findByAccount(account)
.orElseThrow(() -> new UsernameNotFoundException(StatusCode.UNAUTHORIZED.name()));
log.info("유저 조회 성공: {}", member.getAccount());
return new CustomUserDetails(member);
}
}