Search in sources :

Example 31 with ConfigurationException

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

the class CreateSite 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);
    String siteURL = getStringOptionValue(IArgument.SITE_URL);
    List secondaryURLs = (List) rc.getOption(IArgument.SECONDARY_URLS);
    String[] params = { siteName, siteURL };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_SITE", params);
        if (!SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
            SiteConfiguration.createSite(adminSSOToken, siteName, siteURL, secondaryURLs);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("create-site-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("create-site-already-exists"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_CREATE_SITE", params);
    } catch (SSOException e) {
        String[] args = { siteName, siteURL, e.getMessage() };
        debugError("CreateSite.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SITE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { siteName, siteURL, e.getMessage() };
        debugError("CreateSite.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SITE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { siteName, siteURL, e.getMessage() };
        debugError("CreateSite.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CREATE_SITE", 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 32 with ConfigurationException

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

the class DeleteSite 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);
    String[] params = { siteName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_SITE", params);
        if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
            SiteConfiguration.deleteSite(adminSSOToken, siteName);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("delete-site-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(getResourceString("delete-site-no-exists"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_SITE", params);
    } catch (SSOException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("DeleteSite.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SITE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("DeleteSite.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SITE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("DeleteSite.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_SITE", 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) SSOException(com.iplanet.sso.SSOException)

Example 33 with ConfigurationException

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

the class SetSitePrimaryURL 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);
    String siteURL = getStringOptionValue(IArgument.SITE_URL);
    String[] params = { siteName, siteURL };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_SITE_PRIMARY_URL", params);
        if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
            SiteConfiguration.setSitePrimaryURL(adminSSOToken, siteName, siteURL);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-site-primary-url-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-site-primary-url-no-exists"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_SITE_PRIMARY_URL", params);
    } catch (SSOException e) {
        String[] args = { siteName, siteURL, e.getMessage() };
        debugError("SetSitePrimaryURL.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SITE_PRIMARY_URL", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { siteName, siteURL, e.getMessage() };
        debugError("SetSitePrimaryURL.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SITE_PRIMARY_URL", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { siteName, siteURL, e.getMessage() };
        debugError("SetSitePrimaryURL.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SITE_PRIMARY_URL", 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) SSOException(com.iplanet.sso.SSOException)

Example 34 with ConfigurationException

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

the class CloneServer 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 cloneServerName = getStringOptionValue(CLONE_NAME);
    String[] params = { serverName, cloneServerName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CLONE_SERVER", params);
        if (ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
            if (ServerConfiguration.isServerInstanceExist(adminSSOToken, cloneServerName)) {
                outputWriter.printlnMessage(getResourceString("clone-server-exists"));
            } else {
                ServerConfiguration.cloneServerInstance(adminSSOToken, serverName, cloneServerName);
                outputWriter.printlnMessage(getResourceString("clone-server-succeeded"));
            }
        } else {
            outputWriter.printlnMessage(getResourceString("clone-server-no-exists"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_CLONE_SERVER", params);
    } catch (ConfigurationException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("CreateServer.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_CLONE_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_CLONE_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_CLONE_SERVER", 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) SSOException(com.iplanet.sso.SSOException)

Example 35 with ConfigurationException

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

the class SitesResourceProvider method deleteInstance.

@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String id, DeleteRequest request) {
    ResourceResponse site;
    SSOToken token;
    try {
        token = getSsoToken(context);
        site = getSite(token, id);
    } catch (SMSException | SSOException | ConfigurationException e) {
        debug.error("Could not read site {}", id, e);
        return new InternalServerErrorException("Could not read site").asPromise();
    } catch (NotFoundException e) {
        return e.asPromise();
    }
    try {
        if (!site.getRevision().equals(request.getRevision())) {
            return new PreconditionFailedException("Revision did not match").asPromise();
        } else if (!SiteConfiguration.listServers(token, id).isEmpty()) {
            return new PreconditionFailedException("Site still has servers attached to it").asPromise();
        } else if (!SiteConfiguration.deleteSite(token, id)) {
            return new InternalServerErrorException("Could not delete site: " + id).asPromise();
        } else {
            return newResultPromise(site);
        }
    } catch (SSOException | SMSException | ConfigurationException e) {
        debug.error("Could not delete site {}", id, e);
        return new InternalServerErrorException("Could not delete site").asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ResourceResponse(org.forgerock.json.resource.ResourceResponse) SMSException(com.sun.identity.sm.SMSException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotFoundException(org.forgerock.json.resource.NotFoundException) SSOException(com.iplanet.sso.SSOException) PreconditionFailedException(org.forgerock.json.resource.PreconditionFailedException)

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