use of xades4j.xml.bind.xades.XmlAnyType in project xades4j by luisgoncalves.
the class FromXmlCommitmentTypeConverter method convertFromObjectTree.
@Override
public void convertFromObjectTree(XmlSignedDataObjectPropertiesType xmlProps, QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException {
List<XmlCommitmentTypeIndicationType> xmlCommitments = xmlProps.getCommitmentTypeIndication();
if (xmlCommitments.isEmpty()) {
return;
}
for (XmlCommitmentTypeIndicationType xmlCommitment : xmlCommitments) {
List<String> objsRefs = xmlCommitment.getObjectReference();
Object allDataObjs = xmlCommitment.getAllSignedDataObjects();
if (objsRefs.isEmpty()) {
// Should be AllSignedDataObjects.
objsRefs = null;
if (null == allDataObjs) {
throw new PropertyUnmarshalException("ObjectReference or AllSignedDataObjects have to be present", CommitmentTypePropertyBase.PROP_NAME);
}
} else if (allDataObjs != null) {
throw new PropertyUnmarshalException("Both ObjectReference and AllSignedDataObjects are present", CommitmentTypePropertyBase.PROP_NAME);
}
CommitmentTypeData commTypeData = new CommitmentTypeData(xmlCommitment.getCommitmentTypeId().getIdentifier().getValue(), xmlCommitment.getCommitmentTypeId().getDescription());
commTypeData.setObjReferences(objsRefs);
XmlCommitmentTypeQualifiersListType xmlQualifiers = xmlCommitment.getCommitmentTypeQualifiers();
if (xmlQualifiers != null) {
Collection qualifiers = new ArrayList();
for (XmlAnyType xmlQualifier : xmlQualifiers.getCommitmentTypeQualifier()) {
if (!xmlQualifier.getContent().isEmpty()) {
if (xmlQualifier.getContent().size() > 1) {
throw new PropertyUnmarshalException("Qualifiers with multiple children are not support", CommitmentTypePropertyBase.PROP_NAME);
}
qualifiers.add(xmlQualifier.getContent().get(0));
}
}
commTypeData.setQualifiers(qualifiers);
}
propertyDataCollector.addCommitmentType(commTypeData);
}
}
use of xades4j.xml.bind.xades.XmlAnyType in project xades4j by luisgoncalves.
the class FromXmlSignerRoleConverter method convertFromObjectTree.
@Override
public void convertFromObjectTree(XmlSignedSignaturePropertiesType xmlProps, QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException {
XmlSignerRoleType xmlSignerRole = xmlProps.getSignerRole();
if (null == xmlSignerRole)
return;
if (xmlSignerRole.getCertifiedRoles() != null)
throw new PropertyUnmarshalException("certified roles not supported", SignerRoleProperty.PROP_NAME);
Set<String> claimedRoles = new HashSet<String>();
for (XmlAnyType xmlRole : xmlSignerRole.getClaimedRoles().getClaimedRole()) {
List contents = xmlRole.getContent();
if (contents.size() != 1 || !(contents.get(0) instanceof String))
throw new PropertyUnmarshalException("unsupported claimed role. Only one string is supported", SignerRoleProperty.PROP_NAME);
claimedRoles.add((String) contents.get(0));
}
propertyDataCollector.setSignerRole(new SignerRoleData(claimedRoles));
}
use of xades4j.xml.bind.xades.XmlAnyType in project xades4j by luisgoncalves.
the class FromXmlUnknownUnsignedDataObjPropsConv method convertFromObjectTree.
@Override
public void convertFromObjectTree(XmlUnsignedDataObjectPropertiesType xmlProps, QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException {
for (XmlAnyType xmlUnsignedDtaObjProp : xmlProps.getUnsignedDataObjectProperty()) {
// <xsd:complexType name="UnsignedDataObjectPropertiesType">
// <xsd:sequence>
// <xsd:element name="UnsignedDataObjectProperty" type="AnyType"
// maxOccurs="unbounded"/>
// </xsd:sequence>
// <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
// </xsd:complexType>
//
// I assumed that there is only one "top" element inside UnsignedDataObjectProperty,
// which is the property element. The AnyType schema allows for multiple
// elements but since the UnsignedDataObjectProperty has to be present,
// it makes sense that it has only one child.
List<Element> propElemContent = CollectionUtils.filterByType(xmlUnsignedDtaObjProp.getContent(), Element.class);
if (!this.acceptUnknown)
throw new PropertyUnmarshalException("Unknown properties were found", "Unknown");
if (propElemContent.size() > 1)
throw new PropertyUnmarshalException("Multiple children elements in UnsignedDataObjectProperty", "Unknown");
propertyDataCollector.addGenericDOMData(new GenericDOMData(propElemContent.get(0)));
}
}
use of xades4j.xml.bind.xades.XmlAnyType in project xades4j by luisgoncalves.
the class ToXmlSignaturePolicyConverter method getSignaturePolicy.
private XmlSignaturePolicyIdType getSignaturePolicy(SignaturePolicyData sigPolicyData, Document doc) {
XmlSignaturePolicyIdType xmlSigPolicyId = new XmlSignaturePolicyIdType();
// Identifier
xmlSigPolicyId.setSigPolicyId(ToXmlUtils.getXmlObjectId(sigPolicyData.getIdentifier()));
// Hash
XmlDigestMethodType xmlDigestMethod = new XmlDigestMethodType();
xmlDigestMethod.setAlgorithm(sigPolicyData.getDigestAlgorithm());
XmlDigestAlgAndValueType xmlDigest = new XmlDigestAlgAndValueType();
xmlDigest.setDigestMethod(xmlDigestMethod);
xmlDigest.setDigestValue(sigPolicyData.getDigestValue());
xmlSigPolicyId.setSigPolicyHash(xmlDigest);
// Qualifiers
String url = sigPolicyData.getLocationUrl();
if (url != null) {
JAXBElement<String> xmlSPURI = new JAXBElement<String>(new QName(QualifyingProperty.XADES_XMLNS, "SPURI"), String.class, url);
XmlAnyType xmlQualifier = new XmlAnyType();
xmlQualifier.getContent().add(xmlSPURI);
XmlSigPolicyQualifiersListType xmlQualifiers = new XmlSigPolicyQualifiersListType();
xmlQualifiers.getSigPolicyQualifier().add(xmlQualifier);
xmlSigPolicyId.setSigPolicyQualifiers(xmlQualifiers);
}
return xmlSigPolicyId;
}
use of xades4j.xml.bind.xades.XmlAnyType in project xades4j by luisgoncalves.
the class ToXmlSignerRoleConverter method convertIntoObjectTree.
@Override
public void convertIntoObjectTree(PropertyDataObject propData, XmlSignedPropertiesType xmlProps, Document doc) {
SignerRoleData signerRoleData = (SignerRoleData) propData;
XmlSignerRoleType xmlSignerRole = new XmlSignerRoleType();
XmlClaimedRolesListType xmlClaimedRoles = new XmlClaimedRolesListType();
xmlSignerRole.setClaimedRoles(xmlClaimedRoles);
for (String r : signerRoleData.getClaimedRoles()) {
XmlAnyType xmlRole = new XmlAnyType();
xmlRole.getContent().add(r);
xmlClaimedRoles.getClaimedRole().add(xmlRole);
}
xmlProps.getSignedSignatureProperties().setSignerRole(xmlSignerRole);
}
Aggregations