Search in sources :

Example 11 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class SetSiteFailoverURLs 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 siteName = getStringOptionValue(IArgument.SITE_NAME);
    List secondaryURLs = (List) rc.getOption(IArgument.SECONDARY_URLS);
    String[] params = { siteName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_SITE_FAILOVER_URLS", params);
        if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
            SiteConfiguration.setSiteSecondaryURLs(adminSSOToken, siteName, secondaryURLs);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-site-secondary-urls-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-site-secondary-urls-no-exists"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_SITE_FAILOVER_URLS", params);
    } catch (SSOException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("SetSiteFailoverURLs.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SITE_FAILOVER_URLS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("SetSiteFailoverURLs.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SITE_FAILOVER_URLS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("SetSiteFailoverURLs.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SITE_FAILOVER_URLS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 12 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class CreateServer 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 serverName = getStringOptionValue(IArgument.SERVER_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);
    String serverconfigxml = CLIUtil.getFileContent(getCommandManager(), getStringOptionValue(SERVER_CONFIG_XML_FILE));
    String[] params = { serverName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_SERVER", params);
        if (!ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
            ServerConfiguration.createServerInstance(adminSSOToken, serverName, attributeValues, serverconfigxml);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("create-server-config-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("create-server-config-already-exists"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_CREATE_SERVER", params);
    } catch (UnknownPropertyNameException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SERVER", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) SSOToken(com.iplanet.sso.SSOToken) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) Map(java.util.Map)

Example 13 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class UpdateAgent 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 datafile = getStringOptionValue(IArgument.DATA_FILE);
    boolean bSet = isOptionSet(IArgument.AGENT_SET_ATTR_VALUE);
    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);
    String[] params = { realm, agentName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_AGENT", params);
        AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENTONLY, realm, null);
        if (!amid.isExists()) {
            String[] args = { realm, agentName, "agent did not exist" };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
            Object[] p = { agentName };
            String msg = MessageFormat.format(getResourceString("update-agent-does-not-exist"), p);
            throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        AgentConfiguration.updateAgent(adminSSOToken, realm, agentName, attributeValues, bSet);
        outputWriter.printlnMessage(getResourceString("update-agent-succeeded"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UPDATE_AGENT", params);
    } catch (IdRepoException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("UpdateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("UpdateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("UpdateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { realm, agentName, e.getMessage() };
        debugError("UpdateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) Map(java.util.Map)

Example 14 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class UpdateAgentGroup 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 agentGroupName = getStringOptionValue(IArgument.AGENT_GROUP_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    boolean bSet = isOptionSet(IArgument.AGENT_SET_ATTR_VALUE);
    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);
    String[] params = { realm, agentGroupName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_AGENT_GROUP", 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_UPDATE_AGENT_GROUP", args);
            Object[] p = { agentGroupName };
            String msg = MessageFormat.format(getResourceString("update-agent-group-does-not-exist"), p);
            throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        AgentConfiguration.updateAgentGroup(adminSSOToken, realm, agentGroupName, attributeValues, bSet);
        outputWriter.printlnMessage(getResourceString("update-agent-group-succeeded"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_UPDATE_AGENT_GROUP", params);
    } catch (IdRepoException e) {
        String[] args = { realm, agentGroupName, e.getMessage() };
        debugError("UpdateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { realm, agentGroupName, e.getMessage() };
        debugError("UpdateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { realm, agentGroupName, e.getMessage() };
        debugError("UpdateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, agentGroupName, e.getMessage() };
        debugError("UpdateAgent.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_UPDATE_AGENT_GROUP", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) IOutput(com.sun.identity.cli.IOutput) AMIdentity(com.sun.identity.idm.AMIdentity) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) Map(java.util.Map)

Example 15 with ConfigurationException

use of com.sun.identity.common.configuration.ConfigurationException in project OpenAM by OpenRock.

the class ServerSiteModelImpl method createSite.

/**
     * Creates a site.
     *
     * @param name Name of Site.
     * @param url Primary URL of Site.
     * @throws AMConsoleException if error occurs when creating site.
     */
public void createSite(String name, String url) throws AMConsoleException {
    String[] param = { name };
    logEvent("ATTEMPT_CREATE_SITE", param);
    try {
        SiteConfiguration.createSite(getUserSSOToken(), name, url, Collections.EMPTY_SET);
        logEvent("SUCCEED_CREATE_SITE", param);
    } catch (ConfigurationException e) {
        throw new AMConsoleException(getErrorString(e));
    } catch (SMSException e) {
        String[] params = { name, e.getMessage() };
        logEvent("SMS_EXCEPTION_CREATE_SITE", params);
        throw new AMConsoleException(getErrorString(e));
    } catch (SSOException e) {
        String[] params = { name, e.getMessage() };
        logEvent("SSO_EXCEPTION_CREATE_SITE", params);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Aggregations

ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)48 SSOException (com.iplanet.sso.SSOException)40 SMSException (com.sun.identity.sm.SMSException)39 SSOToken (com.iplanet.sso.SSOToken)30 CLIException (com.sun.identity.cli.CLIException)19 IOutput (com.sun.identity.cli.IOutput)17 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)14 List (java.util.List)12 IdRepoException (com.sun.identity.idm.IdRepoException)11 IOException (java.io.IOException)11 Map (java.util.Map)10 Set (java.util.Set)9 UnknownPropertyNameException (com.sun.identity.common.configuration.UnknownPropertyNameException)6 HashSet (java.util.HashSet)6 Iterator (java.util.Iterator)6 NotFoundException (org.forgerock.json.resource.NotFoundException)6 AMIdentity (com.sun.identity.idm.AMIdentity)5 MalformedURLException (java.net.MalformedURLException)5 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)5 HashMap (java.util.HashMap)4