/** * Executes the call to the REST Service and processes the response. * * @param accessToken The access token obtained from the oxAuth authorization request. * @return The service response. */ public ClientInfoResponse execClientInfo(String accessToken) { setRequest(new ClientInfoRequest(accessToken)); return exec(); }
/** * Constructs a Client Info Request. * * @param accessToken The access token obtained from the oxAuth authorization request. */ public ClientInfoRequest(String accessToken) { this.accessToken = accessToken; setAuthorizationMethod(AuthorizationMethod.AUTHORIZATION_REQUEST_HEADER_FIELD); }
/** * Returns a collection of parameters of the client info request. Any * <code>null</code> or empty parameter will be omitted. * * @return A collection of parameters. */ public Map<String, String> getParameters() { Map<String, String> parameters = new HashMap<String, String>(); if (accessToken != null && !accessToken.isEmpty()) { if (getAuthorizationMethod() == AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER || getAuthorizationMethod() == AuthorizationMethod.URL_QUERY_PARAMETER) { parameters.put("access_token", accessToken); } } return parameters; } }
@Parameters({ "clientInfoPath" }) @Test public void requestClientInfoInvalidToken(final String clientInfoPath) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + clientInfoPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); ClientInfoRequest clientInfoRequest = new ClientInfoRequest("INVALID-TOKEN"); clientInfoRequest.setAuthorizationMethod(AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestClientInfoInvalidToken", response, entity); assertEquals(response.getStatus(), 400, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
@Parameters({ "clientInfoPath" }) @Test public void requestClientInfoInvalidRequest(final String clientInfoPath) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + clientInfoPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestClientInfoInvalidRequest", response, entity); assertEquals(response.getStatus(), 400, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
public void requestClientInfoStep2GetImplicitFlow(final String clientInfoPath) throws Exception { ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null); Builder request = ResteasyClientBuilder.newClient() .target(url.toString() + clientInfoPath + "?" + clientInfoRequest.getQueryString()).request();
clientRequest.setHttpMethod(getHttpMethod()); if (getRequest().getAuthorizationMethod() == null || getRequest().getAuthorizationMethod() == AuthorizationMethod.AUTHORIZATION_REQUEST_HEADER_FIELD) { if (StringUtils.isNotBlank(getRequest().getAccessToken())) { clientRequest.header("Authorization", "Bearer " + getRequest().getAccessToken()); } else if (getRequest().getAuthorizationMethod() == AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER) { if (StringUtils.isNotBlank(getRequest().getAccessToken())) { clientRequest.formParameter("access_token", getRequest().getAccessToken()); } else if (getRequest().getAuthorizationMethod() == AuthorizationMethod.URL_QUERY_PARAMETER) { if (StringUtils.isNotBlank(getRequest().getAccessToken())) { clientRequest.queryParameter("access_token", getRequest().getAccessToken()); if (getRequest().getAuthorizationMethod() == null || getRequest().getAuthorizationMethod() == AuthorizationMethod.AUTHORIZATION_REQUEST_HEADER_FIELD || getRequest().getAuthorizationMethod() == AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER) { clientResponse = clientRequest.post(String.class); } else { //AuthorizationMethod.URL_QUERY_PARAMETER
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null); .post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters()))); String entity = response.readEntity(String.class);
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null); .post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters()))); String entity = response.readEntity(String.class);
/** * Returns a query string with the parameters of the Client Info request. * Any <code>null</code> or empty parameter will be omitted. * * @return A query string of parameters. */ @Override public String getQueryString() { StringBuilder queryStringBuilder = new StringBuilder(); if (accessToken != null && !accessToken.isEmpty()) { if (getAuthorizationMethod() == AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER || getAuthorizationMethod() == AuthorizationMethod.URL_QUERY_PARAMETER) { queryStringBuilder.append("access_token=").append(accessToken); } } return queryStringBuilder.toString(); }
@Override public String getHttpMethod() { if (getRequest().getAuthorizationMethod() == null || getRequest().getAuthorizationMethod() == AuthorizationMethod.AUTHORIZATION_REQUEST_HEADER_FIELD || getRequest().getAuthorizationMethod() == AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER) { return HttpMethod.POST; } else { // AuthorizationMethod.URL_QUERY_PARAMETER return HttpMethod.GET; } }