Search in sources :

Example 81 with SAML2MetaException

use of com.sun.identity.saml2.meta.SAML2MetaException 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 SAML2MetaException

use of com.sun.identity.saml2.meta.SAML2MetaException 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 83 with SAML2MetaException

use of com.sun.identity.saml2.meta.SAML2MetaException 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 84 with SAML2MetaException

use of com.sun.identity.saml2.meta.SAML2MetaException in project OpenAM by OpenRock.

the class ImportBulkFederationData method saml2GetRoleAndEntityId.

private void saml2GetRoleAndEntityId() throws CLIException {
    try {
        SAML2MetaManager saml2Mgr = new SAML2MetaManager(ssoToken);
        String role = saml2Mgr.getRoleByMetaAlias(metaAlias);
        if (role.equals(SAML2Constants.UNKNOWN_ROLE)) {
            Object[] param = { metaAlias };
            throw new CLIException(MessageFormat.format(getResourceString("import-bulk-federation-data-unknown-metaalias"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        isIDP = role.equals(SAML2Constants.IDP_ROLE);
        localEntityId = saml2Mgr.getEntityByMetaAlias(metaAlias);
    } catch (SAML2MetaException e) {
        debugError("ImportBulkFederationData.idffGetRoleAndEntityId", e);
        Object[] param = { metaAlias };
        throw new CLIException(MessageFormat.format(getResourceString("import-bulk-federation-data-unknown-metaalias"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : CLIException(com.sun.identity.cli.CLIException) SAML2MetaManager(com.sun.identity.saml2.meta.SAML2MetaManager) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException)

Example 85 with SAML2MetaException

use of com.sun.identity.saml2.meta.SAML2MetaException in project OpenAM by OpenRock.

the class ImportEntityModelImpl method createSAMLv2Entity.

private void createSAMLv2Entity() throws AMConsoleException {
    try {
        EntityConfigElement configElt = null;
        if (extendedMetaData != null) {
            configElt = getEntityConfigElement();
            if (configElt != null && configElt.isHosted()) {
                List config = configElt.getIDPSSOConfigOrSPSSOConfigOrAuthnAuthorityConfig();
                if (!config.isEmpty()) {
                    BaseConfigType bConfig = (BaseConfigType) config.iterator().next();
                    // get the realm from the extended meta and use 
                    // for import
                    realm = SAML2MetaUtils.getRealmByMetaAlias(bConfig.getMetaAlias());
                }
            }
        }
        SAML2MetaManager metaManager = new SAML2MetaManager();
        if (standardMetaData != null) {
            importSAML2MetaData(metaManager, realm);
        }
        if (configElt != null) {
            metaManager.createEntityConfig(realm, configElt);
        }
    } catch (SAML2MetaException e) {
        throw new AMConsoleException(e);
    }
}
Also used : BaseConfigType(com.sun.identity.saml2.jaxb.entityconfig.BaseConfigType) List(java.util.List) SAML2MetaManager(com.sun.identity.saml2.meta.SAML2MetaManager) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) EntityConfigElement(com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement)

Aggregations

SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)138 List (java.util.List)106 SAML2MetaManager (com.sun.identity.saml2.meta.SAML2MetaManager)90 ArrayList (java.util.ArrayList)80 Iterator (java.util.Iterator)55 Map (java.util.Map)50 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)47 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)44 EntityConfigElement (com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement)43 HashMap (java.util.HashMap)41 SPSSOConfigElement (com.sun.identity.saml2.jaxb.entityconfig.SPSSOConfigElement)30 BaseConfigType (com.sun.identity.saml2.jaxb.entityconfig.BaseConfigType)29 EntityDescriptorElement (com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement)28 JAXBException (javax.xml.bind.JAXBException)28 SPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.SPSSODescriptorElement)26 IDPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement)24 IDPSSOConfigElement (com.sun.identity.saml2.jaxb.entityconfig.IDPSSOConfigElement)23 Set (java.util.Set)20 IOException (java.io.IOException)15 HashSet (java.util.HashSet)15