use of com.sun.identity.entitlement.JSONEntitlement in project OpenAM by OpenRock.
the class RestTest method getEntitlementsTest.
@Test
public void getEntitlementsTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resource", RESOURCE_NAME);
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
String json = entitlementsClient.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.getEntitlementsTest: failed, status code not 200");
}
JSONObject jbody = jo.optJSONObject("body");
if (jbody == null) {
throw new Exception("RESTTest.getEntitlementsTest: failed, body element is null");
}
JSONArray results = jbody.optJSONArray("results");
if (results == null) {
throw new Exception("RESTTest.getEntitlementsTest: failed, results element is null");
}
if (results.length() < 1) {
throw new Exception("RESTTest.getEntitlementsTest: failed, results array is empty");
}
// dude, there are two entitlements returned.
// the first one is the root resource which is http://www.resttest.com
// and the action value is empty.
// we need to get the second one, which is http://www.resttest.com:80/*
JSONEntitlement ent = new JSONEntitlement(results.getJSONObject(1));
Object resultObj = ent.getActionValue("GET");
if (resultObj != null) {
if (!ent.getActionValue("GET")) {
throw new Exception("RESTTest.getEntitlementsTest: failed, action value is false");
}
} else {
throw new Exception("RESTTest.getEntitlementsTest: failed, action value is null");
}
}
use of com.sun.identity.entitlement.JSONEntitlement in project OpenAM by OpenRock.
the class RestTest method getEntitlementTest.
@Test
public void getEntitlementTest() 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 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.getEntitlementTest() failed, status code not 200");
}
JSONObject jbody = jo.optJSONObject("body");
if (jbody == null) {
throw new Exception("RESTTest.getEntitlementTest() failed, body element is null");
}
JSONEntitlement ent = new JSONEntitlement(jbody);
boolean result = ent.getActionValue("GET");
if (!result) {
throw new Exception("RESTTest.getEntitlementTest() failed");
}
}
use of com.sun.identity.entitlement.JSONEntitlement in project OpenAM by OpenRock.
the class MultipleResourceRestTest method testEntitlements.
@Test
public void testEntitlements() throws Exception {
MultivaluedMap params = new MultivaluedMapImpl();
params.add("resource", RESOURCE_NAME);
params.add("realm", REALM);
params.add("subject", hashedTokenId);
String json = entitlementsClient.queryParams(params).accept("application/json").header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
List<JSONEntitlement> entitlements = JSONEntitlement.getEntitlements(new JSONObject(json));
for (JSONEntitlement e : entitlements) {
String res = e.getResourceName();
Map<String, Boolean> actionValues = e.getActionValues();
if (res.equals(RESOURCE_NAME)) {
if (!actionValues.isEmpty()) {
throw new Exception("MultipleResourceRestTest.testEntitlements: incorrect result for root");
}
} else if (res.equals(RESOURCE_NAME + ":80/index.html")) {
if (actionValues.get("GET")) {
throw new Exception("MultipleResourceRestTest.testEntitlements: incorrect result for /index.html");
}
} else if (res.equals(RESOURCE_NAME + ":80/*")) {
if (!actionValues.get("GET")) {
throw new Exception("MultipleResourceRestTest.testEntitlements: incorrect result for /*");
}
}
}
}
use of com.sun.identity.entitlement.JSONEntitlement in project OpenAM by OpenRock.
the class MultipleResourceRestTest method testDecisions.
@Test
public void testDecisions() throws Exception {
MultivaluedMap params = new MultivaluedMapImpl();
params.add("resources", RESOURCE_NAME + "/index.html");
params.add("resources", RESOURCE_NAME + "/a");
params.add("action", "GET");
params.add("realm", REALM);
params.add("subject", hashedTokenId);
String json = decisionsClient.queryParams(params).accept("application/json").header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
List<JSONEntitlement> entitlements = JSONEntitlement.getEntitlements(new JSONObject(json));
for (JSONEntitlement e : entitlements) {
String res = e.getResourceName();
Map<String, Boolean> actionValues = e.getActionValues();
if (res.equals(RESOURCE_NAME + "/index.html")) {
if (actionValues.get("GET")) {
throw new Exception("MultipleResourceRestTest.testDecisions: incorrect result for /index.html");
}
} else if (res.equals(RESOURCE_NAME + "/a")) {
if (!actionValues.get("GET")) {
throw new Exception("MultipleResourceRestTest.testDecisions: incorrect result for /a");
}
}
}
}
use of com.sun.identity.entitlement.JSONEntitlement in project OpenAM by OpenRock.
the class RestTest method getDecisionsTest.
@Test
public void getDecisionsTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resources", RESOURCE_NAME + "/index.html");
params.add("action", "GET");
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
String json = decisionsClient.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.getDecisionsTest() failed, status code not 200");
}
JSONObject jbody = jo.optJSONObject("body");
if (jbody == null) {
throw new Exception("RESTTest.getDecisionsTest() failed, body element is null");
}
JSONArray results = jbody.optJSONArray("results");
if (results == null) {
throw new Exception("RESTTest.getDecisionsTest() failed, results array is null");
}
if (results.length() < 1) {
throw new Exception("RESTTest.getDecisionsTest() failed, results array is empty");
}
JSONEntitlement ent = new JSONEntitlement(results.getJSONObject(0));
boolean result = ent.getActionValue("GET");
if (!result) {
throw new Exception("RESTTest.getDecisionsTest() failed");
}
}
Aggregations