keyinfo.java

来自「JAVA 所有包」· Java 代码 · 共 1,226 行 · 第 1/3 页

JAVA
1,226
字号
                        PublicKey pk = keyResolver                           .engineResolvePublicKey((Element) currentChild, this                              .getBaseURI(), storage);                        if (pk != null) {                           return pk;                        }                     }                  }               }            }            currentChild=currentChild.getNextSibling();         }      }      return null;   }   /**    * Method getX509Certificate    *    * @return The certificate contined in this KeyInfo    * @throws KeyResolverException    */   public X509Certificate getX509Certificate() throws KeyResolverException {      // First search using the individual resolvers from the user      X509Certificate cert = this.getX509CertificateFromInternalResolvers();      if (cert != null) {         if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE,             "I could find a X509Certificate using the per-KeyInfo key resolvers");         return cert;      }       if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE,             "I couldn't find a X509Certificate using the per-KeyInfo key resolvers");            // Then use the system-wide Resolvers      cert = this.getX509CertificateFromStaticResolvers();      if (cert != null) {         if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE,             "I could find a X509Certificate using the system-wide key resolvers");         return cert;      }       if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE,             "I couldn't find a X509Certificate using the system-wide key resolvers");            return null;   }   /**    * This method uses each System-wide {@link KeyResolver} to search the    * child elements. Each combination of {@link KeyResolver} and child element    * is checked against all {@link StorageResolver}s.    *    * @return The certificate contined in this KeyInfo    * @throws KeyResolverException    */   X509Certificate getX509CertificateFromStaticResolvers()           throws KeyResolverException {      if (true)      	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Start getX509CertificateFromStaticResolvers() with "                + KeyResolver.length() + " resolvers");      for (int i = 0; i < KeyResolver.length(); i++) {         KeyResolver keyResolver = KeyResolver.item(i);         Node currentChild=this._constructionElement.getFirstChild();         while (currentChild!=null)      {                   if (currentChild.getNodeType() == Node.ELEMENT_NODE) {               if (this._storageResolvers.size() == 0) {                  // if we do not have storage resolvers, we verify with null                  StorageResolver storage = null;                  if (keyResolver.canResolve((Element) currentChild,                                             this.getBaseURI(), storage)) {                     X509Certificate cert =                        keyResolver                           .resolveX509Certificate((Element) currentChild, this                              .getBaseURI(), storage);                     if (cert != null) {                        return cert;                     }                  }               } else {                  for (int k = 0; k < this._storageResolvers.size(); k++) {                     StorageResolver storage =                        (StorageResolver) this._storageResolvers.get(k);                     if (keyResolver.canResolve((Element) currentChild,                                                this.getBaseURI(), storage)) {                        X509Certificate cert = keyResolver                           .resolveX509Certificate((Element) currentChild, this                              .getBaseURI(), storage);                        if (cert != null) {                           return cert;                        }                     }                  }               }                           }            currentChild=currentChild.getNextSibling();         }            }      return null;   }   /**    * Method getX509CertificateFromInternalResolvers    *    * @return The certificate contined in this KeyInfo    * @throws KeyResolverException    */   X509Certificate getX509CertificateFromInternalResolvers()           throws KeyResolverException {      if (true)      	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Start getX509CertificateFromInternalResolvers() with "                + this.lengthInternalKeyResolver() + " resolvers");      for (int i = 0; i < this.lengthInternalKeyResolver(); i++) {         KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i);         if (true)         	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName());         Node currentChild=this._constructionElement.getFirstChild();         while (currentChild!=null)      {                if (currentChild.getNodeType() == Node.ELEMENT_NODE) {               if (this._storageResolvers.size() == 0) {                  // if we do not have storage resolvers, we verify with null                  StorageResolver storage = null;                  if (keyResolver.engineCanResolve((Element) currentChild,                                                   this.getBaseURI(),                                                   storage)) {                     X509Certificate cert =                        keyResolver.engineResolveX509Certificate(                           (Element) currentChild, this.getBaseURI(), storage);                     if (cert != null) {                        return cert;                     }                  }               } else {                  for (int k = 0; k < this._storageResolvers.size(); k++) {                     StorageResolver storage =                        (StorageResolver) this._storageResolvers.get(k);                     if (keyResolver.engineCanResolve((Element) currentChild,                                                      this.getBaseURI(),                                                      storage)) {                        X509Certificate cert =                           keyResolver.engineResolveX509Certificate(                              (Element) currentChild, this.getBaseURI(),                              storage);                        if (cert != null) {                           return cert;                        }                     }                  }               }            }            currentChild=currentChild.getNextSibling();         }      }      return null;   }   /**    * This method returns a secret (symmetric) key. This is for XML Encryption.    * @return the secret key contained in this KeyInfo    * @throws KeyResolverException    */   public SecretKey getSecretKey() throws KeyResolverException {      SecretKey sk = this.getSecretKeyFromInternalResolvers();      if (sk != null) {         if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "I could find a secret key using the per-KeyInfo key resolvers");         return sk;      }       if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "I couldn't find a secret key using the per-KeyInfo key resolvers");            sk = this.getSecretKeyFromStaticResolvers();      if (sk != null) {         if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "I could find a secret key using the system-wide key resolvers");         return sk;      }       if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "I couldn't find a secret key using the system-wide key resolvers");            return null;   }   /**    * Searches the library wide keyresolvers for Secret keys    *    * @return the secret key contained in this KeyInfo    * @throws KeyResolverException    */   SecretKey getSecretKeyFromStaticResolvers() throws KeyResolverException {      for (int i = 0; i < KeyResolver.length(); i++) {         KeyResolver keyResolver = KeyResolver.item(i);         Node currentChild=this._constructionElement.getFirstChild();         while (currentChild!=null)      {                if (currentChild.getNodeType() == Node.ELEMENT_NODE) {               if (this._storageResolvers.size() == 0) {                  // if we do not have storage resolvers, we verify with null                  StorageResolver storage = null;                  if (keyResolver.canResolve((Element) currentChild,                                             this.getBaseURI(), storage)) {                     SecretKey sk  =                        keyResolver.resolveSecretKey((Element) currentChild,                                                     this.getBaseURI(),                                                     storage);                     if (sk != null) {                        return sk;                     }                  }               } else {                  for (int k = 0; k < this._storageResolvers.size(); k++) {                     StorageResolver storage =                        (StorageResolver) this._storageResolvers.get(k);                     if (keyResolver.canResolve((Element) currentChild,                                                this.getBaseURI(), storage)) {                        SecretKey sk =                           keyResolver.resolveSecretKey((Element) currentChild,                                                        this.getBaseURI(),                                                        storage);                        if (sk != null) {                           return sk;                        }                     }                  }               }            }            currentChild=currentChild.getNextSibling();         }      }      return null;   }   /**    * Searches the per-KeyInfo keyresolvers for secret keys    *    * @return the secret key contained in this KeyInfo    * @throws KeyResolverException    */   SecretKey getSecretKeyFromInternalResolvers() throws KeyResolverException {      for (int i = 0; i < this.lengthInternalKeyResolver(); i++) {         KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i);         if (true)         	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName());         Node currentChild=this._constructionElement.getFirstChild();         while (currentChild!=null)      {                if (currentChild.getNodeType() == Node.ELEMENT_NODE) {               if (this._storageResolvers.size() == 0) {                  // if we do not have storage resolvers, we verify with null                  StorageResolver storage = null;                  if (keyResolver.engineCanResolve((Element) currentChild,                                                   this.getBaseURI(),                                                   storage)) {                     SecretKey sk =                        keyResolver                           .engineResolveSecretKey((Element) currentChild, this                              .getBaseURI(), storage);                     if (sk != null) {                        return sk;                     }                  }               } else {                  for (int k = 0; k < this._storageResolvers.size(); k++) {                     StorageResolver storage =                        (StorageResolver) this._storageResolvers.get(k);                     if (keyResolver.engineCanResolve((Element) currentChild,                                                      this.getBaseURI(),                                                      storage)) {                        SecretKey sk = keyResolver                           .engineResolveSecretKey((Element) currentChild, this                              .getBaseURI(), storage);                        if (sk != null) {                           return sk;                        }                     }                  }               }            }            currentChild=currentChild.getNextSibling();         }      }      return null;   }   /**    * Stores the individual (per-KeyInfo) {@link KeyResolver}s    */   List _internalKeyResolvers = new ArrayList();   /**    * This method is used to add a custom {@link KeyResolverSpi} to a KeyInfo    * object.    *    * @param realKeyResolver    */   public void registerInternalKeyResolver(KeyResolverSpi realKeyResolver) {      this._internalKeyResolvers.add(realKeyResolver);   }   /**    * Method lengthInternalKeyResolver    * @return the length of the key    */   int lengthInternalKeyResolver() {      return this._internalKeyResolvers.size();   }   /**    * Method itemInternalKeyResolver    *    * @param i the index    * @return the KeyResolverSpi for the index.    */   KeyResolverSpi itemInternalKeyResolver(int i) {      return (KeyResolverSpi) this._internalKeyResolvers.get(i);   }   /** Field _storageResolvers */   List _storageResolvers = new ArrayList();   /**    * Method addStorageResolver    *    * @param storageResolver    */   public void addStorageResolver(StorageResolver storageResolver) {      if (storageResolver != null) {         this._storageResolvers.add(storageResolver);      }   }   /**    * Method getStorageResolvers    *    * @return the internalStorages    */   List getStorageResolvers() {      return this._storageResolvers;   }   //J-   static boolean _alreadyInitialized = false;   /** init the keyinfo (Still needed?)*/   public static void init() {      if (!KeyInfo._alreadyInitialized) {         if (KeyInfo.log == null) {            /**             * $todo$ why the hell does the static initialization from the             *  start not work ?             */            KeyInfo.log =                    java.util.logging.Logger.getLogger(KeyInfo.class.getName());            log.log(java.util.logging.Level.SEVERE, "Had to assign log in the init() function");         }         // KeyInfo._contentHandlerHash = new HashMap(10);         KeyInfo._alreadyInitialized = true;      }   }   /** @inheritDoc */   public String getBaseLocalName() {      return Constants._TAG_KEYINFO;   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?