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
}
}
}
}
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();
}
}
}
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);
}
}
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());
}
}
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());
}
}
Aggregations