use of com.github.zhenwei.core.asn1.x509.Attribute in project kitodo-production by kitodo.
the class ExportXmlLog method startMultipleExport.
/**
* This method exports the production metadata for al list of processes as a
* single file to a given stream.
*
* @param docketDataList
* a list of Docket data
* @param outputStream
* The output stream, to write the docket to.
*/
void startMultipleExport(Iterable<DocketData> docketDataList, OutputStream outputStream) {
Document answer = new Document();
Element root = new Element("processes");
answer.setRootElement(root);
Namespace xmlns = Namespace.getNamespace(NAMESPACE);
Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.addNamespaceDeclaration(xsi);
root.setNamespace(xmlns);
Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi);
root.setAttribute(attSchema);
for (DocketData docketData : docketDataList) {
Document doc = createDocument(docketData, false);
Element processRoot = doc.getRootElement();
processRoot.detach();
root.addContent(processRoot);
}
XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat());
try {
outp.output(answer, outputStream);
} catch (IOException e) {
logger.error("Generating XML Output failed.", e);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
logger.error("Closing the output stream failed.", e);
}
}
}
}
use of com.github.zhenwei.core.asn1.x509.Attribute in project kitodo-production by kitodo.
the class ExportXmlLog method createDocument.
/**
* This method creates a new xml document with process metadata.
*
* @param docketData
* the docketData to export
* @return a new xml document
*/
private Document createDocument(DocketData docketData, boolean addNamespace) {
Element processElm = new Element("process");
final Document doc = new Document(processElm);
processElm.setAttribute("processID", String.valueOf(docketData.getProcessId()));
Namespace xmlns = Namespace.getNamespace(NAMESPACE);
processElm.setNamespace(xmlns);
// namespace declaration
if (addNamespace) {
Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
processElm.addNamespaceDeclaration(xsi);
Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi);
processElm.setAttribute(attSchema);
}
// process information
ArrayList<Element> processElements = new ArrayList<>();
Element processTitle = new Element("title", xmlns);
processTitle.setText(docketData.getProcessName());
processElements.add(processTitle);
Element project = new Element("project", xmlns);
project.setText(docketData.getProjectName());
processElements.add(project);
Element date = new Element("time", xmlns);
date.setAttribute("type", "creation date");
date.setText(String.valueOf(docketData.getCreationDate()));
processElements.add(date);
Element ruleset = new Element("ruleset", xmlns);
ruleset.setText(docketData.getRulesetName());
processElements.add(ruleset);
Element comment = new Element("comment", xmlns);
comment.setText(docketData.getComment());
processElements.add(comment);
List<Element> processProperties = prepareProperties(docketData.getProcessProperties(), xmlns);
if (!processProperties.isEmpty()) {
Element properties = new Element(PROPERTIES, xmlns);
properties.addContent(processProperties);
processElements.add(properties);
}
// template information
ArrayList<Element> templateElements = new ArrayList<>();
Element template = new Element("original", xmlns);
ArrayList<Element> templateProperties = new ArrayList<>();
if (docketData.getTemplateProperties() != null) {
for (Property prop : docketData.getTemplateProperties()) {
Element property = new Element(PROPERTY, xmlns);
property.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle());
if (prop.getValue() != null) {
property.setAttribute(VALUE, replacer(prop.getValue()));
} else {
property.setAttribute(VALUE, "");
}
Element label = new Element(LABEL, xmlns);
label.setText(prop.getTitle());
property.addContent(label);
templateProperties.add(property);
if (prop.getTitle().equals("Signatur")) {
Element secondProperty = new Element(PROPERTY, xmlns);
secondProperty.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle() + "Encoded");
if (prop.getValue() != null) {
secondProperty.setAttribute(VALUE, "vorl:" + replacer(prop.getValue()));
Element secondLabel = new Element(LABEL, xmlns);
secondLabel.setText(prop.getTitle());
secondProperty.addContent(secondLabel);
templateProperties.add(secondProperty);
}
}
}
}
if (!templateProperties.isEmpty()) {
Element properties = new Element(PROPERTIES, xmlns);
properties.addContent(templateProperties);
template.addContent(properties);
}
templateElements.add(template);
Element templates = new Element("originals", xmlns);
templates.addContent(templateElements);
processElements.add(templates);
// digital document information
ArrayList<Element> docElements = new ArrayList<>();
Element dd = new Element("digitalDocument", xmlns);
List<Element> docProperties = prepareProperties(docketData.getWorkpieceProperties(), xmlns);
if (!docProperties.isEmpty()) {
Element properties = new Element(PROPERTIES, xmlns);
properties.addContent(docProperties);
dd.addContent(properties);
}
docElements.add(dd);
Element digdoc = new Element("digitalDocuments", xmlns);
digdoc.addContent(docElements);
processElements.add(digdoc);
processElm.setContent(processElements);
return doc;
}
use of com.github.zhenwei.core.asn1.x509.Attribute in project acme4j by shred.
the class CSRBuilderTest method csrTest.
/**
* Checks if the CSR contains the right parameters.
* <p>
* This is not supposed to be a Bouncy Castle test. If the
* {@link PKCS10CertificationRequest} contains the right parameters, we assume that
* Bouncy Castle encodes it properly.
*/
private void csrTest(PKCS10CertificationRequest csr) {
X500Name name = csr.getSubject();
try (AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions()) {
softly.assertThat(name.getRDNs(BCStyle.CN)).as("CN").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("abc.de");
softly.assertThat(name.getRDNs(BCStyle.C)).as("C").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("XX");
softly.assertThat(name.getRDNs(BCStyle.L)).as("L").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("Testville");
softly.assertThat(name.getRDNs(BCStyle.O)).as("O").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("Testing Co");
softly.assertThat(name.getRDNs(BCStyle.OU)).as("OU").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("Testunit");
softly.assertThat(name.getRDNs(BCStyle.ST)).as("ST").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("ABC");
}
Attribute[] attr = csr.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest);
assertThat(attr).hasSize(1);
ASN1Encodable[] extensions = attr[0].getAttrValues().toArray();
assertThat(extensions).hasSize(1);
GeneralNames names = GeneralNames.fromExtensions((Extensions) extensions[0], Extension.subjectAlternativeName);
assertThat(names.getNames()).filteredOn(gn -> gn.getTagNo() == GeneralName.dNSName).extracting(gn -> ASN1IA5String.getInstance(gn.getName()).getString()).containsExactlyInAnyOrder("abc.de", "fg.hi", "jklm.no", "pqr.st", "uv.wx", "y.z", "*.wild.card", "ide1.nt", "ide2.nt", "ide3.nt");
assertThat(names.getNames()).filteredOn(gn -> gn.getTagNo() == GeneralName.iPAddress).extracting(gn -> getIP(gn.getName()).getHostAddress()).containsExactlyInAnyOrder("192.168.0.1", "192.168.0.2", "10.0.0.1", "10.0.0.2", "fd00:0:0:0:0:0:0:1", "fd00:0:0:0:0:0:0:2", "192.168.5.5", "192.168.5.6", "192.168.5.7");
}
use of com.github.zhenwei.core.asn1.x509.Attribute in project acme4j by shred.
the class SMIMECSRBuilderTest method smimeCsrTest.
/**
* Checks if the S/MIME CSR contains the right parameters.
* <p>
* This is not supposed to be a Bouncy Castle test. If the
* {@link PKCS10CertificationRequest} contains the right parameters, we assume that
* Bouncy Castle encodes it properly.
*/
private void smimeCsrTest(PKCS10CertificationRequest csr) {
X500Name name = csr.getSubject();
try (AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions()) {
softly.assertThat(name.getRDNs(BCStyle.CN)).as("CN").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("mail@example.com");
softly.assertThat(name.getRDNs(BCStyle.C)).as("C").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("XX");
softly.assertThat(name.getRDNs(BCStyle.L)).as("L").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("Testville");
softly.assertThat(name.getRDNs(BCStyle.O)).as("O").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("Testing Co");
softly.assertThat(name.getRDNs(BCStyle.OU)).as("OU").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("Testunit");
softly.assertThat(name.getRDNs(BCStyle.ST)).as("ST").extracting(rdn -> rdn.getFirst().getValue().toString()).contains("ABC");
}
Attribute[] attr = csr.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest);
assertThat(attr).hasSize(1);
ASN1Encodable[] extensions = attr[0].getAttrValues().toArray();
assertThat(extensions).hasSize(1);
GeneralNames names = GeneralNames.fromExtensions((Extensions) extensions[0], Extension.subjectAlternativeName);
assertThat(names.getNames()).filteredOn(gn -> gn.getTagNo() == GeneralName.rfc822Name).extracting(gn -> DERIA5String.getInstance(gn.getName()).getString()).containsExactlyInAnyOrder("mail@example.com", "info@example.com", "sales@example.com", "shop@example.com", "support@example.com", "help@example.com");
}
use of com.github.zhenwei.core.asn1.x509.Attribute in project vos by opencadc.
the class TransferReader method parseTransfer.
private Transfer parseTransfer(Document document, String targetScheme) throws URISyntaxException {
Element root = document.getRootElement();
Namespace vosNS = root.getNamespace();
Attribute versionAttr = root.getAttribute("version");
int version;
if (VOSPACE_NS_20.equals(vosNS.getURI())) {
version = VOS.VOSPACE_20;
// Check the minor version attribute
if (versionAttr != null && VOSPACE_MINOR_VERSION_21.equals(versionAttr.getValue())) {
version = VOS.VOSPACE_21;
}
} else {
throw new IllegalArgumentException("unexpected VOSpace namespace: " + vosNS.getURI());
}
Direction direction = parseDirection(root, vosNS);
// String serviceUrl; // not in XML yet
List<URI> targets = parseTargets(root, vosNS, targetScheme);
View view = null;
Parameter param = null;
List views = root.getChildren("view", vosNS);
if (views != null && views.size() > 0) {
Element v = (Element) views.get(0);
view = new View(new URI(v.getAttributeValue("uri")));
List params = v.getChildren("param", vosNS);
if (params != null) {
for (Object o : params) {
Element p = (Element) o;
param = new Parameter(new URI(p.getAttributeValue("uri")), p.getText());
view.getParameters().add(param);
}
}
}
List<Protocol> protocols = parseProtocols(root, vosNS, version);
String keepBytesStr = root.getChildText("keepBytes", vosNS);
boolean keepBytes = true;
if (keepBytesStr != null)
keepBytes = keepBytesStr.equalsIgnoreCase("true");
Transfer ret = new Transfer(direction);
ret.getTargets().addAll(targets);
ret.setView(view);
if (protocols != null) {
// parseProtocols() above can potentially return null
ret.getProtocols().addAll(protocols);
}
ret.setKeepBytes(keepBytes);
ret.version = version;
// optional param(s) added in VOSpace-2.1
if (version >= VOS.VOSPACE_21) {
List<Element> params = root.getChildren("param", vosNS);
for (Element pe : params) {
String uri = pe.getAttributeValue("uri");
if (VOS.PROPERTY_URI_CONTENTLENGTH.equals(uri)) {
try {
ret.setContentLength(new Long(pe.getText()));
} catch (NumberFormatException ex) {
throw new IllegalArgumentException("invalid " + VOS.PROPERTY_URI_CONTENTLENGTH + ": " + pe.getText());
}
} else {
log.debug("skip unknown param: " + uri);
}
}
}
return ret;
}
Aggregations