gpt4 book ai didi

java - 添加到 X509Data 的证书列表时 X509Certificates 重复

转载 作者:行者123 更新时间:2023-12-01 14:55:43 25 4
gpt4 key购买 nike

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

最佳答案

这很奇怪,我还没有找到很好的解释。正如我在评论中所说,似乎正在完成某种索引。

但是,我尝试将元素编码到 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>

关于java - 添加到 X509Data 的证书列表时 X509Certificates 重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14322463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com