Guest User

Untitled

a guest
Apr 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. private String obtainAccessToken(String username, String password) throws Exception {
  2.  
  3. ArrayList<NameValuePair> params;
  4.  
  5. params = new ArrayList<NameValuePair>();
  6. params.add(new BasicNameValuePair("grant_type", "password"));
  7. params.add(new BasicNameValuePair("username", username));
  8. params.add(new BasicNameValuePair("password", password));
  9.  
  10. HttpPost request = new HttpPost(new URL("http://localhost:" + 8080 + "/oauth/token/").toURI());
  11.  
  12.  
  13. request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
  14.  
  15.  
  16. request.setHeader(new BasicHeader("Authorization", "Basic Z2lneTpzZWNyZXQ="));
  17. request.setHeader("Content-type", "application/x-www-form-urlencoded");
  18.  
  19. System.out.println("executing request " + request.getRequestLine());
  20. HttpResponse response = HttpClientBuilder.create().build().execute(request);
  21.  
  22. String test = response.getEntity().getContent().toString();
  23.  
  24. JacksonJsonParser jsonParser = new JacksonJsonParser();
  25. return jsonParser.parseMap(response.getEntity().getContent().toString()).get("access_token").toString();
  26. }
  27.  
  28. executing request POST http://localhost:8080/oauth/token/ HTTP/1.1
  29. 22:59:07.416 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
  30. 22:59:07.438 [main] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
  31. 22:59:07.440 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://localhost:8080][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
  32. 22:59:07.460 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://localhost:8080][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
  33. 22:59:07.462 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {}->http://localhost:8080
  34. 22:59:07.470 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to localhost/127.0.0.1:8080
  35. 22:59:07.474 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connection established 127.0.0.1:60428<->127.0.0.1:8080
  36. 22:59:07.474 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request POST /oauth/token/ HTTP/1.1
  37. 22:59:07.474 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
  38. 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> POST /oauth/token/ HTTP/1.1
  39. 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Authorization: Basic Z2lneTpzZWNyZXQ=
  40. 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-type: application/x-www-form-urlencoded
  41. 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 50
  42. 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: localhost:8080
  43. 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
  44. 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.4 (Java/1.8.0_151)
  45. 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
  46. 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "POST /oauth/token/ HTTP/1.1[r][n]"
  47. 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Authorization: Basic Z2lneTpzZWNyZXQ=[r][n]"
  48. 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-type: application/x-www-form-urlencoded[r][n]"
  49. 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length: 50[r][n]"
  50. 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: localhost:8080[r][n]"
  51. 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[r][n]"
  52. 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.4 (Java/1.8.0_151)[r][n]"
  53. 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[r][n]"
  54. 22:59:07.478 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[r][n]"
  55. 22:59:07.479 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "grant_type=password&username=ludo&password=asticot"
  56. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 403 Forbidden[r][n]"
  57. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: Apache-Coyote/1.1[r][n]"
  58. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Content-Type-Options: nosniff[r][n]"
  59. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-XSS-Protection: 1; mode=block[r][n]"
  60. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Cache-Control: no-cache, no-store, max-age=0, must-revalidate[r][n]"
  61. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Pragma: no-cache[r][n]"
  62. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Expires: 0[r][n]"
  63. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Frame-Options: DENY[r][n]"
  64. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Set-Cookie: JSESSIONID=D8C9BEE08765CCFA35DD604A990B351A; Path=/; HttpOnly[r][n]"
  65. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json;charset=UTF-8[r][n]"
  66. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Transfer-Encoding: chunked[r][n]"
  67. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Tue, 17 Apr 2018 20:59:07 GMT[r][n]"
  68. 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[r][n]"
  69. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 403 Forbidden
  70. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Server: Apache-Coyote/1.1
  71. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Content-Type-Options: nosniff
  72. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-XSS-Protection: 1; mode=block
  73. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Cache-Control: no-cache, no-store, max-age=0, must-revalidate
  74. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Pragma: no-cache
  75. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Expires: 0
  76. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Frame-Options: DENY
  77. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: JSESSIONID=D8C9BEE08765CCFA35DD604A990B351A; Path=/; HttpOnly
  78. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: application/json;charset=UTF-8
  79. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Transfer-Encoding: chunked
  80. 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Tue, 17 Apr 2018 20:59:07 GMT
  81. 22:59:07.496 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Connection can be kept alive indefinitely
Add Comment
Please, Sign In to add comment