jdk/src/share/classes/com/sun/org/apache/xml/internal/security/keys/storage/implementations/KeyStoreResolver.java
changeset 10694 cf59e2badd14
parent 1337 e8d6cef36199
child 18780 f47b920867e7
equal deleted inserted replaced
10693:6e9ebed2e783 10694:cf59e2badd14
    40 
    40 
    41    /** Field _keyStore */
    41    /** Field _keyStore */
    42    KeyStore _keyStore = null;
    42    KeyStore _keyStore = null;
    43 
    43 
    44    /** Field _iterator */
    44    /** Field _iterator */
    45    Iterator _iterator = null;
    45    Iterator<X509Certificate> _iterator = null;
    46 
    46 
    47    /**
    47    /**
    48     * Constructor KeyStoreResolver
    48     * Constructor KeyStoreResolver
    49     *
    49     *
    50     * @param keyStore is the keystore which contains the Certificates
    50     * @param keyStore is the keystore which contains the Certificates
    54       this._keyStore = keyStore;
    54       this._keyStore = keyStore;
    55       this._iterator = new KeyStoreIterator(this._keyStore);
    55       this._iterator = new KeyStoreIterator(this._keyStore);
    56    }
    56    }
    57 
    57 
    58    /** @inheritDoc */
    58    /** @inheritDoc */
    59    public Iterator getIterator() {
    59    public Iterator<X509Certificate> getIterator() {
    60       return this._iterator;
    60       return this._iterator;
    61    }
    61    }
    62 
    62 
    63    /**
    63    /**
    64     * Class KeyStoreIterator
    64     * Class KeyStoreIterator
    65     *
    65     *
    66     * @author $Author: mullan $
    66     * @author $Author: mullan $
    67     * @version $Revision: 1.5 $
    67     * @version $Revision: 1.5 $
    68     */
    68     */
    69    static class KeyStoreIterator implements Iterator {
    69    static class KeyStoreIterator implements Iterator<X509Certificate> {
    70 
    70 
    71       /** Field _keyStore */
    71       /** Field _keyStore */
    72       KeyStore _keyStore = null;
    72       KeyStore _keyStore = null;
    73 
    73 
    74       /** Field _aliases */
    74       /** Field _aliases */
    75       Enumeration _aliases = null;
    75       Enumeration<String> _aliases = null;
    76 
    76 
    77       /**
    77       /**
    78        * Constructor KeyStoreIterator
    78        * Constructor KeyStoreIterator
    79        *
    79        *
    80        * @param keyStore
    80        * @param keyStore
    95       public boolean hasNext() {
    95       public boolean hasNext() {
    96          return this._aliases.hasMoreElements();
    96          return this._aliases.hasMoreElements();
    97       }
    97       }
    98 
    98 
    99       /** @inheritDoc */
    99       /** @inheritDoc */
   100       public Object next() {
   100       @SuppressWarnings("unchecked")
       
   101       public X509Certificate next() {
   101 
   102 
   102          String alias = (String) this._aliases.nextElement();
   103          String alias = this._aliases.nextElement();
   103 
   104 
   104          try {
   105          try {
   105             return this._keyStore.getCertificate(alias);
   106             return (X509Certificate)this._keyStore.getCertificate(alias);
   106          } catch (KeyStoreException ex) {
   107          } catch (KeyStoreException ex) {
   107             return null;
   108             return null;
   108          }
   109          }
   109       }
   110       }
   110 
   111 
   133          "data/com/sun/org/apache/xml/internal/security/samples/input/keystore.jks"),
   134          "data/com/sun/org/apache/xml/internal/security/samples/input/keystore.jks"),
   134             "xmlsecurity".toCharArray());
   135             "xmlsecurity".toCharArray());
   135 
   136 
   136       KeyStoreResolver krs = new KeyStoreResolver(ks);
   137       KeyStoreResolver krs = new KeyStoreResolver(ks);
   137 
   138 
   138       for (Iterator i = krs.getIterator(); i.hasNext(); ) {
   139       for (Iterator<X509Certificate> i = krs.getIterator(); i.hasNext(); ) {
   139          X509Certificate cert = (X509Certificate) i.next();
   140          X509Certificate cert = i.next();
   140          byte[] ski =
   141          byte[] ski =
   141             com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI
   142             com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI
   142                .getSKIBytesFromCert(cert);
   143                .getSKIBytesFromCert(cert);
   143 
   144 
   144          System.out.println(com.sun.org.apache.xml.internal.security.utils.Base64.encode(ski));
   145          System.out.println(com.sun.org.apache.xml.internal.security.utils.Base64.encode(ski));