Search in sources :

Example 66 with EntitlementException

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

the class PolicyEvaluator method isAllowedE.

private boolean isAllowedE(SSOToken token, String resourceName, String actionName, Map envParameters) throws SSOException, PolicyException {
    if ((envParameters == null) || envParameters.isEmpty()) {
        envParameters = new HashMap();
    }
    padEnvParameters(token, resourceName, actionName, envParameters);
    ActionSchema schema = serviceType.getActionSchema(actionName);
    if (!AttributeSchema.Syntax.BOOLEAN.equals(schema.getSyntax())) {
        String[] objs = { actionName };
        throw new PolicyException(ResBundleUtils.rbName, "action_does_not_have_boolean_syntax", objs, null);
    }
    HashSet actions = new HashSet(2);
    actions.add(actionName);
    SSOToken adminSSOToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    try {
        Subject adminSubject = SubjectUtils.createSubject(token);
        Entitlement entitlement = new Entitlement(serviceTypeName, resourceName, actions);
        entitlement.canonicalizeResources(adminSubject, realm);
        Evaluator eval = new Evaluator(adminSubject, applicationName);
        return eval.hasEntitlement(realm, SubjectUtils.createSubject(token), entitlement, envParameters);
    } catch (EntitlementException e) {
        throw new PolicyException(e);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) Entitlement(com.sun.identity.entitlement.Entitlement) Evaluator(com.sun.identity.entitlement.Evaluator) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet)

Example 67 with EntitlementException

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

the class PolicyEvaluator method padEnvParameters.

private void padEnvParameters(SSOToken token, String resourceName, String actionName, Map envParameters) throws PolicyException, SSOException {
    if ((resourceName == null) || (resourceName.trim().length() == 0)) {
        resourceName = Rule.EMPTY_RESOURCE_NAME;
    }
    Set originalResourceNames = new HashSet(2);
    originalResourceNames.add(resourceName);
    String realmName = LDAPUtils.isDN(realm) ? DNMapper.orgNameToRealmName(realm) : realm;
    try {
        Application appl = ApplicationManager.getApplication(PolicyConstants.SUPER_ADMIN_SUBJECT, realmName, applicationName);
        resourceName = appl.getResourceComparator().canonicalize(resourceName);
    } catch (EntitlementException e) {
        throw new PolicyException(e);
    }
    //Add request resourceName and request actionNames to the envParameters
    //so that Condition(s)/ResponseProvider(s) can use them if necessary
    Set resourceNames = new HashSet(2);
    resourceNames.add(resourceName);
    Set actions = new HashSet();
    if (actionName != null) {
        actions.add(actionName);
    } else {
        Set actionNames = serviceType.getActionNames();
        if (actionNames != null) {
            actions.addAll(actionNames);
        }
    }
    envParameters.put(SUN_AM_REQUESTED_RESOURCE, resourceNames);
    envParameters.put(SUN_AM_ORIGINAL_REQUESTED_RESOURCE, originalResourceNames);
    envParameters.put(SUN_AM_REQUESTED_ACTIONS, actions);
    envParameters.put(REALM_DN, asSet(policyManager.getOrganizationDN()));
    // Fix for OPENAM-811
    String userid = null;
    Principal principal = token.getPrincipal();
    if (principal != null) {
        userid = principal.getName();
    }
    if ((userid != null) && (userid.length() != 0)) {
        HashSet<String> set = new HashSet<String>();
        set.add(userid);
        // Required by the AMIdentityMembershipCondition
        envParameters.put(Condition.INVOCATOR_PRINCIPAL_UUID, set);
    } else {
        if (DEBUG.messageEnabled()) {
            DEBUG.message("PolicyEvaluator.padEnvParameters() unable to get userid from token.");
        }
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) HashSet(java.util.HashSet) Set(java.util.Set) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) Application(com.sun.identity.entitlement.Application) Principal(java.security.Principal) HashSet(java.util.HashSet)

Example 68 with EntitlementException

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

the class PolicyResourceEvaluationTest method shouldHandleEntitlementExceptions.

@Test
public void shouldHandleEntitlementExceptions() throws EntitlementException {
    // Given...
    given(request.getAction()).willReturn("evaluate");
    Context context = buildContextStructure("/abc");
    EntitlementException eE = new EntitlementException(EntitlementException.INVALID_VALUE);
    given(requestFactory.buildRequest(PolicyAction.EVALUATE, context, request)).willThrow(eE);
    given(request.getRequestType()).willReturn(RequestType.ACTION);
    // When...
    Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
    // Then...
    verify(request).getAction();
    verify(requestFactory).buildRequest(PolicyAction.EVALUATE, context, request);
    verify(request).getRequestType();
    assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
    verifyNoMoreInteractions(request, requestFactory, policyRequest, factory, evaluator, parser);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 69 with EntitlementException

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

the class PolicyResourceTest method shouldRejectNullPolicyIdInDelete.

@Test
public void shouldRejectNullPolicyIdInDelete() throws Exception {
    // Given
    String id = null;
    DeleteRequest request = mock(DeleteRequest.class);
    willThrow(new EntitlementException(EntitlementException.MISSING_PRIVILEGE_NAME)).given(mockStore).delete(id);
    // When
    Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request);
    // Then
    assertThat(promise).failedWithException().isInstanceOf(BadRequestException.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 70 with EntitlementException

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

the class PolicyResourceTest method shouldReportCreatePolicyStoreErrors.

@Test
public void shouldReportCreatePolicyStoreErrors() throws Exception {
    // Given
    String id = "uniqueId";
    JsonValue json = new JsonValue("");
    CreateRequest request = mockCreateRequest(id, json);
    Privilege policy = mockPrivilege(id, 123l);
    given(mockParser.parsePolicy(id, json)).willReturn(policy);
    willThrow(new EntitlementException(EntitlementException.INVALID_APPLICATION_CLASS)).given(mockStore).create(policy);
    // When
    Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
    // Then
    assertThat(promise).failedWithException().isInstanceOf(InternalServerErrorException.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) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

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