Search in sources :

Example 81 with CLIException

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

the class CreateMetaDataTemplate method buildDescriptorTemplate.

private void buildDescriptorTemplate() throws CLIException {
    Writer pw = null;
    try {
        boolean writeToFile = !isWebBased && (metadata != null) && (metadata.length() > 0);
        if (writeToFile) {
            pw = new PrintWriter(new FileWriter(metadata));
        } else {
            pw = new StringWriter();
        }
        String xml = CreateSAML2HostedProviderTemplate.buildMetaDataTemplate(entityID, getWorkflowParamMap(), protocol + "://" + host + ":" + port + deploymentURI);
        pw.write(xml);
        if (writeToFile) {
            Object[] objs = { metadata };
            getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-meta-template-created-descriptor-template"), objs));
        }
    } catch (SAML2MetaException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        Object[] objs = { metadata };
        throw new CLIException(MessageFormat.format(getResourceString("cannot-write-to-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if ((pw != null) && (pw instanceof PrintWriter)) {
            ((PrintWriter) pw).close();
        } else {
            this.getOutputWriter().printlnMessage(((StringWriter) pw).toString());
        }
    }
}
Also used : StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) CLIException(com.sun.identity.cli.CLIException) IOException(java.io.IOException) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) LogWriter(com.sun.identity.cli.LogWriter) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Example 82 with CLIException

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

the class DeleteCircleOfTrust method handleRequest.

/**
     * Deletes a circle of trust.
     *
     * @param rc Request Context.
     * @throws CLIException if unable to process this request.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    realm = getStringOptionValue(FedCLIConstants.ARGUMENT_REALM, "/");
    cot = getStringOptionValue(FedCLIConstants.ARGUMENT_COT);
    String[] params = { realm, cot };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_COT", params);
    try {
        CircleOfTrustManager cotManager = new CircleOfTrustManager(ssoToken);
        cotManager.deleteCircleOfTrust(realm, cot);
        Object[] obj = { cot };
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("delete-circle-of-trust-succeeded"), obj));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_COT", params);
    } catch (COTException e) {
        debugWarning("DeleteCircleOfTrust.handleRequest", e);
        String[] args = { realm, cot, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_COT", args);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : CircleOfTrustManager(com.sun.identity.cot.CircleOfTrustManager) CLIException(com.sun.identity.cli.CLIException) COTException(com.sun.identity.cot.COTException)

Example 83 with CLIException

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

the class ShowSite 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 siteName = getStringOptionValue(IArgument.SITE_NAME);
    String[] params = { siteName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_SITE", params);
        if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
            String primaryURL = SiteConfiguration.getSitePrimaryURL(adminSSOToken, siteName);
            Set failoverURLs = SiteConfiguration.getSiteSecondaryURLs(adminSSOToken, siteName);
            String siteId = SiteConfiguration.getSiteID(adminSSOToken, siteName);
            Object[] args = { primaryURL };
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("show-site-primaryURL"), args));
            if ((failoverURLs != null) && !failoverURLs.isEmpty()) {
                outputWriter.printlnMessage(getResourceString("show-site-secondaryURL"));
                for (Iterator i = failoverURLs.iterator(); i.hasNext(); ) {
                    outputWriter.printlnMessage((String) i.next());
                }
            } else {
                outputWriter.printlnMessage(getResourceString("show-site-no-secondaryURL"));
            }
            outputWriter.printlnMessage("");
            args[0] = siteId;
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("show-site-ID"), args));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("show-site-no-exists"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_SITE", params);
    } catch (SSOException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("ShowSite.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("ShowSite.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE", 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) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 84 with CLIException

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

the class ShowSiteMembers method handleRequest.

/**
     * Display members of a site.
     *
     * @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 siteName = getStringOptionValue(IArgument.SITE_NAME);
    String[] params = { siteName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_SITE_MEMBERS", params);
    IOutput outputWriter = getOutputWriter();
    try {
        Set members = SiteConfiguration.listServers(adminSSOToken, siteName);
        if ((members != null) && !members.isEmpty()) {
            for (Iterator i = members.iterator(); i.hasNext(); ) {
                outputWriter.printlnMessage((String) i.next());
            }
        } else {
            outputWriter.printlnMessage(getResourceString("show-site-members-no-members"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_SITE_MEMBERS", params);
    } catch (ConfigurationException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("ShowSiteMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE_MEMBERS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("ShowSiteMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE_MEMBERS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("ShowSiteMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_SITE_MEMBERS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 85 with CLIException

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

the class AddCircleOfTrustMembers method handleRequest.

/**
     * Adds member to a circle of trust.
     *
     * @param rc Request Context.
     * @throws CLIException if unable to process this request.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    realm = getStringOptionValue(FedCLIConstants.ARGUMENT_REALM, "/");
    cot = getStringOptionValue(FedCLIConstants.ARGUMENT_COT);
    spec = FederationManager.getIDFFSubCommandSpecification(rc);
    entityID = getStringOptionValue(FedCLIConstants.ARGUMENT_ENTITY_ID);
    String[] params = { realm, entityID, cot, spec };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_COT_MEMBER", params);
    try {
        CircleOfTrustManager cotManager = new CircleOfTrustManager(ssoToken);
        cotManager.addCircleOfTrustMember(realm, cot, spec, entityID);
        Object[] objs = { spec, cot, entityID, realm };
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("add-circle-of-trust-member-succeeded"), objs));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_ADD_COT_MEMBER", params);
    } catch (COTException e) {
        debugWarning("AddCircleOfTrustMembers.handleRequest", e);
        if (e instanceof L10NMessage) {
            String[] args = { realm, entityID, cot, spec, ((L10NMessage) e).getL10NMessage(getCommandManager().getLocale()) };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_COT_MEMBER", args);
            throw new CLIException(((L10NMessage) e).getL10NMessage(getCommandManager().getLocale()), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        } else {
            String[] args = { realm, entityID, cot, spec, e.getMessage() };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_COT_MEMBER", args);
            throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    }
}
Also used : CircleOfTrustManager(com.sun.identity.cot.CircleOfTrustManager) L10NMessage(com.sun.identity.shared.locale.L10NMessage) CLIException(com.sun.identity.cli.CLIException) COTException(com.sun.identity.cot.COTException)

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