Search in sources :

Example 86 with CLIException

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

the class BulkFederation method getEntityRoleAndIdIDFF.

private void getEntityRoleAndIdIDFF() throws CLIException {
    try {
        IDFFMetaManager idffMgr = new IDFFMetaManager(ssoToken);
        String role = idffMgr.getProviderRoleByMetaAlias(metaAlias);
        if (role == null) {
            Object[] param = { metaAlias };
            throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-unknown-metaalias"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        isIDP = role.equals(IFSConstants.IDP);
        localEntityId = idffMgr.getEntityIDByMetaAlias(metaAlias);
    } catch (IDFFMetaException e) {
        debugError("BulkFederation.getEntityRoleAndIdIDFF", e);
        Object[] param = { metaAlias };
        throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-unknown-metaalias"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : IDFFMetaManager(com.sun.identity.federation.meta.IDFFMetaManager) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) CLIException(com.sun.identity.cli.CLIException)

Example 87 with CLIException

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

the class BulkFederation method validateFiles.

/*
     * Checks if the input file exists
     * Checks if the output file is writable
     * Returns a handle to the output file writer.
     */
private BufferedWriter validateFiles() throws CLIException {
    File input = new File(userIdMappingFileName);
    if (!input.exists()) {
        Object[] param = { userIdMappingFileName };
        throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-infile-do-not-exists"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    File output = new File(outFile);
    if (output.exists()) {
        Object[] param = { outFile };
        throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-outfile-exists"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    try {
        output.createNewFile();
        if (!output.canWrite()) {
            Object[] param = { outFile };
            throw new CLIException(MessageFormat.format(getResourceString("bulk-federation-outfile-cannot-write"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        BufferedWriter out = new BufferedWriter(new FileWriter(output));
        out.write(HEADER_LOCAL + localEntityId);
        out.newLine();
        out.write(HEADER_REMOTE + remoteEntityId);
        out.newLine();
        String role = (isIDP) ? "IDP" : "SP";
        out.write(HEADER_ROLE + role);
        out.newLine();
        if (spec.equals(FedCLIConstants.IDFF_SPECIFICATION)) {
            out.write(HEADER_SPEC + FedCLIConstants.IDFF_SPECIFICATION);
        } else {
            out.write(HEADER_SPEC + FedCLIConstants.SAML2_SPECIFICATION);
        }
        out.newLine();
        return out;
    } catch (IOException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : FileWriter(java.io.FileWriter) CLIException(com.sun.identity.cli.CLIException) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 88 with CLIException

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

the class ServerConfigBase 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);
    String serverName = getStringOptionValue(IArgument.SERVER_NAME);
    if ((serverName != null) && (serverName.trim().length() > 0) && !serverName.equals(DEFAULT_SVR_CONFIG)) {
        try {
            URL url = new URL(serverName);
            if (url.getPort() == -1) {
                throw new CLIException(getResourceString("server-config-port-missing"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
            }
            if (url.getPath().length() == 0) {
                throw new CLIException(getResourceString("server-config-uri-missing"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
            }
        } catch (MalformedURLException e) {
            throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) CLIException(com.sun.identity.cli.CLIException) URL(java.net.URL)

Example 89 with CLIException

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

the class SetServerConfigXML method handleRequest.

/**
     * Set Server Configuration XML.
     *
     * @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 serverName = getStringOptionValue(IArgument.SERVER_NAME);
    String xmlFile = getStringOptionValue(IArgument.XML_FILE);
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serverName };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_SERVER_CONFIG_XML", params);
        String xml = xmlFile;
        boolean isWebEnabled = getCommandManager().webEnabled();
        if (!isWebEnabled) {
            xml = CLIUtil.getFileContent(getCommandManager(), xmlFile);
        }
        ServerConfiguration.setServerConfigXML(adminSSOToken, serverName, xml);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("set-serverconfig-xml-succeeded"), (Object[]) params));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_SERVER_CONFIG_XML", params);
    } catch (SSOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("SetServerConfigXML.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SERVER_CONFIG_XML", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("SetServerConfigXML.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SERVER_CONFIG_XML", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("SetServerConfigXML.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SERVER_CONFIG_XML", 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 90 with CLIException

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

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