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