FileDocCategorySizeDatePackage
X509SubjectNameResolver.javaAPI DocJava SE 6 API6962Tue Jun 10 00:23:02 BST 2008com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations

X509SubjectNameResolver

public class X509SubjectNameResolver extends KeyResolverSpi
author
$Author: raul $

Fields Summary
static Logger
log
{@link java.util.logging} logging facility
private Element[]
_x509childNodes
Field _x509childNodes
private XMLX509SubjectName[]
_x509childObject
Field _x509childObject[]
Constructors Summary
Methods Summary
public booleanengineCanResolve(org.w3c.dom.Element element, java.lang.String BaseURI, com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver storage)
Method engineCanResolve

inheritDoc
param
element
param
BaseURI
param
storage


                
        
                                     
      if (true)
      	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");

      
       if (!XMLUtils.elementIsInSignatureSpace(element,
                 Constants._TAG_X509DATA) ) {      
         if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "I can't");

         return false;
      }


         
         this._x509childNodes = XMLUtils.selectDsNodes(element,
                 Constants._TAG_X509SUBJECTNAME);

         if ((this._x509childNodes != null)
                 && (this._x509childNodes.length > 0)) {
            if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Yes Sir, I can");

            return true;
         }
     

      if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "I can't");

      return false;
   
public java.security.PublicKeyengineResolvePublicKey(org.w3c.dom.Element element, java.lang.String BaseURI, com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver storage)
Method engineResolvePublicKey

param
element
param
BaseURI
param
storage
return
null if no {@link PublicKey} could be obtained
throws
KeyResolverException


      X509Certificate cert = this.engineResolveX509Certificate(element,
                                BaseURI, storage);

      if (cert != null) {
         return cert.getPublicKey();
      }

      return null;
   
public javax.crypto.SecretKeyengineResolveSecretKey(org.w3c.dom.Element element, java.lang.String BaseURI, com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver storage)
Method engineResolveSecretKey

inheritDoc
param
element
param
BaseURI
param
storage

      return null;
   
public java.security.cert.X509CertificateengineResolveX509Certificate(org.w3c.dom.Element element, java.lang.String BaseURI, com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver storage)
Method engineResolveX509Certificate

inheritDoc
param
element
param
BaseURI
param
storage
throws
KeyResolverException


      try {
         if (this._x509childNodes == null) {
            boolean weCanResolve = this.engineCanResolve(element, BaseURI,
                                      storage);

            if (!weCanResolve || (this._x509childNodes == null)) {
               return null;
            }
         }

         if (storage == null) {
            Object exArgs[] = { Constants._TAG_X509SUBJECTNAME };
            KeyResolverException ex =
               new KeyResolverException("KeyResolver.needStorageResolver",
                                        exArgs);

            if (log.isLoggable(java.util.logging.Level.INFO))                                  log.log(java.util.logging.Level.INFO, "", ex);

            throw ex;
         }

         this._x509childObject =
            new XMLX509SubjectName[this._x509childNodes.length];

         for (int i = 0; i < this._x509childNodes.length; i++) {
            this._x509childObject[i] =
               new XMLX509SubjectName(this._x509childNodes[i],
                                      BaseURI);
         }

         while (storage.hasNext()) {
            X509Certificate cert = storage.next();
            XMLX509SubjectName certSN =
               new XMLX509SubjectName(element.getOwnerDocument(), cert);

            if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Found Certificate SN: " + certSN.getSubjectName());

            for (int i = 0; i < this._x509childObject.length; i++) {
               if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Found Element SN:     "
                         + this._x509childObject[i].getSubjectName());

               if (certSN.equals(this._x509childObject[i])) {
                  if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "match !!! ");

                  return cert;
               } 
               if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "no match...");               
            }
         }

         return null;
      } catch (XMLSecurityException ex) {
         if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);

         throw new KeyResolverException("generic.EmptyMessage", ex);
      }