Search in sources :

Example 26 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class DeleteAuthInstances method handleRequest.

/**
     * Handles request.
     *
     * @param rc Request Context.
     * @throws CLIException if request cannot be processed.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    List names = (List) rc.getOption(AuthOptions.AUTH_INSTANCE_NAMES);
    String[] params = { realm, names.toString() };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_AUTH_INSTANCES", params);
    try {
        AMAuthenticationManager mgr = new AMAuthenticationManager(adminSSOToken, realm);
        for (Iterator i = names.iterator(); i.hasNext(); ) {
            String name = (String) i.next();
            mgr.deleteAuthenticationInstance(name);
        }
        if (names.size() == 1) {
            getOutputWriter().printlnMessage(getResourceString("authentication-delete-auth-instance-succeeded"));
        } else {
            getOutputWriter().printlnMessage(getResourceString("authentication-delete-auth-instances-succeeded"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_AUTH_INSTANCES", params);
    } catch (AMConfigurationException e) {
        debugError("DeleteAuthInstances,handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_AUTH_INSTANCES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Iterator(java.util.Iterator) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 27 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class UpdateAuthConfigurationEntries method validateEntries.

private void validateEntries(String realm, SSOToken adminSSOToken, List entries, String[] params) throws CLIException {
    if ((entries != null) && !entries.isEmpty()) {
        Set instanceNames = getInstanceNames(realm, adminSSOToken, params);
        for (Iterator i = entries.iterator(); i.hasNext(); ) {
            AuthConfigurationEntry token = (AuthConfigurationEntry) i.next();
            String instanceName = token.getLoginModuleName();
            if (!instanceNames.contains(instanceName)) {
                Object[] p = { instanceName };
                throw new CLIException(MessageFormat.format(getResourceString("authentication-set-auth-config-entries-instance-not-found"), p), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) AuthConfigurationEntry(com.sun.identity.authentication.config.AuthConfigurationEntry)

Example 28 with CLIException

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

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class RealmSetServiceAttributeValues 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<String, Set<String>> attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    attributeValues = processFileAttributes(attributeValues);
    try {
        AMIdentityRepository repo = new AMIdentityRepository(adminSSOToken, realm);
        AMIdentity ai = repo.getRealmIdentity();
        Set servicesFromIdRepo = ai.getAssignedServices();
        if (servicesFromIdRepo.contains(serviceName)) {
            handleDynamicAttributes(ai, realm, serviceName, attributeValues, bAppend);
        } else {
            handleOrganizatioAttribute(realm, serviceName, attributeValues, bAppend);
        }
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmSetServiceAttributeValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SVC_ATTR_VALUES_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmSetServiceAttributeValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SVC_ATTR_VALUES_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 30 with CLIException

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

Aggregations

CLIException (com.sun.identity.cli.CLIException)282 SSOException (com.iplanet.sso.SSOException)171 SMSException (com.sun.identity.sm.SMSException)150 IOutput (com.sun.identity.cli.IOutput)136 SSOToken (com.iplanet.sso.SSOToken)116 Set (java.util.Set)88 Iterator (java.util.Iterator)62 List (java.util.List)61 IOException (java.io.IOException)53 IdRepoException (com.sun.identity.idm.IdRepoException)48 ServiceSchema (com.sun.identity.sm.ServiceSchema)46 AMIdentity (com.sun.identity.idm.AMIdentity)43 Map (java.util.Map)42 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)33 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)29 AttributeSchema (com.sun.identity.sm.AttributeSchema)28 CLIRequest (com.sun.identity.cli.CLIRequest)27 AfterTest (org.testng.annotations.AfterTest)27 BeforeTest (org.testng.annotations.BeforeTest)27 Test (org.testng.annotations.Test)27