Search in sources :

Example 11 with IOutput

use of com.sun.identity.cli.IOutput 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 12 with IOutput

use of com.sun.identity.cli.IOutput 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 13 with IOutput

use of com.sun.identity.cli.IOutput 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 14 with IOutput

use of com.sun.identity.cli.IOutput 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)

Example 15 with IOutput

use of com.sun.identity.cli.IOutput 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)

Aggregations

IOutput (com.sun.identity.cli.IOutput)152 CLIException (com.sun.identity.cli.CLIException)137 SSOException (com.iplanet.sso.SSOException)123 SSOToken (com.iplanet.sso.SSOToken)99 SMSException (com.sun.identity.sm.SMSException)98 Set (java.util.Set)61 Iterator (java.util.Iterator)53 IdRepoException (com.sun.identity.idm.IdRepoException)45 List (java.util.List)45 AMIdentity (com.sun.identity.idm.AMIdentity)42 Map (java.util.Map)35 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)26 ServiceSchema (com.sun.identity.sm.ServiceSchema)26 IdType (com.sun.identity.idm.IdType)19 IOException (java.io.IOException)18 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)17 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)15 AttributeSchema (com.sun.identity.sm.AttributeSchema)14