KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > keys > keyresolver > KeyResolverSpi


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package com.sun.org.apache.xml.internal.security.keys.keyresolver;
18
19
20
21 import java.security.PublicKey JavaDoc;
22 import java.security.cert.X509Certificate JavaDoc;
23
24 import javax.crypto.SecretKey;
25
26 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
27 import org.w3c.dom.Element JavaDoc;
28
29
30 /**
31  * This class is abstract class for a child KeyInfo Elemnet.
32  *
33  * If you want the your KeyResolver, at firstly you must extand this class, and register
34  * as following in config.xml
35  * <PRE>
36  * &lt;KeyResolver URI="http://www.w3.org/2000/09/xmldsig#KeyValue"
37  * JAVACLASS="MyPackage.MyKeyValueImpl"//gt;
38  * </PRE>
39  *
40  * @author $Author: raul $
41  * @version $Revision: 1.11 $
42  */

43 public abstract class KeyResolverSpi {
44
45    /** {@link java.util.logging} logging facility */
46     static java.util.logging.Logger JavaDoc log =
47         java.util.logging.Logger.getLogger(KeyResolverSpi.class.getName());
48
49    /**
50     * This method helps the {@link com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver} to decide whether a
51     * {@link com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverSpi} is able to perform the requested action.
52     *
53     * @param element
54     * @param BaseURI
55     * @param storage
56     * @return true if can resolve the key in the element
57     */

58    abstract public boolean engineCanResolve(Element JavaDoc element, String JavaDoc BaseURI,
59                                             StorageResolver storage);
60
61    /**
62     * Method engineResolvePublicKey
63     *
64     * @param element
65     * @param BaseURI
66     * @param storage
67     * @return resolved public key from the registered from the element.
68     *
69     * @throws KeyResolverException
70     */

71    abstract public PublicKey JavaDoc engineResolvePublicKey(
72       Element JavaDoc element, String JavaDoc BaseURI, StorageResolver storage)
73          throws KeyResolverException;
74
75    /**
76     * Method engineResolveCertificate
77     *
78     * @param element
79     * @param BaseURI
80     * @param storage
81     * @return resolved X509Certificate key from the registered from the elements
82     *
83     * @throws KeyResolverException
84     */

85    abstract public X509Certificate JavaDoc engineResolveX509Certificate(
86       Element JavaDoc element, String JavaDoc BaseURI, StorageResolver storage)
87          throws KeyResolverException;
88
89    /**
90     * Method engineResolveSecretKey
91     *
92     * @param element
93     * @param BaseURI
94     * @param storage
95     * @return resolved SecretKey key from the registered from the elements
96     *
97     * @throws KeyResolverException
98     */

99    abstract public SecretKey engineResolveSecretKey(
100       Element JavaDoc element, String JavaDoc BaseURI, StorageResolver storage)
101          throws KeyResolverException;
102
103    /** Field _properties */
104    protected java.util.Map JavaDoc _properties = new java.util.HashMap JavaDoc(10);
105
106    /**
107     * Method engineSetProperty
108     *
109     * @param key
110     * @param value
111     */

112    public void engineSetProperty(String JavaDoc key, String JavaDoc value) {
113
114       java.util.Iterator JavaDoc i = this._properties.keySet().iterator();
115
116       while (i.hasNext()) {
117          String JavaDoc c = (String JavaDoc) i.next();
118
119          if (c.equals(key)) {
120             key = c;
121
122             break;
123          }
124       }
125
126       this._properties.put(key, value);
127    }
128
129    /**
130     * Method engineGetProperty
131     *
132     * @param key
133     * @return obtain the property appointed by key
134     */

135    public String JavaDoc engineGetProperty(String JavaDoc key) {
136
137       java.util.Iterator JavaDoc i = this._properties.keySet().iterator();
138
139       while (i.hasNext()) {
140          String JavaDoc c = (String JavaDoc) i.next();
141
142          if (c.equals(key)) {
143             key = c;
144
145             break;
146          }
147       }
148
149       return (String JavaDoc) this._properties.get(key);
150    }
151
152    /**
153     * Method engineGetPropertyKeys
154     *
155     * @return the keys of properties known by this resolver
156     */

157    public String JavaDoc[] engineGetPropertyKeys() {
158       return new String JavaDoc[0];
159    }
160
161    /**
162     * Method understandsProperty
163     *
164     * @param propertyToTest
165     * @return true if understood the property
166     */

167    public boolean understandsProperty(String JavaDoc propertyToTest) {
168
169       String JavaDoc[] understood = this.engineGetPropertyKeys();
170
171       if (understood != null) {
172          for (int i = 0; i < understood.length; i++) {
173             if (understood[i].equals(propertyToTest)) {
174                return true;
175             }
176          }
177       }
178
179       return false;
180    }
181 }
182
Popular Tags