Search in sources :

Example 96 with IOutput

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

the class GetAuthConfigurationEntries 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);
    String configName = getStringOptionValue(AuthOptions.AUTH_CONFIG_NAME);
    String[] params = { realm, configName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_AUTH_CONFIG_ENTRIES", params);
    try {
        Map configData = AMAuthConfigUtils.getNamedConfig(configName, realm, adminSSOToken);
        IOutput outputWriter = getOutputWriter();
        boolean hasData = false;
        if ((configData != null) && !configData.isEmpty()) {
            Set tmp = (Set) configData.get(AuthOptions.AUTH_CONFIG_ATTR);
            if ((tmp != null) && !tmp.isEmpty()) {
                hasData = true;
                String xml = (String) tmp.iterator().next();
                List entryList = new ArrayList(AMAuthConfigUtils.xmlToAuthConfigurationEntry(xml));
                outputWriter.printlnMessage(getResourceString("authentication-get-auth-config-entries-succeeded"));
                for (Iterator i = entryList.iterator(); i.hasNext(); ) {
                    AuthConfigurationEntry e = (AuthConfigurationEntry) i.next();
                    String options = e.getOptions();
                    if (options == null) {
                        options = "";
                    }
                    Object[] args = { e.getLoginModuleName(), e.getControlFlag(), options };
                    outputWriter.printlnMessage(MessageFormat.format(getResourceString("authentication-get-auth-config-entries-entry"), args));
                }
            }
        } else {
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_CONFIG_ENTRIES", params);
            throw new CLIException(getResourceString("authentication-get-auth-config-entries-not-found"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        if (!hasData) {
            outputWriter.printlnMessage(getResourceString("authentication-get-auth-config-entries-no-values"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_GET_AUTH_CONFIG_ENTRIES", params);
    } catch (AMConfigurationException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_CONFIG_ENTRIES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_CONFIG_ENTRIES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("GetAuthConfigurationEntries.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_AUTH_CONFIG_ENTRIES", params);
        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) ArrayList(java.util.ArrayList) SSOException(com.iplanet.sso.SSOException) AuthConfigurationEntry(com.sun.identity.authentication.config.AuthConfigurationEntry) IOutput(com.sun.identity.cli.IOutput) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 97 with IOutput

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

the class ListAgentGroupMembers 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 pattern = getStringOptionValue(IArgument.FILTER);
    String agentGroupName = getStringOptionValue(IArgument.AGENT_GROUP_NAME);
    String[] params = { realm, agentGroupName };
    if ((pattern == null) || (pattern.trim().length() == 0)) {
        pattern = "*";
    }
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_AGENT_GROUP_MEMBERS", params);
        AMIdentity amid = new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);
        if (!amid.isExists()) {
            String[] args = { realm, agentGroupName, "agent group did not exist" };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP_MEMBERS", args);
            Object[] p = { agentGroupName };
            String msg = MessageFormat.format(getResourceString("list-agent-group-member-group-does-not-exist"), p);
            throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        Set members = amid.getMembers(IdType.AGENT);
        if ((members != null) && !members.isEmpty()) {
            String msg = getResourceString("format-list-agent-group-members-results");
            String[] arg = { "", "" };
            for (Iterator i = members.iterator(); i.hasNext(); ) {
                AMIdentity a = (AMIdentity) i.next();
                if (DisplayUtils.wildcardMatch(a.getName(), pattern)) {
                    arg[0] = a.getName();
                    arg[1] = a.getUniversalId();
                    outputWriter.printlnMessage(MessageFormat.format(msg, (Object[]) arg));
                }
            }
        } else {
            outputWriter.printlnMessage(getResourceString("list-agent-group-members-no-members"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_AGENT_GROUP_MEMBERS", params);
    } catch (IdRepoException e) {
        String[] args = { realm, agentGroupName, e.getMessage() };
        debugError("ListAgentGroupMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP_MEMBERS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, agentGroupName, e.getMessage() };
        debugError("ListAgentGroupMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP_MEMBERS", 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) Iterator(java.util.Iterator) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 98 with IOutput

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

the class ListAgentGroups 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 patternType = getStringOptionValue(IArgument.AGENT_TYPE);
    String filter = getStringOptionValue(IArgument.FILTER);
    if (patternType == null) {
        patternType = "";
    }
    if ((filter == null) || (filter.length() == 0)) {
        filter = "*";
    }
    String[] params = { realm, patternType, filter };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_AGENT_GROUPS", params);
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        IdSearchResults isr = amir.searchIdentities(IdType.AGENTGROUP, filter, new IdSearchControl());
        Set results = isr.getSearchResults();
        if ((results != null) && !results.isEmpty()) {
            for (Iterator i = results.iterator(); i.hasNext(); ) {
                AMIdentity amid = (AMIdentity) i.next();
                if (!matchType(amid, patternType)) {
                    i.remove();
                }
            }
        }
        if ((results != null) && !results.isEmpty()) {
            for (Iterator i = results.iterator(); i.hasNext(); ) {
                AMIdentity amid = (AMIdentity) i.next();
                Object[] args = { amid.getName(), amid.getUniversalId() };
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("format-search-agent-group-results"), args));
            }
        } else {
            outputWriter.printlnMessage(getResourceString("search-agent-group-no-entries"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_LIST_AGENT_GROUPS", params);
    } catch (IdRepoException e) {
        String[] args = { realm, patternType, filter, e.getMessage() };
        debugError("ListAgentGroups.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENT_GROUPS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, patternType, filter, e.getMessage() };
        debugError("ListAgentGroups.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENT_GROUPS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IdSearchResults(com.sun.identity.idm.IdSearchResults) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException)

Example 99 with IOutput

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

the class ListAgentMembership 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 agentName = getStringOptionValue(IArgument.AGENT_NAME);
    String[] params = { realm, agentName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_AGENT_MEMBERSHIP", params);
        AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENT, realm, null);
        if (!amid.isExists()) {
            String[] args = { realm, agentName, "agent did not exist" };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENT_MEMBERSHIP", args);
            Object[] p = { agentName };
            String msg = MessageFormat.format(getResourceString("list-agent-membership-agent-not-found"), p);
            throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        Set groups = amid.getMemberships(IdType.AGENTGROUP);
        if ((groups != null) && !groups.isEmpty()) {
            AMIdentity a = (AMIdentity) groups.iterator().next();
            Object[] obj = { a.getName(), a.getUniversalId() };
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("list-agent-membership-succeeded"), obj));
        } else {
            outputWriter.printlnMessage(getResourceString("list-agent-membership-no-members"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_LIST_AGENT_MEMBERSHIP", params);
    } catch (IdRepoException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("ListAgentMembership.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENT_MEMBERSHIP", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("ListAgentMembership.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_AGENT_MEMBERSHIP", 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) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 100 with IOutput

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

the class RemoveAgentProperties 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 agentName = getStringOptionValue(IArgument.AGENT_NAME);
    Set attributeNames = new HashSet();
    attributeNames.addAll(rc.getOption(IArgument.ATTRIBUTE_NAMES));
    String[] params = { realm, agentName, attributeNames.toString() };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_AGENT_PROPERTIES", params);
        AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENTONLY, realm, null);
        amid.removeAttributes(attributeNames);
        outputWriter.printlnMessage(getResourceString("agent-remove-properties-succeeded"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_AGENT_PROPERTIES", params);
    } catch (IdRepoException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("RemoveAgentProperties.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_AGENT_PROPERTIES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("RemoveAgentProperties.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_AGENT_PROPERTIES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet)

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