Search in sources :

Example 96 with JAXBException

use of javax.xml.bind.JAXBException 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 97 with JAXBException

use of javax.xml.bind.JAXBException 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 98 with JAXBException

use of javax.xml.bind.JAXBException in project opennms by OpenNMS.

the class AbstractNorthbounder method buildParmMappingXml.

/**
     * Builds an XML representation of parameter mappings.
     * @param alarm the alarm
     * @param mapping the mapping
     */
private void buildParmMappingXml(final NorthboundAlarm alarm, final Map<String, Object> mapping) {
    List<OnmsEventParameter> parms = alarm.getEventParametersCollection();
    EventParms eventParms = new EventParms(parms);
    try {
        JAXBElement<EventParms> rootElement = new JAXBElement<EventParms>(new QName("eventParms"), EventParms.class, eventParms);
        StringWriter sw = new StringWriter();
        Marshaller marshaller = ONMS_EVENT_PARM_CONTEXT.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.marshal(rootElement, sw);
        LOG.debug("Adding eventParmsXML mapping with contents {}.", sw);
        mapping.put("eventParmsXml", sw);
    } catch (JAXBException e) {
        LOG.error("Error marshalling event params to XML for alarm ID: {}", alarm.getId(), e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) JAXBElement(javax.xml.bind.JAXBElement)

Example 99 with JAXBException

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

the class CreateMetaDataModelImpl method createIDFFProvider.

/**
     * Creates a IDFF provider.
     *
     * @param realm Realm Name.
     * @param entityId Entity Id.
     * @param values   Map of property name to values.
     */
public void createIDFFProvider(String realm, String entityId, Map values) throws AMConsoleException {
    try {
        IDFFMetaManager metaManager = new IDFFMetaManager(null);
        String metadata = CreateIDFFMetaDataTemplate.createStandardMetaTemplate(entityId, values, requestURL);
        String extendedData = CreateIDFFMetaDataTemplate.createExtendedMetaTemplate(entityId, values);
        EntityDescriptorElement descriptor = (EntityDescriptorElement) IDFFMetaUtils.convertStringToJAXB(metadata);
        EntityConfigElement configElt = (EntityConfigElement) IDFFMetaUtils.convertStringToJAXB(extendedData);
        metaManager.createEntityDescriptor(realm, descriptor);
        metaManager.createEntityConfig(realm, configElt);
    } catch (JAXBException ex) {
        throw new AMConsoleException(ex.getMessage());
    } catch (IDFFMetaException ex) {
        throw new AMConsoleException(ex.getMessage());
    }
}
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) EntityDescriptorElement(com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement) EntityConfigElement(com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement)

Example 100 with JAXBException

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

the class CreateMetaDataModelImpl method createWSFedProvider.

/**
     * Creates a WS Federation provider.
     *
     * @param realm Realm Name.
     * @param entityId Entity Id.
     * @param values   Map of property name to values.
     * 
     * @throws AMConsoleException if duplicate metaAliases provided or unable to create or import metadata.
     * */
public void createWSFedProvider(String realm, String entityId, Map values) throws AMConsoleException {
    try {
        List<String> metaAliases = getFederationAlias(values, MetaTemplateParameters.P_WS_FED_ALIASES);
        Set<String> duplicateCheck = new HashSet<String>(metaAliases);
        if (duplicateCheck.size() < metaAliases.size()) {
            throw new AMConsoleException(getLocalizedString("federation.create.provider.duplicate.metaAlias"));
        }
        WSFederationMetaManager metaManager = new WSFederationMetaManager();
        metaManager.validateMetaAliasForNewEntity(realm, metaAliases);
        String metadata = CreateWSFedMetaDataTemplate.createStandardMetaTemplate(entityId, values, requestURL);
        String extendedData = CreateWSFedMetaDataTemplate.createExtendedMetaTemplate(entityId, values);
        FederationElement elt = (FederationElement) WSFederationMetaUtils.convertStringToJAXB(metadata);
        String federationID = elt.getFederationID();
        if (federationID == null) {
            federationID = WSFederationConstants.DEFAULT_FEDERATION_ID;
        }
        metaManager.createFederation(realm, elt);
        FederationConfigElement cfg = (FederationConfigElement) WSFederationMetaUtils.convertStringToJAXB(extendedData);
        metaManager.createEntityConfig(realm, cfg);
    } catch (WSFederationMetaException ex) {
        throw new AMConsoleException(ex.getMessage());
    } catch (JAXBException ex) {
        throw new AMConsoleException(ex.getMessage());
    } catch (CertificateEncodingException ex) {
        throw new AMConsoleException(ex.getMessage());
    }
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) JAXBException(javax.xml.bind.JAXBException) FederationConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement) CertificateEncodingException(java.security.cert.CertificateEncodingException) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement) HashSet(java.util.HashSet)

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