Search in sources :

Example 1 with XmlAnyType

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);
    }
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) XmlCommitmentTypeIndicationType(xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType) XmlCommitmentTypeQualifiersListType(xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) CommitmentTypeData(xades4j.properties.data.CommitmentTypeData)

Example 2 with XmlAnyType

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));
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) List(java.util.List) SignerRoleData(xades4j.properties.data.SignerRoleData) XmlSignerRoleType(xades4j.xml.bind.xades.XmlSignerRoleType) HashSet(java.util.HashSet)

Example 3 with XmlAnyType

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)));
    }
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) Element(org.w3c.dom.Element) GenericDOMData(xades4j.properties.data.GenericDOMData)

Example 4 with XmlAnyType

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;
}
Also used : XmlDigestAlgAndValueType(xades4j.xml.bind.xades.XmlDigestAlgAndValueType) XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) QName(javax.xml.namespace.QName) XmlDigestMethodType(xades4j.xml.bind.xmldsig.XmlDigestMethodType) JAXBElement(javax.xml.bind.JAXBElement) XmlSignaturePolicyIdType(xades4j.xml.bind.xades.XmlSignaturePolicyIdType) XmlSigPolicyQualifiersListType(xades4j.xml.bind.xades.XmlSigPolicyQualifiersListType)

Example 5 with XmlAnyType

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);
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) XmlClaimedRolesListType(xades4j.xml.bind.xades.XmlClaimedRolesListType) SignerRoleData(xades4j.properties.data.SignerRoleData) XmlSignerRoleType(xades4j.xml.bind.xades.XmlSignerRoleType)

Aggregations

XmlAnyType (xades4j.xml.bind.xades.XmlAnyType)7 Collection (java.util.Collection)2 List (java.util.List)2 JAXBElement (javax.xml.bind.JAXBElement)2 CommitmentTypeData (xades4j.properties.data.CommitmentTypeData)2 SignerRoleData (xades4j.properties.data.SignerRoleData)2 XmlCommitmentTypeIndicationType (xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType)2 XmlCommitmentTypeQualifiersListType (xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType)2 XmlSigPolicyQualifiersListType (xades4j.xml.bind.xades.XmlSigPolicyQualifiersListType)2 XmlSignerRoleType (xades4j.xml.bind.xades.XmlSignerRoleType)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 Element (org.w3c.dom.Element)1 GenericDOMData (xades4j.properties.data.GenericDOMData)1 PropertyDataObject (xades4j.properties.data.PropertyDataObject)1 XmlClaimedRolesListType (xades4j.xml.bind.xades.XmlClaimedRolesListType)1 XmlDigestAlgAndValueType (xades4j.xml.bind.xades.XmlDigestAlgAndValueType)1 XmlIdentifierType (xades4j.xml.bind.xades.XmlIdentifierType)1 XmlObjectIdentifierType (xades4j.xml.bind.xades.XmlObjectIdentifierType)1