Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private String obtainAccessToken(String username, String password) throws Exception {
- ArrayList<NameValuePair> params;
- params = new ArrayList<NameValuePair>();
- params.add(new BasicNameValuePair("grant_type", "password"));
- params.add(new BasicNameValuePair("username", username));
- params.add(new BasicNameValuePair("password", password));
- HttpPost request = new HttpPost(new URL("http://localhost:" + 8080 + "/oauth/token/").toURI());
- request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
- request.setHeader(new BasicHeader("Authorization", "Basic Z2lneTpzZWNyZXQ="));
- request.setHeader("Content-type", "application/x-www-form-urlencoded");
- System.out.println("executing request " + request.getRequestLine());
- HttpResponse response = HttpClientBuilder.create().build().execute(request);
- String test = response.getEntity().getContent().toString();
- JacksonJsonParser jsonParser = new JacksonJsonParser();
- return jsonParser.parseMap(response.getEntity().getContent().toString()).get("access_token").toString();
- }
- executing request POST http://localhost:8080/oauth/token/ HTTP/1.1
- 22:59:07.416 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
- 22:59:07.438 [main] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
- 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]
- 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]
- 22:59:07.462 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {}->http://localhost:8080
- 22:59:07.470 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to localhost/127.0.0.1:8080
- 22:59:07.474 [main] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connection established 127.0.0.1:60428<->127.0.0.1:8080
- 22:59:07.474 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request POST /oauth/token/ HTTP/1.1
- 22:59:07.474 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
- 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> POST /oauth/token/ HTTP/1.1
- 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Authorization: Basic Z2lneTpzZWNyZXQ=
- 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-type: application/x-www-form-urlencoded
- 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 50
- 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: localhost:8080
- 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
- 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)
- 22:59:07.477 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
- 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "POST /oauth/token/ HTTP/1.1[r][n]"
- 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Authorization: Basic Z2lneTpzZWNyZXQ=[r][n]"
- 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-type: application/x-www-form-urlencoded[r][n]"
- 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length: 50[r][n]"
- 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: localhost:8080[r][n]"
- 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[r][n]"
- 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]"
- 22:59:07.477 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[r][n]"
- 22:59:07.478 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[r][n]"
- 22:59:07.479 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "grant_type=password&username=ludo&password=asticot"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 403 Forbidden[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: Apache-Coyote/1.1[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Content-Type-Options: nosniff[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-XSS-Protection: 1; mode=block[r][n]"
- 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]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Pragma: no-cache[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Expires: 0[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Frame-Options: DENY[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Set-Cookie: JSESSIONID=D8C9BEE08765CCFA35DD604A990B351A; Path=/; HttpOnly[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json;charset=UTF-8[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Transfer-Encoding: chunked[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Tue, 17 Apr 2018 20:59:07 GMT[r][n]"
- 22:59:07.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[r][n]"
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 403 Forbidden
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Server: Apache-Coyote/1.1
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Content-Type-Options: nosniff
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-XSS-Protection: 1; mode=block
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Cache-Control: no-cache, no-store, max-age=0, must-revalidate
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Pragma: no-cache
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Expires: 0
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Frame-Options: DENY
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: JSESSIONID=D8C9BEE08765CCFA35DD604A990B351A; Path=/; HttpOnly
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: application/json;charset=UTF-8
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Transfer-Encoding: chunked
- 22:59:07.488 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Tue, 17 Apr 2018 20:59:07 GMT
- 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