Search in sources :

Example 1 with CommitmentTypeData

use of xades4j.properties.data.CommitmentTypeData in project xades4j by luisgoncalves.

the class DataGenCommitmentTypeAllDataObjs method generatePropertyData.

@Override
public PropertyDataObject generatePropertyData(AllDataObjsCommitmentTypeProperty prop, PropertiesDataGenerationContext ctx) {
    CommitmentTypeData commTypeData = new CommitmentTypeData(prop.getUri(), prop.getDescription());
    commTypeData.setQualifiers(prop.getQualifiers());
    return commTypeData;
}
Also used : CommitmentTypeData(xades4j.properties.data.CommitmentTypeData)

Example 2 with CommitmentTypeData

use of xades4j.properties.data.CommitmentTypeData 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 3 with CommitmentTypeData

use of xades4j.properties.data.CommitmentTypeData in project xades4j by luisgoncalves.

the class DataGenCommitmentType method generatePropertyData.

@Override
public PropertyDataObject generatePropertyData(CommitmentTypeProperty prop, PropertiesDataGenerationContext ctx) {
    CommitmentTypeData commTypeData = new CommitmentTypeData(prop.getUri(), prop.getDescription());
    /* One ObjectReference element refers to one ds:Reference element of the
         * ds:SignedInfo corresponding with one data object qualified by this
         * property. If some but not all the signed data objects share the same
         * commitment, one ObjectReference element MUST appear for each one of
         * them. However, if all the signed data objects share the same commitment,
         * the AllSignedDataObjects empty element MUST be present.
         */
    Collection<DataObjectDesc> targets = prop.getTargetDataObjects();
    Map<DataObjectDesc, Reference> referencesMappings = ctx.getReferencesMappings();
    for (DataObjectDesc obj : targets) {
        // The ObjectReference refers the Reference element. This assumes
        // that the QualifyingProperties are in the signature's document.
        commTypeData.addObjReferences('#' + referencesMappings.get(obj).getId());
    }
    commTypeData.setQualifiers(prop.getQualifiers());
    return commTypeData;
}
Also used : Reference(org.apache.xml.security.signature.Reference) CommitmentTypeData(xades4j.properties.data.CommitmentTypeData) DataObjectDesc(xades4j.properties.DataObjectDesc)

Example 4 with CommitmentTypeData

use of xades4j.properties.data.CommitmentTypeData in project xades4j by luisgoncalves.

the class ToXmlCommitmentTypeConverter method convertIntoObjectTree.

@Override
public void convertIntoObjectTree(PropertyDataObject propData, XmlSignedPropertiesType xmlProps, Document doc) {
    CommitmentTypeData commitmentTypeData = (CommitmentTypeData) propData;
    // Create the JAXB CommitmentTypeIndication and add it to SignedDataObjectProperties.
    XmlCommitmentTypeIndicationType xmlCommitmentTypeProp = new XmlCommitmentTypeIndicationType();
    xmlProps.getSignedDataObjectProperties().getCommitmentTypeIndication().add(xmlCommitmentTypeProp);
    XmlIdentifierType xmlIdentifier = new XmlIdentifierType();
    xmlIdentifier.setValue(commitmentTypeData.getUri());
    XmlObjectIdentifierType xmlObjectId = new XmlObjectIdentifierType();
    xmlObjectId.setDescription(commitmentTypeData.getDescription());
    xmlObjectId.setIdentifier(xmlIdentifier);
    xmlCommitmentTypeProp.setCommitmentTypeId(xmlObjectId);
    Collection<String> refsUris = commitmentTypeData.getObjReferences();
    if (null == refsUris) {
        xmlCommitmentTypeProp.setAllSignedDataObjects();
    } else {
        xmlCommitmentTypeProp.getObjectReference().addAll(refsUris);
    }
    Collection qualifiers = commitmentTypeData.getQualifiers();
    if (!qualifiers.isEmpty()) {
        XmlCommitmentTypeQualifiersListType xmlQualifiers = new XmlCommitmentTypeQualifiersListType();
        for (Object q : qualifiers) {
            XmlAnyType xmlQualifier = new XmlAnyType();
            xmlQualifier.getContent().add(q);
            xmlQualifiers.getCommitmentTypeQualifier().add(xmlQualifier);
        }
        xmlCommitmentTypeProp.setCommitmentTypeQualifiers(xmlQualifiers);
    }
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) XmlIdentifierType(xades4j.xml.bind.xades.XmlIdentifierType) XmlCommitmentTypeIndicationType(xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType) XmlObjectIdentifierType(xades4j.xml.bind.xades.XmlObjectIdentifierType) XmlCommitmentTypeQualifiersListType(xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType) Collection(java.util.Collection) PropertyDataObject(xades4j.properties.data.PropertyDataObject) CommitmentTypeData(xades4j.properties.data.CommitmentTypeData)

Aggregations

CommitmentTypeData (xades4j.properties.data.CommitmentTypeData)4 Collection (java.util.Collection)2 XmlAnyType (xades4j.xml.bind.xades.XmlAnyType)2 XmlCommitmentTypeIndicationType (xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType)2 XmlCommitmentTypeQualifiersListType (xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType)2 ArrayList (java.util.ArrayList)1 Reference (org.apache.xml.security.signature.Reference)1 DataObjectDesc (xades4j.properties.DataObjectDesc)1 PropertyDataObject (xades4j.properties.data.PropertyDataObject)1 XmlIdentifierType (xades4j.xml.bind.xades.XmlIdentifierType)1 XmlObjectIdentifierType (xades4j.xml.bind.xades.XmlObjectIdentifierType)1