Search in sources :

Example 11 with ApplicationType

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

the class EntitlementService method createApplication.

private Application createApplication(ServiceConfig conf, String appName) throws IllegalAccessException, EntitlementException, InstantiationException, SMSException, SSOException {
    final Map<String, Set<String>> data = conf.getSubConfig(appName).getAttributes();
    final ApplicationType applicationType = ApplicationTypeManager.getAppplicationType(getAdminSubject(), EntitlementUtils.getAttribute(data, EntitlementUtils.APPLICATION_TYPE));
    return EntitlementUtils.createApplication(applicationType, appName, data);
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) HashSet(java.util.HashSet) Set(java.util.Set)

Example 12 with ApplicationType

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

the class CreateApplication 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 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);
    ApplicationType applicationType = getApplicationType(appTypeName);
    String[] params = { realm, appName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_APPLICATION", params);
    try {
        Application appl = ApplicationManager.newApplication(appName, applicationType);
        setApplicationAttributes(appl, attributeValues, true);
        ApplicationManager.saveApplication(getAdminSubject(), realm, appl);
        String[] param = { appName };
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-application-succeeded"), (Object[]) param));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_CREATE_APPLICATION", params);
    } catch (EntitlementException e) {
        String[] paramExs = { realm, appName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_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_CREATE_APPLICATION", paramExs);
        throw e;
    }
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) 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)

Example 13 with ApplicationType

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

the class DeleteApplicationTypes 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);
    List<String> appTypeNames = (List) rc.getOption(PARAM_APPL_TYPE_NAMES);
    String[] param = { appTypeNames.toString() };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_APPLICATION_TYPES", param);
    Subject adminSubject = getAdminSubject();
    try {
        for (String appTypeName : appTypeNames) {
            // Check it exists before deleting
            ApplicationType applType = ApplicationTypeManager.getAppplicationType(adminSubject, appTypeName);
            if (applType != null) {
                ApplicationTypeManager.removeApplicationType(adminSubject, appTypeName);
            }
        }
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("delete-application-types-succeeded"), (Object[]) param));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_APPLICATION_TYPES", param);
    } catch (EntitlementException e) {
        String[] params = { appTypeNames.toString(), e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_DELETE_APPLICATION_TYPES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) EntitlementException(com.sun.identity.entitlement.EntitlementException) List(java.util.List) Subject(javax.security.auth.Subject)

Example 14 with ApplicationType

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

the class EntitlementService method getApplicationTypes.

/**
     * Returns a set of registered application type.
     *
     * @return A set of registered application type.
     */
public Set<ApplicationType> getApplicationTypes() {
    Set<ApplicationType> results = new HashSet<ApplicationType>();
    try {
        SSOToken token = getSSOToken();
        if (token == null) {
            PolicyConstants.DEBUG.error("EntitlementService.getApplicationTypes : " + "admin sso token is absent");
        } else {
            ServiceConfig conf = getApplicationTypeCollectionConfig(token);
            Set<String> names = conf.getSubConfigNames();
            for (String name : names) {
                ServiceConfig appType = conf.getSubConfig(name);
                Map<String, Set<String>> data = appType.getAttributes();
                results.add(EntitlementUtils.createApplicationType(name, data));
            }
        }
    } catch (InstantiationException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationTypes", ex);
    } catch (IllegalAccessException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationTypes", ex);
    } catch (SMSException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationTypes", ex);
    } catch (SSOException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationTypes", ex);
    }
    return results;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ApplicationType(com.sun.identity.entitlement.ApplicationType) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashSet(java.util.HashSet)

Example 15 with ApplicationType

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

the class EntitlementUtils method createApplicationType.

/**
     * Constructs an {@link ApplicationType} object based on the provided information.
     *
     * @param name The name of the application type.
     * @param data The configuration settings for the application type.
     * @return An {@link ApplicationType} object corresponding to the provided details.
     * @throws InstantiationException If the class settings cannot be instantiated.
     * @throws IllegalAccessException If the class settings cannot be instantiated.
     */
public static ApplicationType createApplicationType(String name, Map<String, Set<String>> data) throws InstantiationException, IllegalAccessException {
    Map<String, Boolean> actions = getActions(data);
    String saveIndexImpl = getAttribute(data, CONFIG_SAVE_INDEX_IMPL);
    Class saveIndex = ApplicationTypeManager.getSaveIndex(saveIndexImpl);
    String searchIndexImpl = getAttribute(data, CONFIG_SEARCH_INDEX_IMPL);
    Class searchIndex = ApplicationTypeManager.getSearchIndex(searchIndexImpl);
    String resourceComp = getAttribute(data, CONFIG_RESOURCE_COMP_IMPL);
    Class resComp = ApplicationTypeManager.getResourceComparator(resourceComp);
    String applicationClassName = getAttribute(data, APPLICATION_CLASSNAME);
    ApplicationType appType = new ApplicationType(name, actions, searchIndex, saveIndex, resComp);
    if (applicationClassName != null) {
        appType.setApplicationClassName(applicationClassName);
    }
    return appType;
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType)

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