jbjares2

Untitled

Jan 31st, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. /*
  2. * Gets the fiesta username
  3. *
  4. * @param SSOtoken the authentication token
  5. */
  6. private User getUserByCookie(String SSOtoken) {
  7. /**
  8. * Create a Jersey client to GET the user id information from the
  9. * Session using a POST call to the OpenAM idm API.
  10. */
  11. Client client = Client.create();
  12. WebResource webResourceOpenAM = client.resource(AUTHENTICATION_URL);
  13. ClientResponse responseAuth = webResourceOpenAM.type("application/json").header(IPLANETDIRECTORYPRO, SSOtoken)
  14. .post(ClientResponse.class, "{}");
  15. if (responseAuth.getStatus() != 200) {
  16. throw new RuntimeException("Failed : HTTP error code : " + responseAuth.getStatus());
  17. }
  18. String userObject = responseAuth.getEntity(String.class);
  19. User dto = null;
  20. ObjectMapper objectUser = new ObjectMapper();
  21. JsonNode userNode;
  22. try {
  23. userNode = objectUser.readValue(userObject, JsonNode.class);
  24. String id = userNode.get("id").asText();
  25. dto = new User();
  26. dto.setId(id);
  27. } catch (JsonParseException e) {
  28. // TODO Auto-generated catch block
  29. e.printStackTrace();
  30. } catch (JsonMappingException e) {
  31. // TODO Auto-generated catch block
  32. e.printStackTrace();
  33. } catch (IOException e) {
  34. // TODO Auto-generated catch block
  35. e.printStackTrace();
  36. }
  37. return dto;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment