Search in sources :

Example 71 with EntitlementException

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);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test)

Example 72 with EntitlementException

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);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 73 with EntitlementException

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);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 74 with EntitlementException

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");
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) PrivilegeIndexStore(com.sun.identity.entitlement.PrivilegeIndexStore) IPrivilege(com.sun.identity.entitlement.IPrivilege) ResourceSearchIndexes(com.sun.identity.entitlement.ResourceSearchIndexes) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 75 with EntitlementException

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);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) JSONException(org.json.JSONException) EntitlementListener(com.sun.identity.entitlement.EntitlementListener) Subject(javax.security.auth.Subject) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

EntitlementException (com.sun.identity.entitlement.EntitlementException)221 Subject (javax.security.auth.Subject)68 HashSet (java.util.HashSet)58 SSOException (com.iplanet.sso.SSOException)51 Set (java.util.Set)50 SSOToken (com.iplanet.sso.SSOToken)47 SMSException (com.sun.identity.sm.SMSException)45 Application (com.sun.identity.entitlement.Application)37 Test (org.testng.annotations.Test)37 HashMap (java.util.HashMap)34 ResourceException (org.forgerock.json.resource.ResourceException)33 ResourceResponse (org.forgerock.json.resource.ResourceResponse)32 Privilege (com.sun.identity.entitlement.Privilege)22 JsonValue (org.forgerock.json.JsonValue)19 JSONException (org.json.JSONException)19 CLIException (com.sun.identity.cli.CLIException)18 ApplicationPrivilegeManager (com.sun.identity.entitlement.ApplicationPrivilegeManager)17 ServiceConfig (com.sun.identity.sm.ServiceConfig)17 ResourceType (org.forgerock.openam.entitlement.ResourceType)17 PolicyException (com.sun.identity.policy.PolicyException)16