jdk/src/share/classes/com/sun/org/apache/xml/internal/security/keys/keyresolver/KeyResolverSpi.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1337 e8d6cef36199
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.security.keys.keyresolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.security.PublicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.security.cert.X509Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class is abstract class for a child KeyInfo Elemnet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * If you want the your KeyResolver, at firstly you must extand this class, and register
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * as following in config.xml
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  &lt;KeyResolver URI="http://www.w3.org/2000/09/xmldsig#KeyValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *   JAVACLASS="MyPackage.MyKeyValueImpl"//gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author $Author: raul $
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public abstract class KeyResolverSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
   /** {@link java.util.logging} logging facility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static java.util.logging.Logger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        java.util.logging.Logger.getLogger(KeyResolverSpi.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    * This method helps the {@link com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver} to decide whether a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    * {@link com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverSpi} is able to perform the requested action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    * @param element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    * @param BaseURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    * @param storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    * @return true if can resolve the key in the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
   abstract public boolean engineCanResolve(Element element, String BaseURI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                                            StorageResolver storage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    * Method engineResolvePublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    * @param element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    * @param BaseURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    * @param storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    * @return resolved public key from the registered from the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    * @throws KeyResolverException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
   abstract public PublicKey engineResolvePublicKey(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
      Element element, String BaseURI, StorageResolver storage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         throws KeyResolverException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    * Method engineResolveCertificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    * @param element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    * @param BaseURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    * @param storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    * @return resolved X509Certificate key from the registered from the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    * @throws KeyResolverException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
   abstract public X509Certificate engineResolveX509Certificate(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      Element element, String BaseURI, StorageResolver storage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         throws KeyResolverException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    * Method engineResolveSecretKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    * @param element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    * @param BaseURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    * @param storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    * @return resolved SecretKey key from the registered from the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    * @throws KeyResolverException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   abstract public SecretKey engineResolveSecretKey(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
      Element element, String BaseURI, StorageResolver storage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         throws KeyResolverException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
   /** Field _properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   protected java.util.Map _properties = new java.util.HashMap(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    * Method engineSetProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    * @param key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    * @param value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
   public void engineSetProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      java.util.Iterator i = this._properties.keySet().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      while (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         String c = (String) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         if (c.equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            key = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      this._properties.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    * Method engineGetProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    * @param key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    * @return obtain the property appointed by key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
   public String engineGetProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      java.util.Iterator i = this._properties.keySet().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      while (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         String c = (String) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         if (c.equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            key = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      return (String) this._properties.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    * Method engineGetPropertyKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    * @return the keys of properties known by this resolver
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
   public String[] engineGetPropertyKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
      return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    * Method understandsProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    * @param propertyToTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    * @return true if understood the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
   public boolean understandsProperty(String propertyToTest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      String[] understood = this.engineGetPropertyKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      if (understood != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         for (int i = 0; i < understood.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (understood[i].equals(propertyToTest)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
               return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
}