use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReportMissingPoliciesInDelete.
@Test
public void shouldReportMissingPoliciesInDelete() throws Exception {
// Given
String id = "unknown";
DeleteRequest request = mock(DeleteRequest.class);
willThrow(new EntitlementException(EntitlementException.NO_SUCH_POLICY)).given(mockStore).delete(id);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class);
}
use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method readShouldHandleServiceException.
@Test
public void readShouldHandleServiceException() throws Exception {
//given
ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
ReadRequest readRequest = mock(ReadRequest.class);
Throwable t = new EntitlementException(EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS);
when(resourceTypeService.getResourceType(any(Subject.class), anyString(), anyString())).thenThrow(t);
//when
Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.readInstance(mockServerContext, createdResource.getId(), readRequest);
//then
assertResourcePromiseFailedWithCodes(promise, ResourceException.CONFLICT, EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS);
}
use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReportBadCreateRequests.
@Test
public void shouldReportBadCreateRequests() throws Exception {
// Given
String id = "uniqueId";
JsonValue json = new JsonValue("");
CreateRequest request = mockCreateRequest(id, json);
given(mockParser.parsePolicy(id, json)).willThrow(new EntitlementException(EntitlementException.INVALID_JSON, "Mock error message"));
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class PolicyIndexTest method storeAndRetrieve.
@Test
public void storeAndRetrieve() throws SSOException, PolicyException, EntitlementException, Exception {
SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
PolicyManager pm = new PolicyManager(adminToken, "/");
Set<String> hostIndexes = new HashSet<String>();
Set<String> pathIndexes = new HashSet<String>();
Set<String> parentPathIndexes = new HashSet<String>();
hostIndexes.add("http://www.sun.com");
pathIndexes.add("/private");
parentPathIndexes.add("/");
ResourceSearchIndexes indexes = new ResourceSearchIndexes(hostIndexes, pathIndexes, parentPathIndexes);
PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(SubjectUtils.createSubject(adminToken), "/");
for (Iterator<IPrivilege> i = pis.search("/", indexes, Collections.EMPTY_SET, false); i.hasNext(); ) {
IPrivilege eval = i.next();
if (!(eval instanceof Privilege)) {
throw new Exception("incorrect deserialized policy, wrong type");
}
Privilege p = (Privilege) eval;
if (!p.getEntitlement().getResourceName().equals(URL_RESOURCE)) {
throw new Exception("incorrect deserialized policy");
}
}
}
use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class ListenerResource method addListener.
@POST
@Produces("application/json")
public String addListener(@Context HttpHeaders headers, @Context HttpServletRequest request, @FormParam("url") String url, @FormParam("resources") List<String> resources, @FormParam("application") @DefaultValue("iPlanetAMWebAgentService") String application) {
try {
Subject caller = getCaller(request);
EntitlementListener l = new EntitlementListener(url, application, resources);
ListenerManager.getInstance().addListener(caller, l);
return createResponseJSONString(201, headers, "Created");
} catch (RestException e) {
throw getWebApplicationException(headers, e, MimeType.JSON);
} catch (JSONException e) {
throw getWebApplicationException(e, MimeType.JSON);
} catch (EntitlementException e) {
throw getWebApplicationException(headers, e, MimeType.JSON);
}
}
Aggregations