use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintDescription.
@Test
public void shouldPrintDescription() throws Exception {
// Given
Privilege policy = new StubPrivilege();
String description = "a test description";
policy.setDescription(description);
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get("description").asString()).isEqualTo(description);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldNotAllowSettingLastModifiedBy.
@Test
public void shouldNotAllowSettingLastModifiedBy() throws Exception {
// Given
JsonValue content = buildJson(field("lastModifiedBy", "Little Bobby"));
// When
Privilege result = parser.parsePolicy(POLICY_NAME, content);
// Then
assertThat(result.getLastModifiedBy()).isNull();
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PrivilegeRestTest method getAndPut.
@Test(dependsOnMethods = "search")
public void getAndPut() throws Exception {
String result = webClient.path(PRIVILEGE_NAME).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
JSONObject jbody = parseResult(result);
String jsonStr = jbody.getString(PrivilegeResource.RESULT);
Privilege privilege = Privilege.getNewInstance(new JSONObject(jsonStr));
privilege.setDescription("desciption1");
Form form = new Form();
form.add("privilege.json", privilege.toMinimalJSONObject());
result = webClient.path(PRIVILEGE_NAME).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).put(String.class, form);
//OK
validateResult(result, 200, "OK");
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class MultipleResourceRestTest method setup.
@BeforeClass
public void setup() throws Exception {
PrivilegeManager pm = PrivilegeManager.getInstance(REALM, adminSubject);
{
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME + "1");
Map<String, Boolean> actions = new HashMap<String, Boolean>();
actions.put("GET", true);
Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/*", actions);
privilege.setEntitlement(entitlement);
EntitlementSubject sbj = new AuthenticatedUsers();
privilege.setSubject(sbj);
pm.add(privilege);
}
{
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME + "2");
Map<String, Boolean> actions = new HashMap<String, Boolean>();
actions.put("GET", false);
Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/index.html", actions);
privilege.setEntitlement(entitlement);
EntitlementSubject sbj = new AuthenticatedUsers();
privilege.setSubject(sbj);
pm.add(privilege);
}
String tokenId = adminToken.getTokenID().toString();
hashedTokenId = Hash.hash(tokenId);
tokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + tokenId;
String cookieValue = tokenId;
if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
cookieValue = URLEncoder.encode(tokenId, "UTF-8");
}
cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
user = IdRepoUtils.createUser(REALM, "MultipleResourceRestTestUser");
decisionsClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/decisions");
entitlementsClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/entitlements");
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyConditionUpgraderTest method shouldMigratePolicyWithNotEnvironmentCondition.
@Test
public void shouldMigratePolicyWithNotEnvironmentCondition() throws EntitlementException, UpgradeException {
//Given
Privilege policy = mock(Privilege.class);
NotCondition notCondition = mock(NotCondition.class);
Set<EntitlementCondition> notConditions = new HashSet<EntitlementCondition>();
PolicyCondition condition = mock(PolicyCondition.class);
notConditions.add(condition);
EntitlementCondition migratedCondition = mock(EntitlementCondition.class);
given(policy.getCondition()).willReturn(notCondition);
given(notCondition.getEConditions()).willReturn(notConditions);
given(condition.getClassName()).willReturn("CONDITION_CLASS_NAME");
given(conditionUpgradeMap.migrateEnvironmentCondition(eq("CONDITION_CLASS_NAME"), eq(condition), Matchers.<MigrationReport>anyObject())).willReturn(migratedCondition);
//When
conditionUpgrader.dryRunPolicyUpgrade(policy);
//Then
ArgumentCaptor<Set> conditionCaptor = ArgumentCaptor.forClass(Set.class);
verify(notCondition).setEConditions(conditionCaptor.capture());
assertThat(conditionCaptor.getValue()).hasSize(1).contains(migratedCondition);
verify(policy, never()).setSubject(Matchers.<EntitlementSubject>anyObject());
verify(policy, never()).setCondition(Matchers.<EntitlementCondition>anyObject());
}
Aggregations