Search in sources :

Example 91 with CLIException

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

the class ExportMetaData method runIDFFExportMetaSign.

private void runIDFFExportMetaSign() throws CLIException {
    PrintWriter pw = null;
    String out = (isWebBase) ? "web" : metadata;
    Object[] objs = { out };
    try {
        IDFFMetaManager metaManager = new IDFFMetaManager(ssoToken);
        com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement descriptor = metaManager.getEntityDescriptor(realm, entityID);
        if (descriptor == null) {
            Object[] objs2 = { entityID, realm };
            throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-entity-descriptor-not-exist"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        SPDescriptorConfigElement spConfig = metaManager.getSPDescriptorConfig(realm, entityID);
        IDPDescriptorConfigElement idpConfig = metaManager.getIDPDescriptorConfig(realm, entityID);
        Document doc = null;
        /*
 * TODO: Signing
 * Document doc = SAML2MetaSecurityUtils.sign(
                descriptor, spConfig, idpConfig);
 */
        if (doc == null) {
            runIDFFExportMeta();
            return;
        } else {
            String xmlstr = XMLUtils.print(doc);
            if (isWebBase) {
                getOutputWriter().printlnMessage(xmlstr);
            } else {
                pw = new PrintWriter(new FileWriter(metadata));
                pw.print(xmlstr);
            }
            getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("export-entity-export-descriptor-succeeded"), objs));
        }
    } catch (IDFFMetaException e) {
        debugError("ExportMetaData.runIDFFExportMetaSign", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        debugError("ExportMetaData.runIDFFExportMetaSign", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}
Also used : IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) FileWriter(java.io.FileWriter) SPDescriptorConfigElement(com.sun.identity.federation.jaxb.entityconfig.SPDescriptorConfigElement) IOException(java.io.IOException) Document(org.w3c.dom.Document) IDFFMetaManager(com.sun.identity.federation.meta.IDFFMetaManager) CLIException(com.sun.identity.cli.CLIException) IDPDescriptorConfigElement(com.sun.identity.federation.jaxb.entityconfig.IDPDescriptorConfigElement) PrintWriter(java.io.PrintWriter)

Example 92 with CLIException

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

the class ExportMetaData method runExportExtended.

private void runExportExtended() throws CLIException {
    OutputStream os = null;
    String out = (isWebBase) ? "web" : extendedData;
    Object[] objs = { out };
    Object[] objs2 = { entityID, realm };
    try {
        SAML2MetaManager metaManager = new SAML2MetaManager(ssoToken);
        EntityConfigElement config = metaManager.getEntityConfig(realm, entityID);
        if (config == null) {
            throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-entity-config-not-exist"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        if (isWebBase) {
            os = new ByteArrayOutputStream();
        } else {
            os = new FileOutputStream(extendedData);
        }
        SAML2MetaUtils.convertJAXBToOutputStream(config, os);
        if (isWebBase) {
            getOutputWriter().printlnMessage(os.toString());
        }
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("export-entity-export-config-succeeded"), objs));
    } catch (SAML2MetaException e) {
        debugError("ExportMetaData.runExportExtended", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (FileNotFoundException e) {
        debugWarning("ExportMetaData.runExportExtended", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (JAXBException e) {
        debugWarning("ExportMetaData.runExportExtended", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IllegalArgumentException e) {
        debugWarning("ExportMetaData.runExportExtended", e);
        throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-invalid-config"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) SAML2MetaManager(com.sun.identity.saml2.meta.SAML2MetaManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) CLIException(com.sun.identity.cli.CLIException) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) EntityConfigElement(com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement)

Example 93 with CLIException

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

the class ExportMetaData method runExportMetaSign.

private void runExportMetaSign() throws CLIException {
    PrintWriter pw = null;
    String out = (isWebBase) ? "web" : metadata;
    Object[] objs = { out };
    try {
        SAML2MetaManager metaManager = new SAML2MetaManager(ssoToken);
        EntityDescriptorElement descriptor = metaManager.getEntityDescriptor(realm, entityID);
        if (descriptor == null) {
            Object[] objs2 = { entityID, realm };
            throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-entity-descriptor-not-exist"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        Document doc = SAML2MetaSecurityUtils.sign(realm, descriptor);
        if (doc == null) {
            runExportMeta();
            return;
        } else {
            String xmlstr = XMLUtils.print(doc);
            xmlstr = workaroundAbstractRoleDescriptor(xmlstr);
            if (isWebBase) {
                getOutputWriter().printlnMessage(xmlstr);
            } else {
                pw = new PrintWriter(new FileWriter(metadata));
                pw.print(xmlstr);
            }
            getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("export-entity-export-descriptor-succeeded"), objs));
        }
    } catch (SAML2MetaException e) {
        debugError("ExportMetaData.runExportMetaSign", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (JAXBException jaxbe) {
        Object[] objs3 = { entityID, realm };
        throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-invalid_descriptor"), objs3), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        debugError("ExportMetaData.runExportMetaSign", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}
Also used : FileWriter(java.io.FileWriter) JAXBException(javax.xml.bind.JAXBException) CLIException(com.sun.identity.cli.CLIException) SAML2MetaManager(com.sun.identity.saml2.meta.SAML2MetaManager) IOException(java.io.IOException) Document(org.w3c.dom.Document) EntityDescriptorElement(com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) PrintWriter(java.io.PrintWriter)

Example 94 with CLIException

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

the class ListSites 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();
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LIST_SITES", null);
        Set sites = SiteConfiguration.getSites(adminSSOToken);
        if ((sites != null) && !sites.isEmpty()) {
            for (Iterator i = sites.iterator(); i.hasNext(); ) {
                outputWriter.printlnMessage((String) i.next());
            }
        } else {
            outputWriter.printlnMessage(getResourceString("list-sites-no-instances"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_LIST_SITES", null);
    } catch (SSOException e) {
        String[] args = { e.getMessage() };
        debugError("ListSites.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_SITES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { e.getMessage() };
        debugError("ListSites.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_SITES", 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 95 with CLIException

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

the class RemoveServerConfig 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);
    List propertyNames = rc.getOption(IArgument.PROPERTY_NAMES);
    try {
        String[] params = { serverName };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_SERVER_CONFIG", params);
        if (serverName.equals(DEFAULT_SVR_CONFIG)) {
            ServerConfiguration.removeServerConfiguration(adminSSOToken, ServerConfiguration.DEFAULT_SERVER_CONFIG, propertyNames);
        } else {
            if (ServerConfiguration.isServerInstanceExist(adminSSOToken, serverName)) {
                ServerConfiguration.removeServerConfiguration(adminSSOToken, serverName, propertyNames);
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-server-config-succeeded"), (Object[]) params));
            } else {
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-server-config-does-not-exists"), (Object[]) params));
            }
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_SERVER_CONFIG", params);
    } catch (IOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("RemoveServerConfig.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SERVER_CONFIG", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("RemoveServerConfig.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SERVER_CONFIG", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serverName, e.getMessage() };
        debugError("RemoveServerConfig.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SERVER_CONFIG", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) 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)

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