Search in sources :

Example 46 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class RealmAddServiceAttributes 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);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String serviceName = getStringOptionValue(IArgument.SERVICE_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);
    attributeValues = processFileAttributes(attributeValues);
    try {
        String[] params = { realm, serviceName };
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Map<String, Boolean> mapAttrType = getMultipleValueAttrs(serviceName);
        Set assignedServices = ocm.getAssignedServices(true);
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = repo.getRealmIdentity();
        Set servicesFromIdRepo = ai.getAssignedServices();
        boolean modified = false;
        if (assignedServices.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_ADD_SERVICE_ATTR_VALUES", params);
            Map origValues = ocm.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, mapAttrType, true)) {
                ocm.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_ADD_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (servicesFromIdRepo.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_ADD_SERVICE_ATTR_VALUES", params);
            Map origValues = ai.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, mapAttrType, true)) {
                ai.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_ADD_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (modified) {
            outputWriter.printlnMessage(getResourceString("realm-add-service-attributes-succeed"));
            outputWriter.printlnMessage("");
            outputWriter.printlnMessage(FormatUtils.printAttributeValues("{0}={1}", attributeValues));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("realm-add-service-attributes-not-assigned"), (Object[]) params));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmAddServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmAddServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmAddServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_ADD_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 47 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class RealmAssignService method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);
    Map<String, Set<String>> attributeValues = null;
    if ((datafile != null) || (attrValues != null)) {
        attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
        attributeValues = processFileAttributes(attributeValues);
    }
    IOutput outputWriter = getOutputWriter();
    String[] params = { realm, serviceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ASSIGN_SERVICE_TO_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set assignableServices = ocm.getAssignableServices();
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = amir.getRealmIdentity();
        Set dynAssignableServices = ai.getAssignableServices();
        if (assignableServices.contains(serviceName)) {
            ocm.assignService(serviceName, attributeValues);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
        }
        if (dynAssignableServices.contains(serviceName)) {
            ai.assignService(serviceName, attributeValues);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("assign-service-to-realm-succeed"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ASSIGN_SERVICE_TO_REALM", params);
    } catch (SSOException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IdRepoException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmAssignService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ASSIGN_SERVICE_TO_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

Example 48 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class RealmGetAssignableServices method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String[] params = { realm };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ASSIGNABLE_SERVICES_OF_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set serviceNames = ocm.getAssignableServices();
        Set dynamicServiceNames = getAssignableDynamicServiceNames(adminSSOToken, realm);
        if ((dynamicServiceNames != null) && !dynamicServiceNames.isEmpty()) {
            if ((serviceNames != null) && !serviceNames.isEmpty()) {
                serviceNames.addAll(dynamicServiceNames);
            } else {
                serviceNames = dynamicServiceNames;
            }
        }
        IOutput outputWriter = getOutputWriter();
        if ((serviceNames != null) && !serviceNames.isEmpty()) {
            String msg = getResourceString("realm-getassignable-services-result");
            outputWriter.printlnMessage(FormatUtils.printServiceNames(serviceNames, msg, adminSSOToken));
            outputWriter.printlnMessage(getResourceString("realm-getassignable-services-succeed"));
        } else {
            outputWriter.printlnMessage(getResourceString("realm-getassignable-services-no-services"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ASSIGNABLE_SERVICES_OF_REALM", params);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignableServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignableServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignableServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 49 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class RealmGetAssignedServices method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    boolean incMandatory = isOptionSet(IArgument.MANDATORY);
    String strMandatory = (incMandatory) ? "include mandatory" : "exclude mandatory";
    String[] params = { realm, strMandatory };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ASSIGNED_SERVICES_OF_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set serviceNames = ocm.getAssignedServices(incMandatory);
        Set dynamicServiceNames = getAssignedDynamicServiceNames(adminSSOToken, realm);
        if ((dynamicServiceNames != null) && !dynamicServiceNames.isEmpty()) {
            if ((serviceNames != null) && !serviceNames.isEmpty()) {
                serviceNames.addAll(dynamicServiceNames);
            } else {
                serviceNames = dynamicServiceNames;
            }
        }
        IOutput outputWriter = getOutputWriter();
        if ((serviceNames != null) && !serviceNames.isEmpty()) {
            String msg = getResourceString("realm-get-assigned-services-results");
            outputWriter.printlnMessage(FormatUtils.printServiceNames(serviceNames, msg, adminSSOToken));
            outputWriter.printlnMessage(getResourceString("realm-get-assigned-services-succeed"));
        } else {
            outputWriter.printlnMessage(getResourceString("realm-get-assigned-services-no-services"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ASSIGNED_SERVICES_OF_REALM", params);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignedServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES_OF_REALM", args);
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignedServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES_OF_REALM", args);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignedServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNED_SERVICES_OF_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 50 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class AMCommonNameGenerator method addFormats.

/**
     * Adds format by retrieving the globalization service
     * attributes to get the list of formats and add them
     * accordingly.
     *
     * @param realm Realm Name
     * @return map of locale to formats
     */
private Map addFormats(String realm) {
    Set values = null;
    Map map = null;
    try {
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity realmIdentity = repo.getRealmIdentity();
        Set servicesFromIdRepo = realmIdentity.getAssignedServices();
        if (servicesFromIdRepo.contains(G11N_SERVICE_NAME)) {
            map = realmIdentity.getServiceAttributes(G11N_SERVICE_NAME);
        } else {
            OrganizationConfigManager orgCfgMgr = new OrganizationConfigManager(adminSSOToken, realm);
            map = orgCfgMgr.getServiceAttributes(G11N_SERVICE_NAME);
        }
    } catch (SSOException e) {
        debug.warning("AMCommonNameGenerator.addFormats", e);
    } catch (SMSException e) {
        debug.warning("AMCommonNameGenerator.addFormats", e);
    } catch (IdRepoException e) {
        debug.warning("AMCommonNameGenerator.addFormats", e);
    }
    if ((map != null) && !map.isEmpty()) {
        values = (Set) map.get(G11N_SERIVCE_COMMON_NAME_FORMAT);
    }
    if ((values == null) || values.isEmpty()) {
        if (serviceSchemaManager != null) {
            try {
                values = AMAdminUtils.getAttribute(serviceSchemaManager, SchemaType.ORGANIZATION, G11N_SERIVCE_COMMON_NAME_FORMAT);
            } catch (SMSException e) {
                debug.error("AMCommonNameGenerator.addFormats", e);
            }
        } else {
            debug.error("AMCommonNameGenerator.addFormats: " + "formats are not added because Console cannot get " + "an instance of service schema manager.");
        }
    }
    Map mapFormats = getFormatMap(values);
    synchronized (mapRealmToFormat) {
        mapRealmToFormat.put(realm, mapFormats);
    }
    return mapFormats;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)144 SMSException (com.sun.identity.sm.SMSException)87 Set (java.util.Set)79 HashSet (java.util.HashSet)54 SSOException (com.iplanet.sso.SSOException)50 Map (java.util.Map)48 HashMap (java.util.HashMap)40 SSOToken (com.iplanet.sso.SSOToken)33 IdRepoException (com.sun.identity.idm.IdRepoException)32 Iterator (java.util.Iterator)28 AMIdentity (com.sun.identity.idm.AMIdentity)23 CLIException (com.sun.identity.cli.CLIException)21 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)20 ServiceConfig (com.sun.identity.sm.ServiceConfig)17 IOutput (com.sun.identity.cli.IOutput)15 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)15 List (java.util.List)10 ForbiddenException (org.forgerock.json.resource.ForbiddenException)9 BadRequestException (org.forgerock.json.resource.BadRequestException)8 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)8