我正在尝试将证书添加到 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!?
}
}