| | |
| | | import kr.wisestone.owl.constant.MsgConstants; |
| | | import kr.wisestone.owl.domain.ApiToken; |
| | | import kr.wisestone.owl.domain.User; |
| | | import kr.wisestone.owl.exception.ApiAuthException; |
| | | import kr.wisestone.owl.exception.OwlRuntimeException; |
| | | import kr.wisestone.owl.repository.ApiTokenRepository; |
| | | import kr.wisestone.owl.service.ApiTokenService; |
| | | import kr.wisestone.owl.service.UserService; |
| | | import kr.wisestone.owl.util.ConvertUtil; |
| | | import kr.wisestone.owl.util.DateUtil; |
| | | import kr.wisestone.owl.util.WebAppUtil; |
| | |
| | | |
| | | @Autowired |
| | | private ApiTokenRepository apiTokenRepository; |
| | | |
| | | |
| | | @Autowired |
| | | protected WebAppUtil webAppUtil; |
| | |
| | | |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | //반환 타입은 LinkedHashMap 이다. 이를 User 타입으로 변환하기 위해 ObjectMapper 사용 |
| | | return objectMapper.convertValue(claims.getBody().get(DATA_KEY), UserVo.class); |
| | | try { |
| | | return objectMapper.convertValue(claims.getBody().get(DATA_KEY), UserVo.class); |
| | | } catch (Exception ex) { |
| | | log.debug(ex.getMessage()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private Jws<Claims> decryption(String jwt) { |
| | |
| | | @Override |
| | | public ApiTokenVo find() { |
| | | User user = this.webAppUtil.getLoginUserObject(); |
| | | List<ApiToken> apiTokens = this.apiTokenRepository.findByUserId(user.getId()); |
| | | if (apiTokens != null && apiTokens.size() >0 ) { |
| | | return ConvertUtil.copyProperties(apiTokens.get(0), ApiTokenVo.class); |
| | | return this.find(user.getId()); |
| | | } |
| | | |
| | | private ApiTokenVo find(Long userId) { |
| | | if (userId != null) { |
| | | List<ApiToken> apiTokens = this.apiTokenRepository.findByUserId(userId); |
| | | if (apiTokens != null && apiTokens.size() > 0) { |
| | | return ConvertUtil.copyProperties(apiTokens.get(0), ApiTokenVo.class); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | // 토큰 사용자 인증 |
| | | // 토큰 사용자 인증, 인증후 사용자 가져오기 |
| | | @Override |
| | | public UserVo certification(String token) { |
| | | UserVo userVo = this.getUserVo(token); |
| | | if (userVo != null){ |
| | | if (userVo != null && containsToken(userVo, token)) |
| | | { |
| | | return userVo; |
| | | } else { |
| | | throw new OwlRuntimeException( |
| | | throw new ApiAuthException( |
| | | this.messageAccessor.getMessage(MsgConstants.ERROR_TOKEN)); |
| | | } |
| | | } |
| | | |
| | | // 토큰으로 찾기 |
| | | private ApiToken find(String token) { |
| | | List<ApiToken> apiTokens = this.apiTokenRepository.findByToken(token); |
| | | if (apiTokens != null && apiTokens.size() > 0) { |
| | | return apiTokens.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | // 토큰 값이 db에 존재하는지 확인 |
| | | private boolean containsToken(UserVo userVo, String token) { |
| | | List<ApiToken> apiTokens = this.apiTokenRepository.findByUserId(userVo.getId()); |
| | | if (apiTokens != null && apiTokens.size() > 0) { |
| | | return apiTokens.get(0).getToken().equals(token); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | // 토큰 삭제 |
| | | @Override |
| | | public void remove(ApiTokenForm apiTokenForm) { |