当前位置: 首页>>代码示例>>Java>>正文


Java KeySelectorException类代码示例

本文整理汇总了Java中javax.xml.crypto.KeySelectorException的典型用法代码示例。如果您正苦于以下问题:Java KeySelectorException类的具体用法?Java KeySelectorException怎么用?Java KeySelectorException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeySelectorException类属于javax.xml.crypto包,在下文中一共展示了KeySelectorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: select

import javax.xml.crypto.KeySelectorException; //导入依赖的package包/类
@Override
public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
		throws KeySelectorException {

	for (Object o : keyInfo.getContent()) {
		if (o instanceof X509Data) {
			for (Object o2 : ((X509Data) o).getContent()) {
				if (o2 instanceof X509Certificate) {
					final X509Certificate cert = (X509Certificate) o2;
					return new KeySelectorResult() {
						public Key getKey() {
							return cert.getPublicKey();
						}
					};
				}
			}
		}
	}

	return null;
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:22,代码来源:X509CertificateKeySelector.java

示例2: select_wrong_structType

import javax.xml.crypto.KeySelectorException; //导入依赖的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."));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:X509KeySelectorTest.java

示例3: select_x509Data_empty

import javax.xml.crypto.KeySelectorException; //导入依赖的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."));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:X509KeySelectorTest.java

示例4: select_x509Data_noCertificate

import javax.xml.crypto.KeySelectorException; //导入依赖的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."));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:X509KeySelectorTest.java

示例5: select_publicKey_exception

import javax.xml.crypto.KeySelectorException; //导入依赖的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"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:X509KeySelectorTest.java

示例6: select_wrong_structType

import javax.xml.crypto.KeySelectorException; //导入依赖的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"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:KeyValueKeySelectorTest.java

示例7: select_publicKey_exception

import javax.xml.crypto.KeySelectorException; //导入依赖的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"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:KeyValueKeySelectorTest.java

示例8: select

import javax.xml.crypto.KeySelectorException; //导入依赖的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.");
}
 
开发者ID:GilbertoMattos,项目名称:nfce,代码行数:24,代码来源:X509KeySelector.java

示例9: select

import javax.xml.crypto.KeySelectorException; //导入依赖的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.");
}
 
开发者ID:wmixvideo,项目名称:nfe,代码行数:24,代码来源:X509KeySelector.java

示例10: select

import javax.xml.crypto.KeySelectorException; //导入依赖的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!" );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:35,代码来源:KeyValueKeySelector.java

示例11: select

import javax.xml.crypto.KeySelectorException; //导入依赖的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 ( final Object l : list )
    {
        final XMLStructure xmlStructure = (XMLStructure)l;
        if ( xmlStructure instanceof X509Data )
        {
            for ( final Object o : ( (X509Data)xmlStructure ).getContent () )
            {
                KeySelectorResult result = null;
                if ( o instanceof X509Certificate )
                {
                    result = findPublicKey ( (X509Certificate)o, sm );
                }

                if ( result != null )
                {
                    return result;
                }
            }
        }
    }
    throw new KeySelectorException ( "No KeyValue element found!" );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:34,代码来源:X509KeySelector.java

示例12: select_keyInfo_null

import javax.xml.crypto.KeySelectorException; //导入依赖的package包/类
@Test()
public void select_keyInfo_null() throws Exception {
    // given

    // when
    try {
        selector.select(null, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains("Null KeyInfo object!"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:13,代码来源:X509KeySelectorTest.java

示例13: select_xmlStruct_empty

import javax.xml.crypto.KeySelectorException; //导入依赖的package包/类
@Test()
public void select_xmlStruct_empty() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    doReturn(new ArrayList<XMLStructure>()).when(keyinfo).getContent();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getMessage().contains("No X509Data element found."));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:15,代码来源:X509KeySelectorTest.java

示例14: select_xmlStruct_empty

import javax.xml.crypto.KeySelectorException; //导入依赖的package包/类
@Test()
public void select_xmlStruct_empty() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    doReturn(new ArrayList<XMLStructure>()).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"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:16,代码来源:KeyValueKeySelectorTest.java

示例15: select

import javax.xml.crypto.KeySelectorException; //导入依赖的package包/类
@Override
public KeySelectorResult select(KeyInfo keyInfo,
        KeySelector.Purpose purpose, AlgorithmMethod algorithmMethod,
        XMLCryptoContext context) throws KeySelectorException {

    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }

    @SuppressWarnings("unchecked")
    List<XMLStructure> list = keyInfo.getContent();
    for (XMLStructure xmlStructure : list) {
        if (xmlStructure instanceof X509Data) {
            X509Data x509Data = (X509Data) xmlStructure;
            @SuppressWarnings("rawtypes")
            List content = x509Data.getContent();
            for (int i = 0; i < content.size(); i++) {
                Object x509Content = content.get(i);
                if (x509Content instanceof X509Certificate) {
                    X509Certificate certificate = (X509Certificate) x509Content;
                    try {
                        return getPublicKeyFromKeystore(certificate,
                                (SignatureMethod) algorithmMethod);
                    } catch (KeyStoreException e) {
                        throw new KeySelectorException(e);
                    }
                }
            }
        }
    }

    throw new KeySelectorException("No X509Data element found.");
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:34,代码来源:X509KeySelector.java


注:本文中的javax.xml.crypto.KeySelectorException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。