ViewController.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.icontrols.oauth.controller;
  2. import java.io.UnsupportedEncodingException;
  3. import java.security.GeneralSecurityException;
  4. import java.security.NoSuchAlgorithmException;
  5. import java.time.Duration;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.data.redis.connection.RedisConnectionFactory;
  10. import org.springframework.data.redis.core.RedisTemplate;
  11. import org.springframework.data.redis.core.ValueOperations;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import com.icontrols.oauth.utils.JWTUtils;
  17. @RestController
  18. @RequestMapping(value = "/api/oauth2")
  19. public class ViewController {
  20. private static final Logger logger = LoggerFactory.getLogger(ViewController.class);
  21. @Autowired
  22. RedisTemplate<String, Object> redisTemplate;
  23. // redis 테스트
  24. @RequestMapping(value = "/check", method = RequestMethod.GET)
  25. public String validTest(@RequestParam(value = "token", required = false) String token)
  26. throws UnsupportedEncodingException, NoSuchAlgorithmException, GeneralSecurityException {
  27. JWTUtils jwt = new JWTUtils();
  28. Boolean bool = jwt.validateToken(token, "accessToken");
  29. logger.info("validate :" + bool.toString());
  30. String cmpIp = jwt.getCmpIpFromToken(token);
  31. logger.info("cmpIp :" + cmpIp);
  32. String homeId = jwt.getHomeIdFromToken(token);
  33. logger.info("homeId :" + homeId);
  34. return bool.toString();
  35. }
  36. }