-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feat: Spring Security를 위한 User 객체에 UserDetails 인터페이스 상속 (#31)
- Loading branch information
Showing
2 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/main/java/com/diareat/diareat/auth/service/CustomUserDetailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.diareat.diareat.auth.service; | ||
|
||
import com.diareat.diareat.user.repository.UserRepository; | ||
import com.diareat.diareat.util.api.ResponseCode; | ||
import lombok.RequiredArgsConstructor; | ||
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; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class CustomUserDetailService implements UserDetailsService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
@Override | ||
public UserDetails loadUserByUsername(String keyCode) throws UsernameNotFoundException { | ||
return userRepository.findByKeyCode(keyCode) | ||
.orElseThrow(() -> new UsernameNotFoundException(ResponseCode.USER_NOT_FOUND.getMessage())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters