use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method negativeTest.
@Test
public void negativeTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resource", RESOURCE_NAME + "/index.html");
params.add("action", "GET");
params.add("realm", REALM);
String decision = decisionClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("text/plain").get(String.class);
if ((decision != null) && decision.equals("allow")) {
throw new Exception("RESTTest.negativeTest (/decision) failed");
}
String json = entitlementClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("application/json").get(String.class);
JSONObject jo = new JSONObject(json);
if (jo.optInt("statusCode") != 200) {
throw new Exception("RESTTest.negativeTest() failed, status code not 200");
}
JSONObject jbody = jo.optJSONObject("body");
if (jbody == null) {
throw new Exception("RESTTest.negativeTest() failed, body element is null");
}
JSONEntitlement ent = new JSONEntitlement(jbody);
boolean result = false;
Object resultObj = ent.getActionValue("GET");
if (resultObj != null) {
result = ent.getActionValue("GET");
}
if (result) {
throw new Exception("RESTTest.getnegativeTest() failed");
}
Map<String, Set<String>> advices = ent.getAdvices();
Set<String> setNumericCondAdvice = advices.get(NumericAttributeCondition.class.getName());
if ((setNumericCondAdvice == null) || setNumericCondAdvice.isEmpty()) {
throw new Exception("RESTTest.negativeTest: no advice");
}
String advice = setNumericCondAdvice.iterator().next();
if (!advice.equals(ATTR_NAME + "=" + ATTR_VAL)) {
throw new Exception("RESTTest.negativeTest: incorrect advice");
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method getDecisionTest.
@Test
public void getDecisionTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resource", RESOURCE_NAME + "/index.html");
params.add("action", "GET");
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
String decision = decisionClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("text/plain").get(String.class);
if ((decision == null) || !decision.equals("allow")) {
throw new Exception("RESTTest.getDecisionTest() failed");
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method missingActionTest.
@Test
public void missingActionTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resource", RESOURCE_NAME + "/index.html");
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
try {
decisionClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("text/plain").get(String.class);
throw new Exception("RESTTest.missingActionTest: no exception thrown.");
} catch (UniformInterfaceException e) {
int errorCode = e.getResponse().getStatus();
if (errorCode != 400) {
throw new Exception("RESTTest.missingActionTest: incorrect error code");
}
}
}
use of com.sun.jersey.api.representation.Form in project ORCID-Source by ORCID.
the class SalesForceDaoImpl method getFreshAccessToken.
private String getFreshAccessToken() {
LOGGER.info("About get SalesForce access token");
WebResource resource = client.resource(tokenEndPointUrl);
Form form = new Form();
form.add("grant_type", "password");
form.add("client_id", clientId);
form.add("client_secret", clientSecret);
form.add("username", username);
form.add("password", password);
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, form);
if (response.getStatus() == 200) {
try {
return response.getEntity(JSONObject.class).getString("access_token");
} catch (ClientHandlerException | UniformInterfaceException | JSONException e) {
throw new RuntimeException("Unable to extract access token from response", e);
}
} else {
throw new RuntimeException("Error getting access token from SalesForce, status code = " + response.getStatus() + ", reason = " + response.getStatusInfo().getReasonPhrase() + ", body = " + response.getEntity(String.class));
}
}
use of com.sun.jersey.api.representation.Form in project activityinfo by bedatadriven.
the class PoEditorClient method addTerms.
public void addTerms(int projectId, List<PoTerm> terms) {
String data;
try {
data = objectMapper.writeValueAsString(terms);
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println(data);
Form form = new Form();
form.putSingle("id", Integer.toString(projectId));
form.putSingle("action", "add_terms");
form.putSingle("api_token", token);
form.putSingle("data", data);
}
Aggregations