Search in sources :

Example 41 with OrganizationConfigManager

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

the class RealmSetAttributeValues 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();
    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);
    boolean bAppend = isOptionSet(OPT_APPEND);
    if ((datafile == null) && (attrValues == null)) {
        throw new CLIException(getResourceString("missing-attributevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        if (bAppend) {
            for (Iterator i = attributeValues.keySet().iterator(); i.hasNext(); ) {
                String attributeName = (String) i.next();
                String[] params = { realm, serviceName, attributeName };
                Set values = (Set) attributeValues.get(attributeName);
                writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_ATTR_VALUES_REALM", params);
                ocm.addAttributeValues(serviceName, attributeName, values);
                writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_ATTR_VALUES_REALM", params);
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-attribute-values-realm-succeed"), (Object[]) params));
            }
        } else {
            String[] params = { realm, serviceName };
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_ATTR_VALUES_REALM", params);
            ocm.setAttributes(serviceName, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_ATTR_VALUES_REALM", params);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-attribute-values-realm-succeed"), (Object[]) params));
        }
    } catch (SMSException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmSetAttributeValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_ATTR_VALUES_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) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) Map(java.util.Map)

Example 42 with OrganizationConfigManager

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

the class SearchRealms 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 pattern = getStringOptionValue(IArgument.FILTER);
    boolean recursive = isOptionSet(IArgument.RECURSIVE);
    String strRecursive = (recursive) ? "recursive" : "non recursive";
    if ((pattern == null) || (pattern.trim().length() == 0)) {
        pattern = "*";
    }
    String[] params = { realm, pattern, strRecursive };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SEARCH_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set results = ocm.getSubOrganizationNames(pattern, recursive);
        IOutput outputWriter = getOutputWriter();
        if ((results != null) && !results.isEmpty()) {
            String template = getResourceString("search-realm-results");
            String[] arg = new String[1];
            for (Iterator i = results.iterator(); i.hasNext(); ) {
                arg[0] = (String) i.next();
                outputWriter.printlnMessage(MessageFormat.format(template, (Object[]) arg));
            }
            outputWriter.printlnMessage(getResourceString("search-realm-succeed"));
        } else {
            outputWriter.printlnMessage(getResourceString("search-realm-no-results"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SEARCH_REALM", params);
    } catch (SMSException e) {
        String[] args = { realm, strRecursive, e.getMessage() };
        debugError("SearchRealms.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SEARCH_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) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException)

Example 43 with OrganizationConfigManager

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

the class RealmModifyService 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();
    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);
        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_MODIFY_SERVICE_REALM", params);
            ocm.modifyService(serviceName, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SERVICE_REALM", params);
            modified = true;
        }
        if (servicesFromIdRepo.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_SERVICE_REALM", params);
            ai.modifyService(serviceName, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_SERVICE_REALM", params);
            modified = true;
        }
        if (modified) {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-service-of-realm-succeed"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("modify-service-of-realm-not-assigned"), (Object[]) params));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, serviceName, e.getMessage() };
        debugError("RealmModifyService.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_SERVICE_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 44 with OrganizationConfigManager

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

the class RealmRemoveAttribute 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 attributeName = getStringOptionValue(IArgument.ATTRIBUTE_NAME);
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { realm, serviceName, attributeName };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_REALM_ATTRIBUTE", params);
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        ocm.removeAttribute(serviceName, attributeName);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-attribute-from-realm-succeed"), (Object[]) params));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_REALM_ATTRIBUTE", params);
    } catch (SMSException e) {
        String[] args = { realm, serviceName, attributeName, e.getMessage() };
        debugError("RealmRemoveAttribute.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_REALM_ATTRIBUTE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) CLIException(com.sun.identity.cli.CLIException)

Example 45 with OrganizationConfigManager

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

the class RealmRemoveServiceAttributes 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();
    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 attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    try {
        String[] params = { realm, serviceName };
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        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_REMOVE_SERVICE_ATTR_VALUES", params);
            Map origValues = ocm.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, false)) {
                ocm.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (servicesFromIdRepo.contains(serviceName)) {
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            Map origValues = ai.getServiceAttributes(serviceName);
            if (AttributeValues.mergeAttributeValues(origValues, attributeValues, false)) {
                ai.modifyService(serviceName, origValues);
            }
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REALM_REMOVE_SERVICE_ATTR_VALUES", params);
            modified = true;
        }
        if (modified) {
            outputWriter.printlnMessage(getResourceString("realm-remove-service-attributes-succeed"));
            outputWriter.printlnMessage("");
            outputWriter.printlnMessage(FormatUtils.printAttributeValues("{0}={1}", attributeValues));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("realm-remove-service-attributes-not-assigned"), (Object[]) params));
        }
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmRemoveServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmRemoveServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_SERVICE_ATTR_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmRemoveServiceAttributes.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REALM_REMOVE_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) 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