Search in sources :

Example 1 with Application

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

the class SetApplication method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String appName = getStringOptionValue(PARAM_APPL_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    String[] params = { realm, appName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_APPLICATION", params);
    Subject adminSubject = getAdminSubject();
    try {
        Application appl = ApplicationManager.getApplication(adminSubject, realm, appName);
        Object[] param = { appName };
        if (appl == null) {
            throw new CLIException(MessageFormat.format(getResourceString("set-application-not-found"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        setApplicationAttributes(appl, attributeValues, false);
        ApplicationManager.saveApplication(getAdminSubject(), realm, appl);
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("set-application-modified"), param));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_SET_APPLICATION", params);
    } catch (EntitlementException e) {
        String[] paramExs = { realm, appName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_SET_APPLICATION", paramExs);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (CLIException e) {
        String[] paramExs = { realm, appName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_SET_APPLICATION", paramExs);
        throw e;
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) Set(java.util.Set) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject)

Example 2 with Application

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

the class ApplicationPrivilegeBase method getApplicationResourcesMap.

protected Map<String, Set<String>> getApplicationResourcesMap(RequestContext rc, String realm) throws CLIException, EntitlementException {
    String appName = getStringOptionValue(PARAM_APPL_NAME);
    Subject subject = SubjectUtils.createSubject(getAdminSSOToken());
    Application application = ApplicationManager.getApplication(subject, realm, appName);
    if (application == null) {
        String[] param = { appName };
        throw new CLIException(MessageFormat.format(getResourceString("privilege-application-application-invalid"), (Object[]) param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    Set<String> delResources = new HashSet<String>();
    List<String> resources = rc.getOption(PARAM_RESOURCES);
    // if resources is not provided, delegate all resources
    if ((resources == null) || resources.isEmpty()) {
        delResources.addAll(getAllBaseResources(subject, realm, application));
    } else {
        delResources.addAll(resources);
    }
    Map<String, Set<String>> map = new HashMap<String, Set<String>>();
    map.put(appName, delResources);
    return map;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CLIException(com.sun.identity.cli.CLIException) Application(com.sun.identity.entitlement.Application) OpenSSOGroupSubject(com.sun.identity.entitlement.opensso.OpenSSOGroupSubject) Subject(javax.security.auth.Subject) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) HashSet(java.util.HashSet)

Example 3 with Application

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

the class ConfigureOAuth2 method getUrlResourceTypeId.

private String getUrlResourceTypeId(Subject adminSubject, String realm) throws EntitlementException, WorkflowException {
    Application application = ApplicationManager.getApplication(adminSubject, realm, POLICY_APPLICATION_NAME);
    if (application == null) {
        ApplicationType applicationType = ApplicationTypeManager.getAppplicationType(adminSubject, ApplicationTypeManager.URL_APPLICATION_TYPE_NAME);
        application = ApplicationManager.newApplication(POLICY_APPLICATION_NAME, applicationType);
    }
    Set<String> resourceTypeIds = application.getResourceTypeUuids();
    ResourceTypeService resourceTypeService = InjectorHolder.getInstance(ResourceTypeService.class);
    for (String id : resourceTypeIds) {
        ResourceType resourceType = resourceTypeService.getResourceType(adminSubject, realm, id);
        if (POLICY_RESOURCE_TYPE_NAME.equalsIgnoreCase(resourceType.getName())) {
            return id;
        }
    }
    QueryFilter<SmsAttribute> name = equalTo(SmsAttribute.newSearchableInstance("name"), POLICY_RESOURCE_TYPE_NAME);
    Set<ResourceType> types = resourceTypeService.getResourceTypes(name, adminSubject, realm);
    ResourceType resourceType;
    if (types == null || types.isEmpty()) {
        resourceType = ResourceType.builder().addPatterns(asSet("*://*:*/*/authorize?*")).addActions(new ImmutableMap.Builder<String, Boolean>().put("GET", true).put("POST", true).build()).setName(POLICY_RESOURCE_TYPE_NAME).setUUID(UUID.randomUUID().toString()).build();
        resourceType = resourceTypeService.saveResourceType(adminSubject, realm, resourceType);
    } else {
        resourceType = types.iterator().next();
    }
    application.addAllResourceTypeUuids(asSet(resourceType.getUUID()));
    application.setEntitlementCombiner(DenyOverride.class);
    ApplicationManager.saveApplication(adminSubject, realm, application);
    return resourceType.getUUID();
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) SmsAttribute(org.forgerock.openam.entitlement.configuration.SmsAttribute) ResourceType(org.forgerock.openam.entitlement.ResourceType) ResourceTypeService(org.forgerock.openam.entitlement.service.ResourceTypeService) Application(com.sun.identity.entitlement.Application)

Example 4 with Application

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

the class PolicyV1FilterTest method resourceTypeAssociationOnUpdate.

/**
     * Verifies that the appropriate resource type is associated with the policy being updated.
     */
@Test
public void resourceTypeAssociationOnUpdate() throws Exception {
    // Given
    given(contextHelper.getRealm(context)).willReturn("/abc");
    given(contextHelper.getSubject(context)).willReturn(subject);
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    JsonValue jsonValue = json(object(field("applicationName", "testApp")));
    given(updateRequest.getContent()).willReturn(jsonValue);
    given(applicationServiceFactory.create(subject, "/abc")).willReturn(applicationService);
    Application application = mock(Application.class);
    given(applicationService.getApplication("testApp")).willReturn(application);
    Set<String> resourceTypeUUIDs = new HashSet<>(CollectionUtils.asSet("abc-def-hij"));
    given(application.getResourceTypeUuids()).willReturn(resourceTypeUUIDs);
    // When
    Promise<ResourceResponse, ResourceException> promise = filter.filterUpdate(context, updateRequest, requestHandler);
    // Then
    assertThat(promise).succeeded();
    verify(applicationServiceFactory).create(subject, "/abc");
    verify(applicationService).getApplication("testApp");
    assertThat(jsonValue.get("resourceTypeUuid").asString()).isEqualTo("abc-def-hij");
    assertThat(promise.get().getContent().contains("resourceTypeUuid")).isFalse();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Application(com.sun.identity.entitlement.Application) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with Application

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

the class PrivilegeUtils method entitlementToRule.

private static Set<Rule> entitlementToRule(String realm, Entitlement entitlement) throws PolicyException, SSOException, EntitlementException {
    Set<Rule> rules = new HashSet<Rule>();
    String appName = entitlement.getApplicationName();
    String realmName = LDAPUtils.isDN(realm) ? DNMapper.orgNameToRealmName(realm) : realm;
    Application application = ApplicationManager.getApplication(PolicyConstants.SUPER_ADMIN_SUBJECT, realmName, appName);
    if (application == null) {
        Object[] params = { appName, realm };
        throw new EntitlementException(105, params);
    }
    String serviceName = application.getApplicationType().getName();
    Set<String> resourceNames = entitlement.getResourceNames();
    Map<String, Boolean> actionValues = entitlement.getActionValues();
    Map av = pravToPav(actionValues, serviceName);
    if (resourceNames != null) {
        String entName = entitlement.getName();
        if (entName == null) {
            entName = "entitlement";
        }
        Rule rule = new Rule(entName, serviceName, null, av);
        rule.setResourceNames(resourceNames);
        rule.setApplicationName(appName);
        rules.add(rule);
    }
    return rules;
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) Rule(com.sun.identity.policy.Rule) Application(com.sun.identity.entitlement.Application) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

Application (com.sun.identity.entitlement.Application)65 EntitlementException (com.sun.identity.entitlement.EntitlementException)37 Subject (javax.security.auth.Subject)29 ResourceResponse (org.forgerock.json.resource.ResourceResponse)22 Test (org.testng.annotations.Test)22 HashSet (java.util.HashSet)20 JsonValue (org.forgerock.json.JsonValue)18 Set (java.util.Set)16 ResourceException (org.forgerock.json.resource.ResourceException)16 RealmContext (org.forgerock.openam.rest.RealmContext)16 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)16 HashMap (java.util.HashMap)15 ClientContext (org.forgerock.services.context.ClientContext)13 Context (org.forgerock.services.context.Context)13 Matchers.anyString (org.mockito.Matchers.anyString)13 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)10 UpdateRequest (org.forgerock.json.resource.UpdateRequest)9 ApplicationWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper)9 Map (java.util.Map)8 BadRequestException (org.forgerock.json.resource.BadRequestException)7