Search in sources :

Example 71 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PolicyResourceTest method shouldCreatePoliciesInStore.

@Test
public void shouldCreatePoliciesInStore() throws Exception {
    // Given
    String id = "uniqueId";
    long lastModified = 12345l;
    JsonValue json = new JsonValue("");
    CreateRequest request = mockCreateRequest(id, json);
    Privilege policy = mockPrivilege(id, lastModified);
    JsonValue result = new JsonValue("result");
    given(mockParser.parsePolicy(id, json)).willReturn(policy);
    given(mockParser.printPolicy(policy)).willReturn(result);
    // When
    Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
    // Then
    verify(mockStore).create(policy);
    assertThat(promise).succeeded().withId().isNotNull();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 72 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PolicyResourceTest method shouldRejectMismatchedPolicyName.

@Test
public void shouldRejectMismatchedPolicyName() throws Exception {
    // Given
    String policyName = "policyName";
    String differentPolicyName = "Different!";
    JsonValue json = JsonValue.json(JsonValue.object(JsonValue.field("name", policyName)));
    CreateRequest request = mockCreateRequest(differentPolicyName, json);
    Privilege policy = mockPrivilege(policyName, 123l);
    given(mockParser.parsePolicy(differentPolicyName, json)).willReturn(policy);
    // When
    Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
    // Then
    assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 73 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PolicyResourceTest method mockPrivilege.

private Privilege mockPrivilege(String name, long lastModified) throws EntitlementException {
    Privilege mock = new StubPrivilege();
    mock.setName(name);
    mock.setLastModifiedDate(lastModified);
    return mock;
}
Also used : Privilege(com.sun.identity.entitlement.Privilege)

Example 74 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class JsonPolicyParserTest method shouldParseResourceAttributes.

@Test
public void shouldParseResourceAttributes() throws Exception {
    // Given
    List<String> values = Arrays.asList("one", "two", "three");
    JsonValue content = buildJson(field("resourceAttributes", Arrays.asList(object(field("type", "Static"), field("propertyName", "test"), field("propertyValues", values)))));
    // Given
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getResourceAttributes()).hasSize(1);
    ResourceAttribute attr = result.getResourceAttributes().iterator().next();
    assertThat(attr).isInstanceOf(StaticAttributes.class);
    assertThat(attr.getPropertyName()).isEqualTo("test");
    assertThat(attr.getPropertyValues()).containsOnly(values.toArray());
}
Also used : JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) Test(org.testng.annotations.Test)

Example 75 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class JsonPolicyParserTest method shouldNotPrintPolicyAttributes.

@Test
public void shouldNotPrintPolicyAttributes() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    policy.setEntitlement(new Entitlement());
    policy.getEntitlement().setAttributes(Collections.singletonMap("one", CollectionUtils.asSet("two")));
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    // Attributes should not appear on the policy entitlement
    assertThat(result.get("attributes").asMapOfList(String.class)).isNullOrEmpty();
}
Also used : JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Entitlement(com.sun.identity.entitlement.Entitlement) Test(org.testng.annotations.Test)

Aggregations

Privilege (com.sun.identity.entitlement.Privilege)122 Test (org.testng.annotations.Test)76 JsonValue (org.forgerock.json.JsonValue)46 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)39 HashSet (java.util.HashSet)30 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)26 EntitlementException (com.sun.identity.entitlement.EntitlementException)23 IPrivilege (com.sun.identity.entitlement.IPrivilege)23 Entitlement (com.sun.identity.entitlement.Entitlement)19 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)18 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)17 HashMap (java.util.HashMap)15 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)13 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)11 PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)10 Set (java.util.Set)9 SSOToken (com.iplanet.sso.SSOToken)8 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)8 Subject (javax.security.auth.Subject)8 ResourceResponse (org.forgerock.json.resource.ResourceResponse)8