use of com.sun.identity.entitlement.JSONEntitlement 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");
}
}
Aggregations