use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyResource method queryCollection.
/**
* {@inheritDoc}
*/
@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
try {
List<ResourceResponse> results = new ArrayList<>();
for (Privilege policy : policyStoreProvider.getPolicyStore(context).query(request)) {
results.add(policyResource(policy));
}
QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
return QueryResponsePresentation.perform(handler, request, results);
} catch (EntitlementException ex) {
DEBUG.error("PolicyResource :: QUERY : Error querying policy collection.", ex);
return resourceErrorHandler.handleError(context, request, ex).asPromise();
} catch (IllegalArgumentException ex) {
DEBUG.error("PolicyResource :: QUERY : Error querying policy collection due to bad request.", ex);
return new BadRequestException(ex.getMessage()).asPromise();
}
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldAcceptConsistentPolicyNamesFromURLandJSON.
@Test
public void shouldAcceptConsistentPolicyNamesFromURLandJSON() throws Exception {
// Given
String policyName = "policyName";
// Policy name can be specified in *both* URL and JSON so long as it is equal
JsonValue json = JsonValue.json(JsonValue.object(JsonValue.field("name", policyName)));
CreateRequest request = mockCreateRequest(policyName, json);
Privilege policy = mockPrivilege(policyName, 123l);
given(mockParser.parsePolicy(policyName, json)).willReturn(policy);
// When
policyResource.createInstance(mockServerContext, request);
// Then
verify(mockParser).parsePolicy(policyName, json);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReadPoliciesFromStore.
@Test
public void shouldReadPoliciesFromStore() throws Exception {
// Given
String id = "testPolicy";
long lastModified = 1234l;
Privilege policy = mockPrivilege(id, lastModified);
ReadRequest request = mock(ReadRequest.class);
given(mockStore.read(id)).willReturn(policy);
JsonValue content = new JsonValue("content");
given(mockParser.printPolicy(policy)).willReturn(content);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.readInstance(mockServerContext, id, request);
// Then
assertThat(promise).succeeded().withId().isNotNull();
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PrivilegePolicyStoreTest method shouldDelegateReadsToPrivilegeManager.
@Test
public void shouldDelegateReadsToPrivilegeManager() throws Exception {
// Given
String id = "testPolicy";
Privilege policy = new StubPrivilege();
given(mockManager.findByName(id)).willReturn(policy);
// When
Privilege response = testStore.read(id);
// Then
verify(mockManager).findByName(id);
assertThat(response).isSameAs(policy);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldUpdatePoliciesInStore.
@Test
public void shouldUpdatePoliciesInStore() throws Exception {
// Given
String id = "testPolicy";
long lastModified = 1234l;
UpdateRequest request = mock(UpdateRequest.class);
JsonValue content = new JsonValue("content");
given(request.getContent()).willReturn(content);
Privilege privilege = mockPrivilege(id, lastModified);
given(mockParser.parsePolicy(id, content)).willReturn(privilege);
given(mockStore.update(id, privilege)).willReturn(privilege);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.updateInstance(mockServerContext, id, request);
// Then
assertThat(promise).succeeded().withId().isNotNull();
}
Aggregations