Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. @Action("VALIDATE_2FA")
  2. @RequestMapping(value = "/validate", method = RequestMethod.POST)
  3. public ResponseEntity<JSONObject> validateCode(HttpServletRequest request, String userId, String code,
  4. HttpServletResponse response) throws IOException, TokenIssuerException {
  5.  
  6. JSONObject jsonObject = new JSONObject();
  7.  
  8. if (code != null) {
  9.  
  10. ICode cacheCode = tokenCache.getCode(code, null);
  11.  
  12. IClientInfo clientInfo = clientAuthCore.getClient(request, response, true);
  13.  
  14. boolean checkClientId = checkClientID(clientInfo, cacheCode);
  15. if (checkClientId) {
  16.  
  17. String seshUser = cacheCode.getSessionInfo().getUserId().trim();
  18.  
  19. if (userId != null) {
  20. // Validate UserID if equals like in cache
  21. boolean validUser = validateUser(userId, cacheCode);
  22. if (validUser) {
  23. jsonObject.put("code", true);
  24. tokenCache.revokeCode(cacheCode);
  25. return new ResponseEntity<>(jsonObject, HttpStatus.OK);
  26. } else {
  27. LOG.trace("Validation not passed");
  28. jsonObject.put("code", false);
  29. return new ResponseEntity<>(jsonObject, HttpStatus.BAD_REQUEST);
  30. }
  31.  
  32. } else {
  33. jsonObject.put("userID", seshUser);
  34. tokenCache.revokeCode(cacheCode);
  35. return new ResponseEntity<>(jsonObject, HttpStatus.OK);
  36. }
  37. } else {
  38. LOG.trace("Invalid Client provided");
  39. return new ResponseEntity<>(jsonObject, HttpStatus.BAD_REQUEST);
  40. }
  41. } else {
  42. LOG.trace("Invalid parameters");
  43. return new ResponseEntity<>(jsonObject, HttpStatus.BAD_REQUEST);
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement