From 1aab5db212e50c433130d547c308040a95b28112 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Fri, 8 Jul 2022 14:22:24 +0900 Subject: [PATCH] config: config set --- .../service/CustomUserDetailsService.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/com/xit/core/oauth2/oauth/service/CustomUserDetailsService.java 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()); + } +}