src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/keys/keyresolver/implementations/X509CertificateResolver.java
changeset 50614 3810c9a2efa1
parent 47216 71c04702a3d5
equal deleted inserted replaced
50613:0f93a75b9213 50614:3810c9a2efa1
    34 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
    34 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
    35 import org.w3c.dom.Element;
    35 import org.w3c.dom.Element;
    36 
    36 
    37 /**
    37 /**
    38  * Resolves Certificates which are directly contained inside a
    38  * Resolves Certificates which are directly contained inside a
    39  * <CODE>ds:X509Certificate</CODE> Element.
    39  * {@code ds:X509Certificate} Element.
    40  *
    40  *
    41  * @author $Author: coheigea $
       
    42  */
    41  */
    43 public class X509CertificateResolver extends KeyResolverSpi {
    42 public class X509CertificateResolver extends KeyResolverSpi {
    44 
    43 
    45     /** {@link org.apache.commons.logging} logging facility */
    44     private static final com.sun.org.slf4j.internal.Logger LOG =
    46     private static java.util.logging.Logger log =
    45         com.sun.org.slf4j.internal.LoggerFactory.getLogger(X509CertificateResolver.class);
    47         java.util.logging.Logger.getLogger(X509CertificateResolver.class.getName());
       
    48 
    46 
    49     /**
    47     /**
    50      * Method engineResolvePublicKey
    48      * Method engineResolvePublicKey
    51      * @inheritDoc
    49      * {@inheritDoc}
    52      * @param element
    50      * @param element
    53      * @param BaseURI
    51      * @param baseURI
    54      * @param storage
    52      * @param storage
    55      *
    53      *
    56      * @throws KeyResolverException
    54      * @throws KeyResolverException
    57      */
    55      */
    58     public PublicKey engineLookupAndResolvePublicKey(
    56     public PublicKey engineLookupAndResolvePublicKey(
    59         Element element, String BaseURI, StorageResolver storage
    57         Element element, String baseURI, StorageResolver storage
    60     ) throws KeyResolverException {
    58     ) throws KeyResolverException {
    61 
    59 
    62         X509Certificate cert =
    60         X509Certificate cert =
    63             this.engineLookupResolveX509Certificate(element, BaseURI, storage);
    61             this.engineLookupResolveX509Certificate(element, baseURI, storage);
    64 
    62 
    65         if (cert != null) {
    63         if (cert != null) {
    66             return cert.getPublicKey();
    64             return cert.getPublicKey();
    67         }
    65         }
    68 
    66 
    69         return null;
    67         return null;
    70     }
    68     }
    71 
    69 
    72     /**
    70     /**
    73      * Method engineResolveX509Certificate
    71      * Method engineResolveX509Certificate
    74      * @inheritDoc
    72      * {@inheritDoc}
    75      * @param element
    73      * @param element
    76      * @param BaseURI
    74      * @param baseURI
    77      * @param storage
    75      * @param storage
    78      *
    76      *
    79      * @throws KeyResolverException
    77      * @throws KeyResolverException
    80      */
    78      */
    81     public X509Certificate engineLookupResolveX509Certificate(
    79     public X509Certificate engineLookupResolveX509Certificate(
    82         Element element, String BaseURI, StorageResolver storage
    80         Element element, String baseURI, StorageResolver storage
    83     ) throws KeyResolverException {
    81     ) throws KeyResolverException {
    84 
    82 
    85         try {
    83         try {
    86             Element[] els =
    84             Element[] els =
    87                 XMLUtils.selectDsNodes(element.getFirstChild(), Constants._TAG_X509CERTIFICATE);
    85                 XMLUtils.selectDsNodes(element.getFirstChild(), Constants._TAG_X509CERTIFICATE);
    88             if ((els == null) || (els.length == 0)) {
    86             if (els == null || els.length == 0) {
    89                 Element el =
    87                 Element el =
    90                     XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_X509DATA, 0);
    88                     XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_X509DATA, 0);
    91                 if (el != null) {
    89                 if (el != null) {
    92                     return engineLookupResolveX509Certificate(el, BaseURI, storage);
    90                     return engineLookupResolveX509Certificate(el, baseURI, storage);
    93                 }
    91                 }
    94                 return null;
    92                 return null;
    95             }
    93             }
    96 
    94 
    97             // populate Object array
    95             // populate Object array
    98             for (int i = 0; i < els.length; i++) {
    96             for (int i = 0; i < els.length; i++) {
    99                 XMLX509Certificate xmlCert = new XMLX509Certificate(els[i], BaseURI);
    97                 XMLX509Certificate xmlCert = new XMLX509Certificate(els[i], baseURI);
   100                 X509Certificate cert = xmlCert.getX509Certificate();
    98                 X509Certificate cert = xmlCert.getX509Certificate();
   101                 if (cert != null) {
    99                 if (cert != null) {
   102                     return cert;
   100                     return cert;
   103                 }
   101                 }
   104             }
   102             }
   105             return null;
   103             return null;
   106         } catch (XMLSecurityException ex) {
   104         } catch (XMLSecurityException ex) {
   107             if (log.isLoggable(java.util.logging.Level.FINE)) {
   105             LOG.debug("Security Exception", ex);
   108                 log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
   106             throw new KeyResolverException(ex);
   109             }
       
   110             throw new KeyResolverException("generic.EmptyMessage", ex);
       
   111         }
   107         }
   112     }
   108     }
   113 
   109 
   114     /**
   110     /**
   115      * Method engineResolveSecretKey
   111      * Method engineResolveSecretKey
   116      * @inheritDoc
   112      * {@inheritDoc}
   117      * @param element
   113      * @param element
   118      * @param BaseURI
   114      * @param baseURI
   119      * @param storage
   115      * @param storage
   120      */
   116      */
   121     public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
   117     public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
   122         Element element, String BaseURI, StorageResolver storage
   118         Element element, String baseURI, StorageResolver storage
   123     ) {
   119     ) {
   124         return null;
   120         return null;
   125     }
   121     }
   126 }
   122 }