0

我正在尝试将证书添加到 OpenSAML 中的 X509Data 对象。但是,当我这样做时,证书似乎被添加了两次。下面的代码演示了这一点。我在做傻事吗?

import org.junit.Test;
import org.opensaml.Configuration;
import org.opensaml.DefaultBootstrap;
import org.opensaml.xml.ConfigurationException;
import org.opensaml.xml.XMLObjectBuilderFactory;
import org.opensaml.xml.signature.X509Certificate;
import org.opensaml.xml.signature.X509Data;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;


public class BrokenListAdditionTest {
    @Test
    public void shouldNotFail() throws ConfigurationException {
        DefaultBootstrap.bootstrap();

        XMLObjectBuilderFactory openSamlBuilderFactory = Configuration.getBuilderFactory();
        X509Certificate x509Certificate = (X509Certificate) openSamlBuilderFactory.getBuilder(X509Certificate.DEFAULT_ELEMENT_NAME).buildObject(X509Certificate.DEFAULT_ELEMENT_NAME, X509Certificate.DEFAULT_ELEMENT_NAME);
        x509Certificate.setValue("foo-value");
        X509Data x509Data = (X509Data) openSamlBuilderFactory.getBuilder(X509Data.DEFAULT_ELEMENT_NAME).buildObject(X509Data.DEFAULT_ELEMENT_NAME, X509Data.TYPE_NAME);
        x509Data.getX509Certificates().add(x509Certificate);

        assertThat(x509Data.getX509Certificates().size(), is(1)); // Fails, because size() is 2!?
    }
}
4

1 回答 1

1

这很奇怪,我无法找到一个很好的解释。正如我在评论中所说,它似乎正在完成某种索引。

但是,我尝试将元素编组为 XML,并且那里的每件事看起来都很好。所以我认为无论如何你都可以使用它。

<?xml version="1.0" encoding="UTF-8"?>
<ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ds:X509DataType">
<ds:X509Certificate xsi:type="ds:X509Certificate">foo-value</ds:X509Certificate>
</ds:X509Data>
于 2013-01-17T12:52:27.127 回答