Search in sources :

Example 81 with JAXBException

use of javax.xml.bind.JAXBException in project OpenAM by OpenRock.

the class ImportMetaData method importIDFFMetaData.

private String importIDFFMetaData(String realm, IDFFMetaManager metaManager) throws IDFFMetaException, CLIException {
    InputStream is = null;
    String out = (webAccess) ? "web" : metadata;
    Object[] objs = { out };
    String entityID = null;
    try {
        Object obj;
        if (webAccess) {
            obj = IDFFMetaUtils.convertStringToJAXB(metadata);
        } else {
            is = new FileInputStream(metadata);
            Document doc = XMLUtils.toDOMDocument(is, CommandManager.getDebugger());
            obj = IDFFMetaUtils.convertNodeToJAXB(doc);
        }
        if (obj instanceof com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement) {
            com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement descriptor = (com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement) obj;
            entityID = descriptor.getProviderID();
            //TODO: signature
            //SAML2MetaSecurityUtils.verifySignature(doc);
            //
            metaManager.createEntityDescriptor(realm, descriptor);
            getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("import-entity-succeeded"), objs));
        }
        return entityID;
    } catch (FileNotFoundException e) {
        throw new CLIException(MessageFormat.format(getResourceString("file-not-found"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (JAXBException e) {
        debugWarning("ImportMetaData.importMetaData", e);
        throw new CLIException(MessageFormat.format(getResourceString("import-entity-exception-invalid-descriptor-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IllegalArgumentException e) {
        debugWarning("ImportMetaData.importMetaData", e);
        throw new CLIException(MessageFormat.format(getResourceString("import-entity-exception-invalid-descriptor-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            //do not if the file cannot be closed.
            }
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) CLIException(com.sun.identity.cli.CLIException)

Example 82 with JAXBException

use of javax.xml.bind.JAXBException in project OpenAM by OpenRock.

the class ImportMetaData method getIDFFEntityConfigElement.

private com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement getIDFFEntityConfigElement() throws IDFFMetaException, CLIException {
    String out = (webAccess) ? "web" : extendedData;
    Object[] objs = { out };
    try {
        Object obj;
        if (webAccess) {
            obj = IDFFMetaUtils.convertStringToJAXB(extendedData);
        } else {
            obj = IDFFMetaUtils.convertStringToJAXB(getFileContent(extendedData));
        }
        return (obj instanceof com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement) ? (com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement) obj : null;
    } catch (IOException e) {
        throw new CLIException(MessageFormat.format(getResourceString("file-not-found"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (JAXBException e) {
        debugWarning("ImportMetaData.importExtendedData", e);
        throw new CLIException(MessageFormat.format(getResourceString("import-entity-exception-invalid-config-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IllegalArgumentException e) {
        debugWarning("ImportMetaData.importExtendedData", e);
        throw new CLIException(MessageFormat.format(getResourceString("import-entity-exception-invalid-config-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) CLIException(com.sun.identity.cli.CLIException) EntityConfigElement(com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement)

Example 83 with JAXBException

use of javax.xml.bind.JAXBException in project OpenAM by OpenRock.

the class IDFFModelImpl method updateIDPEntityConfig.

/**
     * Modifies a identity provider's extended metadata.
     *
     * @param entityName name of Entity Descriptor.
     * @param realm where entity exists.
     * @param attrValues Map of attribute name to set of values.
     * @throws AMConsoleException if provider cannot be modified.
     * @throws JAXBException if provider cannot be retrieved.
     */
public void updateIDPEntityConfig(String realm, String entityName, Map attrValues) throws AMConsoleException {
    String[] params = { realm, entityName, "IDFF", "IDP-Extended Metadata" };
    logEvent("ATTEMPT_MODIFY_ENTITY_DESCRIPTOR", params);
    try {
        IDFFMetaManager idffMetaMgr = getIDFFMetaManager();
        EntityConfigElement entityConfig = idffMetaMgr.getEntityConfig(realm, entityName);
        if (entityConfig == null) {
            throw new AMConsoleException("invalid.entity.name");
        }
        IDPDescriptorConfigElement idpDecConfigElement = idffMetaMgr.getIDPDescriptorConfig(realm, entityName);
        if (idpDecConfigElement == null) {
            throw new AMConsoleException("invalid.config.element");
        } else {
            updateAttrInConfig(idpDecConfigElement, attrValues, EntityModel.IDENTITY_PROVIDER);
        }
        //saves the attributes by passing the new entityConfig object
        idffMetaMgr.setEntityConfig(realm, entityConfig);
        logEvent("SUCCEED_MODIFY_ENTITY_DESCRIPTOR", params);
    } catch (IDFFMetaException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realm, entityName, "IDFF", "IDP-Extended Metadata", strError };
        logEvent("FEDERATION_EXCEPTION_MODIFY_ENTITY_DESCRIPTOR", paramsEx);
        throw new AMConsoleException(strError);
    } catch (JAXBException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realm, entityName, "IDFF", "IDP-Extended Metadata", strError };
        logEvent("FEDERATION_EXCEPTION_MODIFY_ENTITY_DESCRIPTOR", paramsEx);
        throw new AMConsoleException(strError);
    }
}
Also used : IDFFMetaManager(com.sun.identity.federation.meta.IDFFMetaManager) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) JAXBException(javax.xml.bind.JAXBException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) IDPDescriptorConfigElement(com.sun.identity.federation.jaxb.entityconfig.IDPDescriptorConfigElement) EntityConfigElement(com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement)

Example 84 with JAXBException

use of javax.xml.bind.JAXBException in project OpenAM by OpenRock.

the class ImportEntityModelImpl method importSAML2MetaData.

private void importSAML2MetaData(SAML2MetaManager metaManager, String realm) throws SAML2MetaException, AMConsoleException {
    try {
        Document doc = XMLUtils.toDOMDocument(standardMetaData, debug);
        SAML2MetaUtils.importSAML2Document(metaManager, realm, doc);
    } catch (JAXBException e) {
        debug.error("ImportEntityModel.importSAML2MetaData", e);
        throw new AMConsoleException(e);
    } catch (IllegalArgumentException e) {
        debug.warning("ImportEntityModel.importSAML2MetaData", e);
        throw new AMConsoleException(e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) Document(org.w3c.dom.Document) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 85 with JAXBException

use of javax.xml.bind.JAXBException in project OpenAM by OpenRock.

the class ImportEntityModelImpl method importWSFedMetaData.

private void importWSFedMetaData() throws WSFederationMetaException, AMConsoleException {
    try {
        Object obj = WSFederationMetaUtils.convertStringToJAXB(standardMetaData);
        if (obj instanceof com.sun.identity.wsfederation.jaxb.wsfederation.FederationMetadataElement) {
            obj = ((com.sun.identity.wsfederation.jaxb.wsfederation.FederationMetadataElement) obj).getAny().get(0);
        }
        if (obj instanceof com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement) {
            com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement federation = (com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement) obj;
            // TBD
            //Document doc = XMLUtils.toDOMDocument(standardMetadata, debug);
            // WSFederationMetaSecurityUtils.verifySignature(doc);
            (new WSFederationMetaManager()).createFederation(realm, federation);
        }
    } catch (JAXBException e) {
        debug.error("ImportEntityModel.importWSFedMetaData", e);
        throw new AMConsoleException(e);
    } catch (IllegalArgumentException e) {
        debug.error("ImportEntityModel.importWSFedMetaData", e);
        throw new AMConsoleException(e);
    }
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) JAXBException(javax.xml.bind.JAXBException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Aggregations

JAXBException (javax.xml.bind.JAXBException)402 JAXBContext (javax.xml.bind.JAXBContext)126 IOException (java.io.IOException)93 Unmarshaller (javax.xml.bind.Unmarshaller)91 Marshaller (javax.xml.bind.Marshaller)69 ArrayList (java.util.ArrayList)38 StringWriter (java.io.StringWriter)35 List (java.util.List)35 Map (java.util.Map)33 SAXException (org.xml.sax.SAXException)32 File (java.io.File)29 InputStream (java.io.InputStream)29 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)28 HashSet (java.util.HashSet)28 JAXBElement (javax.xml.bind.JAXBElement)24 XMLStreamException (javax.xml.stream.XMLStreamException)23 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)22 StringReader (java.io.StringReader)21 HashMap (java.util.HashMap)21 SAML2MetaManager (com.sun.identity.saml2.meta.SAML2MetaManager)20