1 /* |
1 /* |
2 * reserved comment block |
2 * reserved comment block |
3 * DO NOT REMOVE OR ALTER! |
3 * DO NOT REMOVE OR ALTER! |
|
4 */ |
|
5 /** |
|
6 * Licensed to the Apache Software Foundation (ASF) under one |
|
7 * or more contributor license agreements. See the NOTICE file |
|
8 * distributed with this work for additional information |
|
9 * regarding copyright ownership. The ASF licenses this file |
|
10 * to you under the Apache License, Version 2.0 (the |
|
11 * "License"); you may not use this file except in compliance |
|
12 * with the License. You may obtain a copy of the License at |
|
13 * |
|
14 * http://www.apache.org/licenses/LICENSE-2.0 |
|
15 * |
|
16 * Unless required by applicable law or agreed to in writing, |
|
17 * software distributed under the License is distributed on an |
|
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
19 * KIND, either express or implied. See the License for the |
|
20 * specific language governing permissions and limitations |
|
21 * under the License. |
4 */ |
22 */ |
5 package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; |
23 package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; |
6 |
24 |
7 import java.security.PrivateKey; |
25 import java.security.PrivateKey; |
8 import java.security.PublicKey; |
26 import java.security.PublicKey; |
16 import org.w3c.dom.Element; |
34 import org.w3c.dom.Element; |
17 |
35 |
18 /** |
36 /** |
19 * Resolves a single Key based on the KeyName. |
37 * Resolves a single Key based on the KeyName. |
20 */ |
38 */ |
21 public class SingleKeyResolver extends KeyResolverSpi |
39 public class SingleKeyResolver extends KeyResolverSpi { |
22 { |
40 private static final com.sun.org.slf4j.internal.Logger LOG = |
23 /** {@link org.apache.commons.logging} logging facility */ |
41 com.sun.org.slf4j.internal.LoggerFactory.getLogger(SingleKeyResolver.class); |
24 private static java.util.logging.Logger log = |
|
25 java.util.logging.Logger.getLogger(SingleKeyResolver.class.getName()); |
|
26 |
42 |
27 private String keyName; |
43 private String keyName; |
28 private PublicKey publicKey; |
44 private PublicKey publicKey; |
29 private PrivateKey privateKey; |
45 private PrivateKey privateKey; |
30 private SecretKey secretKey; |
46 private SecretKey secretKey; |
61 |
77 |
62 /** |
78 /** |
63 * This method returns whether the KeyResolverSpi is able to perform the requested action. |
79 * This method returns whether the KeyResolverSpi is able to perform the requested action. |
64 * |
80 * |
65 * @param element |
81 * @param element |
66 * @param BaseURI |
82 * @param baseURI |
67 * @param storage |
83 * @param storage |
68 * @return whether the KeyResolverSpi is able to perform the requested action. |
84 * @return whether the KeyResolverSpi is able to perform the requested action. |
69 */ |
85 */ |
70 public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) { |
86 public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) { |
71 return XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME); |
87 return XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME); |
81 * @throws KeyResolverException |
97 * @throws KeyResolverException |
82 */ |
98 */ |
83 public PublicKey engineLookupAndResolvePublicKey( |
99 public PublicKey engineLookupAndResolvePublicKey( |
84 Element element, String baseURI, StorageResolver storage |
100 Element element, String baseURI, StorageResolver storage |
85 ) throws KeyResolverException { |
101 ) throws KeyResolverException { |
86 if (log.isLoggable(java.util.logging.Level.FINE)) { |
102 LOG.debug("Can I resolve {}?", element.getTagName()); |
87 log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?"); |
|
88 } |
|
89 |
103 |
90 if (publicKey != null |
104 if (publicKey != null |
91 && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) { |
105 && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) { |
92 String name = element.getFirstChild().getNodeValue(); |
106 String name = element.getFirstChild().getNodeValue(); |
93 if (keyName.equals(name)) { |
107 if (keyName.equals(name)) { |
94 return publicKey; |
108 return publicKey; |
95 } |
109 } |
96 } |
110 } |
97 |
111 |
98 log.log(java.util.logging.Level.FINE, "I can't"); |
112 LOG.debug("I can't"); |
99 return null; |
113 return null; |
100 } |
114 } |
101 |
115 |
102 /** |
116 /** |
103 * Method engineResolveX509Certificate |
117 * Method engineResolveX509Certificate |
104 * @inheritDoc |
118 * {@inheritDoc} |
105 * @param element |
119 * @param element |
106 * @param baseURI |
120 * @param baseURI |
107 * @param storage |
121 * @param storage |
108 * @throws KeyResolverException |
122 * @throws KeyResolverException |
109 */ |
123 */ |
124 * @throws KeyResolverException |
138 * @throws KeyResolverException |
125 */ |
139 */ |
126 public SecretKey engineResolveSecretKey( |
140 public SecretKey engineResolveSecretKey( |
127 Element element, String baseURI, StorageResolver storage |
141 Element element, String baseURI, StorageResolver storage |
128 ) throws KeyResolverException { |
142 ) throws KeyResolverException { |
129 if (log.isLoggable(java.util.logging.Level.FINE)) { |
143 LOG.debug("Can I resolve {}?", element.getTagName()); |
130 log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?"); |
|
131 } |
|
132 |
144 |
133 if (secretKey != null |
145 if (secretKey != null |
134 && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) { |
146 && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) { |
135 String name = element.getFirstChild().getNodeValue(); |
147 String name = element.getFirstChild().getNodeValue(); |
136 if (keyName.equals(name)) { |
148 if (keyName.equals(name)) { |
137 return secretKey; |
149 return secretKey; |
138 } |
150 } |
139 } |
151 } |
140 |
152 |
141 log.log(java.util.logging.Level.FINE, "I can't"); |
153 LOG.debug("I can't"); |
142 return null; |
154 return null; |
143 } |
155 } |
144 |
156 |
145 /** |
157 /** |
146 * Method engineResolvePrivateKey |
158 * Method engineResolvePrivateKey |
147 * @inheritDoc |
159 * {@inheritDoc} |
148 * @param element |
160 * @param element |
149 * @param baseURI |
161 * @param baseURI |
150 * @param storage |
162 * @param storage |
151 * @return resolved PrivateKey key or null if no {@link PrivateKey} could be obtained |
163 * @return resolved PrivateKey key or null if no {@link PrivateKey} could be obtained |
152 * @throws KeyResolverException |
164 * @throws KeyResolverException |
153 */ |
165 */ |
154 public PrivateKey engineLookupAndResolvePrivateKey( |
166 public PrivateKey engineLookupAndResolvePrivateKey( |
155 Element element, String baseURI, StorageResolver storage |
167 Element element, String baseURI, StorageResolver storage |
156 ) throws KeyResolverException { |
168 ) throws KeyResolverException { |
157 if (log.isLoggable(java.util.logging.Level.FINE)) { |
169 LOG.debug("Can I resolve {}?", element.getTagName()); |
158 log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?"); |
|
159 } |
|
160 |
170 |
161 if (privateKey != null |
171 if (privateKey != null |
162 && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) { |
172 && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) { |
163 String name = element.getFirstChild().getNodeValue(); |
173 String name = element.getFirstChild().getNodeValue(); |
164 if (keyName.equals(name)) { |
174 if (keyName.equals(name)) { |
165 return privateKey; |
175 return privateKey; |
166 } |
176 } |
167 } |
177 } |
168 |
178 |
169 log.log(java.util.logging.Level.FINE, "I can't"); |
179 LOG.debug("I can't"); |
170 return null; |
180 return null; |
171 } |
181 } |
172 } |
182 } |