Search in sources :

Example 1 with ApplicationType

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

the class ShowApplication method displayAttrs.

private void displayAttrs(IOutput writer, Application appl) {
    ApplicationType applType = appl.getApplicationType();
    writer.printlnMessage(ATTR_APPLICATIONTYPE + '=' + applType.getName());
    String description = appl.getDescription();
    if (description == null) {
        description = "";
    }
    writer.printlnMessage(ATTR_DESCRIPTION + "=" + description);
    writer.printlnMessage(ATTR_CREATED_BY + "=" + appl.getCreatedBy());
    writer.printlnMessage(ATTR_CREATION_DATE + "=" + appl.getCreationDate());
    writer.printlnMessage(ATTR_LAST_MODIFIED_BY + "=" + appl.getLastModifiedBy());
    writer.printlnMessage(ATTR_LAST_MODIFICATION_DATE + "=" + appl.getLastModifiedDate());
    displayAttributes(writer, ATTR_SUBJECT_ATTRIBUTE_NAMES, appl.getAttributeNames());
    displayAttributes(writer, ATTR_RESOURCE_TYPE_UUIDS, appl.getResourceTypeUuids());
    displayAttributes(writer, ATTR_CONDITIONS, appl.getConditions());
    displayAttributes(writer, ATTR_SUBJECTS, appl.getSubjects());
    displayClassName(writer, ATTR_ENTITLEMENT_COMBINER, appl.getEntitlementCombinerClass());
    displayClassName(writer, ATTR_RESOURCE_COMPARATOR, appl.getResourceComparatorClass());
    displayClassName(writer, ATTR_SAVE_INDEX, appl.getSaveIndexClass());
    displayClassName(writer, ATTR_SEARCH_INDEX, appl.getSearchIndexClass());
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType)

Example 2 with ApplicationType

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

the class ApplicationImpl method getApplicationType.

protected ApplicationType getApplicationType(String name) throws CLIException {
    ApplicationType applType = ApplicationTypeManager.getAppplicationType(getAdminSubject(), name);
    if (applType == null) {
        String msg = getResourceString("application-type-invalid");
        Object[] param = { name };
        throw new CLIException(MessageFormat.format(msg, param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    return applType;
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) CLIException(com.sun.identity.cli.CLIException)

Example 3 with ApplicationType

use of com.sun.identity.entitlement.ApplicationType 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 ApplicationType

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

the class CreateApplicationType 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 appTypeName = getStringOptionValue(PARAM_APPL_TYPE_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 = { appTypeName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_APPLICATION_TYPE", params);
    try {
        Map<String, Boolean> actions = getActions(attributeValues);
        Class searchIndex = getClassAttribute(ATTR_SEARCH_INDEX, attributeValues);
        Class saveIndex = getClassAttribute(ATTR_SAVE_INDEX, attributeValues);
        Class resourceComp = getClassAttribute(ATTR_RESOURCE_COMPARATOR, attributeValues);
        ApplicationType applType = new ApplicationType(appTypeName, actions, searchIndex, saveIndex, resourceComp);
        ApplicationTypeManager.saveApplicationType(getAdminSubject(), applType);
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-application-type-succeeded"), (Object[]) params));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_CREATE_APPLICATION_TYPE", params);
    } catch (ClassCastException e) {
        String[] paramExs = { appTypeName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (EntitlementException e) {
        String[] paramExs = { appTypeName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (InstantiationException e) {
        String[] paramExs = { appTypeName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IllegalAccessException e) {
        String[] paramExs = { appTypeName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (CLIException e) {
        String[] paramExs = { appTypeName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_TYPE", paramExs);
        throw e;
    }
}
Also used : Set(java.util.Set) ApplicationType(com.sun.identity.entitlement.ApplicationType) EntitlementException(com.sun.identity.entitlement.EntitlementException) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

Example 5 with ApplicationType

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

the class ShowApplicationType 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 appTypeName = getStringOptionValue(PARAM_APPL_TYPE_NAME);
    String[] params = { appTypeName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_APPLICATION_TYPE", params);
    ApplicationType applType = ApplicationTypeManager.getAppplicationType(getAdminSubject(), appTypeName);
    IOutput writer = getOutputWriter();
    if (applType == null) {
        Object[] param = { appTypeName };
        writer.printlnMessage(MessageFormat.format(getResourceString("show-application-type-not-found"), param));
    } else {
        displayAttrs(writer, applType);
    }
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_SHOW_APPLICATION_TYPE", params);
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) IOutput(com.sun.identity.cli.IOutput)

Aggregations

ApplicationType (com.sun.identity.entitlement.ApplicationType)20 EntitlementException (com.sun.identity.entitlement.EntitlementException)6 Set (java.util.Set)6 Application (com.sun.identity.entitlement.Application)5 HashSet (java.util.HashSet)5 Subject (javax.security.auth.Subject)5 CLIException (com.sun.identity.cli.CLIException)3 List (java.util.List)3 ResourceResponse (org.forgerock.json.resource.ResourceResponse)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)2 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)2 ApplicationTypeWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper)2 EntitlementUtils.resourceTypeFromMap (org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap)2 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)2 Test (org.testng.annotations.Test)2 Node (org.w3c.dom.Node)2 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1