本文整理汇总了Java中javax.xml.crypto.XMLStructure类的典型用法代码示例。如果您正苦于以下问题:Java XMLStructure类的具体用法?Java XMLStructure怎么用?Java XMLStructure使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMLStructure类属于javax.xml.crypto包,在下文中一共展示了XMLStructure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: select_wrong_structType
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Test()
public void select_wrong_structType() throws Exception {
// given
KeyInfo keyinfo = mock(KeyInfo.class);
ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
KeyName struct = mock(KeyName.class);
list.add(struct);
doReturn(list).when(keyinfo).getContent();
// when
try {
selector.select(keyinfo, null, null, null);
fail();
} catch (KeySelectorException e) {
assertTrue(e.getMessage().contains("No X509Data element found."));
}
}
示例2: select_x509Data_empty
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Test()
public void select_x509Data_empty() throws Exception {
// given
KeyInfo keyinfo = mock(KeyInfo.class);
ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
X509Data x509Data = mock(X509Data.class);
list.add(x509Data);
doReturn(list).when(keyinfo).getContent();
doReturn(new ArrayList<Object>()).when(x509Data).getContent();
// when
try {
selector.select(keyinfo, null, null, null);
fail();
} catch (KeySelectorException e) {
assertTrue(e.getMessage().contains("No X509Data element found."));
}
}
示例3: select_x509Data_noCertificate
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Test()
public void select_x509Data_noCertificate() throws Exception {
// given
KeyInfo keyinfo = mock(KeyInfo.class);
ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
X509Data x509Data = mock(X509Data.class);
list.add(x509Data);
doReturn(list).when(keyinfo).getContent();
ArrayList<Object> x509DataContent = new ArrayList<Object>();
x509DataContent.add(new String());
doReturn(x509DataContent).when(x509Data).getContent();
// when
try {
selector.select(keyinfo, null, null, null);
fail();
} catch (KeySelectorException e) {
assertTrue(e.getMessage().contains("No X509Data element found."));
}
}
示例4: select_publicKey_exception
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Test()
public void select_publicKey_exception() throws Exception {
// given
selector = spy(new X509KeySelector(keystore));
KeyInfo keyinfo = mock(KeyInfo.class);
ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
X509Data x509Data = mock(X509Data.class);
list.add(x509Data);
doReturn(list).when(keyinfo).getContent();
ArrayList<Object> x509DataContent = new ArrayList<Object>();
x509DataContent.add(mock(X509Certificate.class));
doReturn(x509DataContent).when(x509Data).getContent();
doThrow(new KeyStoreException("key exception")).when(selector)
.getPublicKeyFromKeystore(any(X509Certificate.class),
any(SignatureMethod.class));
// when
try {
selector.select(keyinfo, null, null, null);
fail();
} catch (KeySelectorException e) {
assertTrue(e.getCause().getMessage().contains("key exception"));
}
}
示例5: select_wrong_structType
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Test()
public void select_wrong_structType() throws Exception {
// given
KeyInfo keyinfo = mock(KeyInfo.class);
ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
KeyName struct = mock(KeyName.class);
list.add(struct);
doReturn(list).when(keyinfo).getContent();
// when
try {
selector.select(keyinfo, null, null, null);
fail();
} catch (KeySelectorException e) {
assertTrue(e.getMessage().contains(
"No RSA/DSA KeyValue element found"));
}
}
示例6: select_publicKey_exception
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Test()
public void select_publicKey_exception() throws Exception {
// given
KeyInfo keyinfo = mock(KeyInfo.class);
ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
KeyValue struct = mock(KeyValue.class);
list.add(struct);
doReturn(list).when(keyinfo).getContent();
doThrow(new KeyException("test")).when(struct).getPublicKey();
// when
try {
selector.select(keyinfo, null, null, null);
fail();
} catch (KeySelectorException e) {
assertTrue(e.getCause().getMessage().contains("test"));
}
}
示例7: marshalPGPData
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
/**
* Marshals a {@link PGPData}
*
* @param xwriter
* @param pgpData
* @param dsPrefix
* @param context
* @throws MarshalException
*/
public static void marshalPGPData(XmlWriter xwriter, PGPData pgpData, String dsPrefix, XMLCryptoContext context)
throws MarshalException {
xwriter.writeStartElement(dsPrefix, "PGPData", XMLSignature.XMLNS);
// create and append PGPKeyID element
byte[] keyId = pgpData.getKeyId();
if (keyId != null) {
xwriter.writeTextElement(dsPrefix, "PGPKeyID", XMLSignature.XMLNS, Base64.encode(keyId));
}
// create and append PGPKeyPacket element
byte[] keyPacket = pgpData.getKeyPacket();
if (keyPacket != null) {
xwriter.writeTextElement(dsPrefix, "XMLSignature.XMLNS", XMLSignature.XMLNS, Base64.encode(keyPacket));
}
// create and append any elements
@SuppressWarnings("unchecked")
List<XMLStructure> externalElements = pgpData.getExternalElements();
for (XMLStructure externalItem : externalElements) {
xwriter.marshalStructure(externalItem, dsPrefix, context);
}
xwriter.writeEndElement(); // "PGPData"
}
示例8: dereferenceAsXMLStructure
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
public XMLStructure dereferenceAsXMLStructure(XMLCryptoContext context)
throws URIReferenceException
{
DocumentBuilder db = null;
boolean secVal = Utils.secureValidation(context);
try {
ApacheData data = (ApacheData)dereference(context);
db = XMLUtils.createDocumentBuilder(false, secVal);
Document doc = db.parse(new ByteArrayInputStream
(data.getXMLSignatureInput().getBytes()));
Element kiElem = doc.getDocumentElement();
if (kiElem.getLocalName().equals("X509Data")
&& XMLSignature.XMLNS.equals(kiElem.getNamespaceURI())) {
return new DOMX509Data(kiElem);
} else {
return null; // unsupported
}
} catch (Exception e) {
throw new URIReferenceException(e);
} finally {
if (db != null) {
XMLUtils.repoolDocumentBuilder(db);
}
}
}
示例9: DOMKeyInfo
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
/**
* Creates a <code>DOMKeyInfo</code>.
*
* @param content a list of one or more {@link XMLStructure}s representing
* key information types. The list is defensively copied to protect
* against subsequent modification.
* @param id an ID attribute
* @throws NullPointerException if <code>content</code> is <code>null</code>
* @throws IllegalArgumentException if <code>content</code> is empty
* @throws ClassCastException if <code>content</code> contains any entries
* that are not of type {@link XMLStructure}
*/
public DOMKeyInfo(List<? extends XMLStructure> content, String id) {
if (content == null) {
throw new NullPointerException("content cannot be null");
}
this.keyInfoTypes =
Collections.unmodifiableList(new ArrayList<XMLStructure>(content));
if (this.keyInfoTypes.isEmpty()) {
throw new IllegalArgumentException("content cannot be empty");
}
for (int i = 0, size = this.keyInfoTypes.size(); i < size; i++) {
if (!(this.keyInfoTypes.get(i) instanceof XMLStructure)) {
throw new ClassCastException
("content["+i+"] is not a valid KeyInfo type");
}
}
this.id = id;
}
示例10: marshalInternal
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
private static void marshalInternal(XmlWriter xwriter, KeyInfo ki,
String dsPrefix, XMLCryptoContext context, boolean declareNamespace) throws MarshalException {
xwriter.writeStartElement(dsPrefix, "KeyInfo", XMLSignature.XMLNS);
if (declareNamespace) {
xwriter.writeNamespace(dsPrefix, XMLSignature.XMLNS);
}
xwriter.writeIdAttribute("", "", "Id", ki.getId());
// create and append KeyInfoType elements
List<XMLStructure> keyInfoTypes = getContent(ki);
for (XMLStructure kiType : keyInfoTypes) {
xwriter.marshalStructure(kiType, dsPrefix, context);
}
xwriter.writeEndElement(); // "KeyInfo"
}
示例11: testgetContent
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@org.junit.Test
@SuppressWarnings("unchecked")
public void testgetContent() {
KeyInfo[] infos = new KeyInfo[2];
infos[0] = fac.newKeyInfo
(Collections.singletonList(fac.newKeyName("foo")), "skeleton");
infos[1] = fac.newKeyInfo
(Collections.singletonList(fac.newKeyName("foo")));
for (int j = 0; j < infos.length; j++) {
KeyInfo ki = infos[j];
List<XMLStructure> li = ki.getContent();
assertNotNull(ki.getContent());
Object[] content = li.toArray();
for (int i = 0; i < content.length; i++) {
if (!(content[i] instanceof XMLStructure)) {
fail("KeyInfo element has the wrong type");
}
}
}
}
示例12: select
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Override
public KeySelectorResult select(final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context) throws KeySelectorException {
for (final Object object : keyInfo.getContent()) {
final XMLStructure info = (XMLStructure) object;
if (info instanceof X509Data) {
final X509Data x509Data = (X509Data) info;
for (final Object certificado : x509Data.getContent()) {
if (certificado instanceof X509Certificate) {
final X509Certificate x509Certificate = (X509Certificate) certificado;
if (this.algEquals(method.getAlgorithm(), x509Certificate.getPublicKey().getAlgorithm())) {
return new KeySelectorResult() {
@Override
public Key getKey() {
return x509Certificate.getPublicKey();
}
};
}
}
}
}
}
throw new KeySelectorException("N\u00e3o foi localizada a chave do certificado.");
}
示例13: marshalParams
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Override
public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
LOG.debug("marshallParams(parent,context)");
DOMStructure domParent = (DOMStructure) parent;
Node parentNode = domParent.getNode();
Element parentElement = (Element) parentNode;
parentElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:mdssi",
"http://schemas.openxmlformats.org/package/2006/digital-signature");
Document document = parentNode.getOwnerDocument();
for (String sourceId : this.sourceIds) {
Element relationshipReferenceElement = document.createElementNS(
"http://schemas.openxmlformats.org/package/2006/digital-signature", "mdssi:RelationshipReference");
relationshipReferenceElement.setAttribute("SourceId", sourceId);
parentElement.appendChild(relationshipReferenceElement);
}
for (String sourceType : this.sourceTypes) {
Element relationshipsGroupReferenceElement = document.createElementNS(
"http://schemas.openxmlformats.org/package/2006/digital-signature",
"mdssi:RelationshipsGroupReference");
relationshipsGroupReferenceElement.setAttribute("SourceType", sourceType);
parentElement.appendChild(relationshipsGroupReferenceElement);
}
}
示例14: select
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Override
public KeySelectorResult select(final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context) throws KeySelectorException {
for (final Object object : keyInfo.getContent()) {
final XMLStructure info = (XMLStructure) object;
if (info instanceof X509Data) {
final X509Data x509Data = (X509Data) info;
for (final Object certificado : x509Data.getContent()) {
if (certificado instanceof X509Certificate) {
final X509Certificate x509Certificate = (X509Certificate) certificado;
if (this.algEquals(method.getAlgorithm(), x509Certificate.getPublicKey().getAlgorithm())) {
return new KeySelectorResult() {
@Override
public Key getKey() {
return x509Certificate.getPublicKey();
}
};
}
}
}
}
}
throw new KeySelectorException("Nao foi localizada a chave do certificado.");
}
示例15: select
import javax.xml.crypto.XMLStructure; //导入依赖的package包/类
@Override
public KeySelectorResult select ( final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context ) throws KeySelectorException
{
if ( keyInfo == null )
{
throw new KeySelectorException ( "Null KeyInfo object!" );
}
final SignatureMethod sm = (SignatureMethod)method;
final List<?> list = keyInfo.getContent ();
for ( int i = 0; i < list.size (); i++ )
{
final XMLStructure xmlStructure = (XMLStructure)list.get ( i );
if ( xmlStructure instanceof KeyValue )
{
try
{
final PublicKey pk = ( (KeyValue)xmlStructure ).getPublicKey ();
// make sure algorithm is compatible with method
if ( algEquals ( sm.getAlgorithm (), pk.getAlgorithm () ) )
{
return new SimpleKeySelectorResult ( pk );
}
}
catch ( final KeyException ke )
{
throw new KeySelectorException ( ke );
}
}
}
throw new KeySelectorException ( "No KeyValue element found!" );
}