diff --git a/src/main/java/com/xit/biz/ctgy/auth/MinPasswordEncoder.java b/src/main/java/com/xit/biz/ctgy/auth/MinPasswordEncoder.java index 9a7f128..f796bab 100644 --- a/src/main/java/com/xit/biz/ctgy/auth/MinPasswordEncoder.java +++ b/src/main/java/com/xit/biz/ctgy/auth/MinPasswordEncoder.java @@ -1,6 +1,7 @@ package com.xit.biz.ctgy.auth; import com.xit.biz.ctgy.repository.IMinUserRepository; +import com.xit.biz.ctgy.v2.dao.MinUserinfoDao; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -17,11 +18,7 @@ public class MinPasswordEncoder implements PasswordEncoder { @Setter private String userid; - private final IMinUserRepository repository; - -// public MinPasswordEncoder(IMinUserinfoRepository repository) { -// this.repository = repository; -// } + private final MinUserinfoDao minUserinfoDao; /** * 비밀번호 암호화 @@ -33,7 +30,7 @@ public class MinPasswordEncoder implements PasswordEncoder { if (rawPassword == null) { throw new IllegalArgumentException("rawPassword cannot be null"); } - return repository.queryGetPasswdEncode(rawPassword.toString()); + return minUserinfoDao.queryGetPasswdEncode(rawPassword.toString()); } /** @@ -44,7 +41,6 @@ public class MinPasswordEncoder implements PasswordEncoder { */ @Override public boolean matches(CharSequence rawPassword, String encodedPassword) { - //return false; if (rawPassword == null) { throw new IllegalArgumentException("rawPassword cannot be null"); @@ -54,7 +50,7 @@ public class MinPasswordEncoder implements PasswordEncoder { return false; } - return Objects.equals(repository.queryGetPasswd(rawPassword.toString()), encodedPassword); + return Objects.equals(minUserinfoDao.queryGetPasswd(rawPassword.toString()), encodedPassword); } /** diff --git a/src/main/java/com/xit/biz/ctgy/auth/service/impl/AuthMinService.java b/src/main/java/com/xit/biz/ctgy/auth/service/impl/AuthMinService.java index bf54f27..d2618ac 100644 --- a/src/main/java/com/xit/biz/ctgy/auth/service/impl/AuthMinService.java +++ b/src/main/java/com/xit/biz/ctgy/auth/service/impl/AuthMinService.java @@ -3,11 +3,14 @@ package com.xit.biz.ctgy.auth.service.impl; import com.xit.biz.cmm.entity.CmmUser; import com.xit.biz.ctgy.auth.service.IAuthMinService; import com.xit.biz.ctgy.dto.LoginMinRequestDto; +import com.xit.biz.ctgy.dto.MinUserinfoDto; import com.xit.biz.ctgy.entity.MinUserinfo; import com.xit.biz.ctgy.repository.IMinUserRepository; +import com.xit.biz.ctgy.v2.dao.MinUserinfoDao; import com.xit.core.constant.ErrorCode; import com.xit.core.constant.XitConstants; import com.xit.core.exception.TokenAuthException; +import com.xit.core.oauth2.api.dao.RefreshTokenDao; import com.xit.core.oauth2.api.dto.TokenDto; import com.xit.core.oauth2.api.dto.TokenRequestDto; import com.xit.core.oauth2.api.entity.RefreshToken; @@ -49,9 +52,9 @@ public class AuthMinService implements IAuthMinService { private final AppProperties appProperties; private final AuthenticationManager authenticationManager; - private final IMinUserRepository userRepository; + private final MinUserinfoDao userinfoDao; private final JwtTokenProvider jwtTokenProvider; - private final RefreshTokenRepository refreshTokenRepository; + private final RefreshTokenDao refreshTokenDao; /** *
@@ -96,19 +99,19 @@ public class AuthMinService implements IAuthMinService { session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext()); } - MinUserinfo user = userRepository.findByUserid(loginRequestDto.getUserid()).orElseThrow(() -> new UsernameNotFoundException(loginRequestDto.getUserid() + " -> 사용자를 찾을 수 없습니다.")); + MinUserinfoDto user = userinfoDao.findByUserid(loginRequestDto.getUserid()).orElseThrow(() -> new UsernameNotFoundException(loginRequestDto.getUserid() + " -> 사용자를 찾을 수 없습니다.")); MapinfoMap = new HashMap<>(); infoMap.put(XitConstants.JwtToken.TOKEN_USER_NAME.getCode(), user.getName()); infoMap.put(XitConstants.JwtToken.TOKEN_USER_MAIL.getCode(), user.getEmail()); - RefreshToken savedRefreshToken = refreshTokenRepository.findByKey(authentication.getName()) + RefreshToken savedRefreshToken = refreshTokenDao.findByKey(authentication.getName()) .orElse(null); // 저장된 refresh token not exists if (Checks.isNull(savedRefreshToken) || Checks.isNull(savedRefreshToken.getValue())) { // 없는 경우 새로 등록 tokenDto = jwtTokenProvider.generateTokenDto(authentication, infoMap); - refreshTokenRepository.saveAndFlush( + refreshTokenDao.save( RefreshToken.builder() .key(loginRequestDto.getUserid()) .value(tokenDto.getRefreshToken()) @@ -118,7 +121,6 @@ public class AuthMinService implements IAuthMinService { // 저장된 토큰이 있다 } else { - // 만료되지 않은 refresh token if(!jwtTokenProvider.isExpiredToken(savedRefreshToken.getValue())) { @@ -137,10 +139,10 @@ public class AuthMinService implements IAuthMinService { tokenDto = TokenDto.builder() .grantType(XitConstants.JwtToken.GRANT_TYPE.getCode()) .accessToken(jwtTokenProvider.generateJwtAccessToken(authentication, infoMap)) - .refreshToken(null) + .refreshToken(savedRefreshToken.getValue()) .build(); - refreshTokenRepository.saveAndFlush( + refreshTokenDao.update( RefreshToken.builder() .key(loginRequestDto.getUserid()) .value(tokenDto.getRefreshToken()) @@ -152,7 +154,7 @@ public class AuthMinService implements IAuthMinService { }else{ tokenDto = jwtTokenProvider.generateTokenDto(authentication, infoMap); - refreshTokenRepository.saveAndFlush( + refreshTokenDao.update( RefreshToken.builder() .key(loginRequestDto.getUserid()) .value(tokenDto.getRefreshToken()) @@ -168,7 +170,20 @@ public class AuthMinService implements IAuthMinService { } // 5. 토큰 발급 - tokenDto.setUser(user); + tokenDto.setUser( + 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() + ); return tokenDto; } @@ -240,7 +255,7 @@ public class AuthMinService implements IAuthMinService { jwtTokenProvider.validateTokenExcludeExpired(sRefreshToken, true, true); // userId refresh token 으로 DB 확인 - RefreshToken savedRefreshToken = refreshTokenRepository.findByKey(authentication.getName()) + RefreshToken savedRefreshToken = refreshTokenDao.findByKey(authentication.getName()) .orElse(null); if (Checks.isEmpty(savedRefreshToken)) throw new TokenAuthException(ErrorCode.NOT_EXISTS_SAVED_REFRESH_TOKEN); @@ -249,7 +264,7 @@ public class AuthMinService implements IAuthMinService { } // 토큰 부가 정보 set - MinUserinfo user = userRepository.findByUserid(authentication.getName()).orElse(null); + MinUserinfoDto user = userinfoDao.findByUserid(authentication.getName()).orElse(null); if(Checks.isNull(user)) throw new TokenAuthException(ErrorCode.INVALID_ROLE_TOKEN); Map infoMap = new HashMap<>(); infoMap.put(XitConstants.JwtToken.TOKEN_USER_NAME.getCode(), user.getName()); diff --git a/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinUserDetailsService.java b/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinUserDetailsService.java index b327534..c2721fb 100644 --- a/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinUserDetailsService.java +++ b/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinUserDetailsService.java @@ -1,8 +1,10 @@ package com.xit.biz.ctgy.auth.service.impl; 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.repository.IMinUserRepository; +import com.xit.biz.ctgy.v2.dao.MinUserinfoDao; import com.xit.core.constant.ErrorCode; import com.xit.core.exception.CustomBaseException; import lombok.RequiredArgsConstructor; @@ -15,11 +17,22 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class CustomMinUserDetailsService implements UserDetailsService { - private final IMinUserRepository userRepository; + private final MinUserinfoDao minUserinfoDao; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - MinUserinfo user = userRepository.findByUserid(username).orElseThrow(() -> new CustomBaseException(ErrorCode.USER_NOT_FOUND)); - return UserMinPrincipal.create(user); + MinUserinfoDto user = minUserinfoDao.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()); } } diff --git a/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java b/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java index 884808a..c4990e7 100644 --- a/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java +++ b/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java @@ -51,6 +51,7 @@ public class MinUserController { final MinUserinfoDto minUserinfoDto, @Parameter(hidden = true) final Pageable pageable) { + //return null; return RestResponse.of(service.findMinUsers(mapstruct.toEntity(minUserinfoDto), pageable)); } diff --git a/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java b/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java index 1e0f46c..0d62756 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import java.io.Serializable; +import java.time.LocalDate; import java.util.Objects; @Schema(name = "MinUserinfoDto", description = "사용자 DTO") @@ -39,7 +40,7 @@ public class MinUserinfoDto implements Serializable { private String team; @Schema(required = false, title = "등록일시", example = " ", description = "Input Description...") - private java.sql.Date regdate; + private LocalDate regdate; @Schema(required = false, title = "사용여부", example = " ", description = "Input Description...") private String isenable; diff --git a/src/main/java/com/xit/biz/ctgy/v2/controller/MinUserController.java b/src/main/java/com/xit/biz/ctgy/v2/controller/MinUserController.java index 05e9a11..c5a49b5 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/controller/MinUserController.java +++ b/src/main/java/com/xit/biz/ctgy/v2/controller/MinUserController.java @@ -33,8 +33,6 @@ public class MinUserController { private final IMinUserService service; - private final MinUserinfoMapstruct mapstruct = Mappers.getMapper(MinUserinfoMapstruct.class); - // TODO :: 파라메터 정의 필요 @Secured(policy = SecurityPolicy.TOKEN) @Operation(summary = "사용자 목록 조회" , description = "사용자 목록 조회") @@ -51,7 +49,8 @@ public class MinUserController { final MinUserinfoDto minUserinfoDto, @Parameter(hidden = true) final Pageable pageable) { - return RestResponse.of(service.findMinUsers(mapstruct.toEntity(minUserinfoDto), pageable)); + return null; + //return RestResponse.of(service.findMinUsers(mapstruct.toEntity(minUserinfoDto), pageable)); } @Operation(summary = "사용자 정보 조회" , description = "사용자 정보 조회") diff --git a/src/main/java/com/xit/biz/ctgy/v2/dao/MinUserinfoDao.java b/src/main/java/com/xit/biz/ctgy/v2/dao/MinUserinfoDao.java new file mode 100644 index 0000000..9a5e849 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/v2/dao/MinUserinfoDao.java @@ -0,0 +1,60 @@ +package com.xit.biz.ctgy.v2.dao; + +import com.xit.biz.ctgy.dto.MinUserinfoDto; +import com.xit.biz.ctgy.entity.MinUserinfo; +import com.xit.core.support.sql.parser.QueryGenerator; +import com.xit.core.util.mpower.MpowerUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +@Repository +@Slf4j +public class MinUserinfoDao { + public Optional findByUserid(final String userid){ + String sql = QueryGenerator.createNamedQuery("user", "selectUserInfo") + .setParameter("userid", userid) + .getQueryString(); + MpowerUtils query = new MpowerUtils(); + query.setFeilds("userid, passwd, name, regnum, mphone, email, accesstype, team, isenable, gu"); + query.setQuery(sql); + log.debug("=======>>>>>>", sql); + return Optional.ofNullable(query.getListObject(MinUserinfoDto.class).get(0)); + } + + public String queryGetPasswdEncode(final String passwd){ + String sql = QueryGenerator.createNamedQuery("user", "selectPasswdEnc") + .setParameter("passwd", passwd) + .getQueryString(); + MpowerUtils query = new MpowerUtils(); + query.setFeilds("passwd"); + query.setQuery(sql); + log.debug("=======>>>>>>", sql); + return String.valueOf(query.getListMap().get(0).get("passwd")); + } + + //@Query(value = "SELECT ECL_DECRYPT(MU.passwd) AS passwd FROM min_userinfo MU WHERE MU.userid = ?1", nativeQuery = true) + public String queryGetPasswd(final String userid){ + String sql = QueryGenerator.createNamedQuery("user", "selectPasswdDec") + .setParameter("userid", userid) + .getQueryString(); + MpowerUtils query = new MpowerUtils(); + query.setFeilds("passwd"); + query.setQuery(sql); + log.debug("=======>>>>>>", sql); + return String.valueOf(query.getListMap().get(0).get("passwd")); + } + + public MinUserinfo findMinUserinfoByUserid(final String userid){ + return null; + } + + //------------------------------------------------------------------------- + // 주정차위반 심사대상 등록 - 등록 대상 심사자 조회 + //------------------------------------------------------------------------- + public List findAllByTeamAndIsenableAndAccesstype(String msuTeam, String isenabled, String accesstype){ + return null; + } +} diff --git a/src/main/java/com/xit/core/config/SecurityConfig.java b/src/main/java/com/xit/core/config/SecurityConfig.java index af39a97..414e1c7 100644 --- a/src/main/java/com/xit/core/config/SecurityConfig.java +++ b/src/main/java/com/xit/core/config/SecurityConfig.java @@ -4,6 +4,7 @@ import com.xit.biz.ctgy.auth.MinPasswordEncoder; import com.xit.biz.ctgy.auth.service.impl.CustomMinOAuth2UserService; import com.xit.biz.ctgy.auth.service.impl.CustomMinUserDetailsService; import com.xit.biz.ctgy.repository.IMinUserRepository; +import com.xit.biz.ctgy.v2.dao.MinUserinfoDao; import com.xit.core.oauth2.api.dao.RefreshTokenDao; import com.xit.core.oauth2.api.repository.RefreshTokenRepository; import com.xit.core.oauth2.config.properties.AppProperties; @@ -105,10 +106,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { private final CustomMinUserDetailsService userDetailsService; private final CustomMinOAuth2UserService customOAuth2UserService; private final TokenAccessDeniedHandler tokenAccessDeniedHandler; - //private final RefreshTokenRepository refreshTokenRepository; private final RefreshTokenDao refreshTokenDao; - - private final IMinUserRepository minUserRepository; + private final MinUserinfoDao minUserinfoDao; /** * 1. configure( WebSecurity) : 서비스 전체에 영향을 미치는 설정 @@ -244,7 +243,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { * */ @Bean public MinPasswordEncoder passwordEncoder() { - return new MinPasswordEncoder(minUserRepository); + return new MinPasswordEncoder(minUserinfoDao); } /* diff --git a/src/main/java/com/xit/core/oauth2/api/dao/RefreshTokenDao.java b/src/main/java/com/xit/core/oauth2/api/dao/RefreshTokenDao.java index ab0ac2b..89d1f26 100644 --- a/src/main/java/com/xit/core/oauth2/api/dao/RefreshTokenDao.java +++ b/src/main/java/com/xit/core/oauth2/api/dao/RefreshTokenDao.java @@ -11,14 +11,10 @@ import java.util.Optional; @Repository public class RefreshTokenDao { - private static final String sqlXmlFile = "sql/refreshToken-mapper"; - public Optional findByKey(String key){ String sql = QueryGenerator.createNamedQuery("refreshToken", "selectRefreshToken") .setParameter("key", key) .getQueryString(); - //String sql = DBUtils.getXmlSql(sqlXmlFile, "selectRefreshToken"); - //sql = sql.replaceFirst(":userId", key); MpowerUtils selectQuery = new MpowerUtils(); selectQuery.setFeilds("key, value"); @@ -27,36 +23,22 @@ public class RefreshTokenDao { } public void save(RefreshToken refreshToken){ -// String sql = DBUtils.getXmlSql(sqlXmlFile, "saveRefreshToken"); -// sql = sql.replaceFirst(":userId", refreshToken.getKey()); -// sql = sql.replaceFirst(":tokenValue", refreshToken.getValue()); - String sql = QueryGenerator.createNamedQuery("refreshToken", "insertRefreshToken") .setParameter("key", refreshToken.getKey()) .setParameter("value", refreshToken.getValue()) .getQueryString(); - MpowerUtils saveQuery = new MpowerUtils(); - //sendXml.setFeilds("key, value"); - //sendXml.setQuery(sql); - //return Optional.ofNullable(sendXml.selectCustomQuery(RefreshToken.class).get(0)); + saveQuery.insertQuery(sql); } public void update(RefreshToken refreshToken){ -// String sql = DBUtils.getXmlSql(sqlXmlFile, "updateRefreshToken"); -// sql = sql.replaceFirst(":userId", refreshToken.getKey()); -// sql = sql.replaceFirst(":tokenValue", refreshToken.getValue()); - String sql = QueryGenerator.createNamedQuery("refreshToken", "updateRefreshToken") .setParameter("value", refreshToken.getValue()) .setParameter("key", refreshToken.getKey()) .getQueryString(); - MpowerUtils updateQuery = new MpowerUtils(); - //sendXml.setFeilds("key, value"); - //sendXml.setQuery(sql); - //return Optional.ofNullable(sendXml.selectCustomQuery(RefreshToken.class).get(0)); + updateQuery.updateQuery(sql); } } diff --git a/src/main/java/com/xit/core/util/mpower/MpowerUtils.java b/src/main/java/com/xit/core/util/mpower/MpowerUtils.java index 5b8f690..7880469 100644 --- a/src/main/java/com/xit/core/util/mpower/MpowerUtils.java +++ b/src/main/java/com/xit/core/util/mpower/MpowerUtils.java @@ -33,31 +33,12 @@ public class MpowerUtils { static int port = 9999; static String query = ""; static ArrayList feilds = new ArrayList (); - //static String feild = ""; - static String tmpFeilds = ""; - static Boolean RowNum = false; - static String tableNm = ""; - static String WhereStr = ""; - static String Orderby = ""; - static int pageIndex = 0; - static int lastIndex = 10; - static int recordCountPerPage = 10; static String beforeXml = " "; - - - //Ps변수 - static String Params = ""; - - static int psParamCount = 0; - static String psFinalFarams =""; - static String QueryXml = ""; - - static String vioPhoto = ""; - static String vioPhotoBus = ""; - static String tunullingFile = ""; - public void setQuery(String query){ MpowerUtils.query = query; } @@ -66,276 +47,10 @@ public class MpowerUtils { feilds.add(feildNm); } - public int getFirstIndex() { - return (pageIndex - 1) * recordCountPerPage +1; - } - - public int getLastIndex() { - return lastIndex = pageIndex * recordCountPerPage; - } - - public List