diff --git a/src/main/java/com/xit/core/oauth2/oauth/service/CustomUserDetailsService.java b/src/main/java/com/xit/core/oauth2/oauth/service/CustomUserDetailsService.java new file mode 100644 index 0000000..122187c --- /dev/null +++ b/src/main/java/com/xit/core/oauth2/oauth/service/CustomUserDetailsService.java @@ -0,0 +1,37 @@ +package com.xit.core.oauth2.oauth.service; + +import com.xit.biz.ctgy.auth.UserMinPrincipal; +import com.xit.biz.ctgy.dto.MinUserinfoDto; +import com.xit.biz.ctgy.entity.MinUserinfo; +import com.xit.biz.ctgy.v2.repository.UserDao; +import com.xit.core.constant.ErrorCode; +import com.xit.core.exception.CustomBaseException; +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; + +@Service +@RequiredArgsConstructor +public class CustomUserDetailsService implements UserDetailsService { + + private final UserDao userDao; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + MinUserinfoDto user = userDao.findByUserid(username).orElseThrow(() -> new CustomBaseException(ErrorCode.USER_NOT_FOUND)); + return UserMinPrincipal.create(MinUserinfo.builder() + .userid(user.getUserid()) + .passwd(user.getPasswd()) + .name(user.getName()) + .regnum(user.getRegnum()) + .mphone(user.getMphone()) + .email(user.getEmail()) + .accesstype(user.getAccesstype()) + .regdate(user.getRegdate()) + .isenable(user.getIsenable()) + .gu(user.getGu()) + .build()); + } +}