KickJava   Java API By Example, From Geeks To Geeks.

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


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

18 package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
19
20
21
22 import java.security.PublicKey JavaDoc;
23 import java.security.cert.X509Certificate JavaDoc;
24
25
26 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
27 import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue;
28 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
29 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
30 import com.sun.org.apache.xml.internal.security.utils.Constants;
31 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
32 import org.w3c.dom.Element JavaDoc;
33
34
35 /**
36  *
37  * @author $Author: raul $
38  */

39 public class RSAKeyValueResolver extends KeyResolverSpi {
40
41    /** {@link java.util.logging} logging facility */
42     static java.util.logging.Logger JavaDoc log =
43         java.util.logging.Logger.getLogger(
44                         RSAKeyValueResolver.class.getName());
45
46    /** Field _rsaKeyElement */
47    private Element JavaDoc _rsaKeyElement = null;
48
49    /** @inheritDoc */
50    public boolean engineCanResolve(Element JavaDoc element, String JavaDoc BaseURI,
51                                    StorageResolver storage) {
52       if (true)
53         if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
54
55       if (element == null) {
56          return false;
57       }
58
59       boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element,
60                               Constants._TAG_KEYVALUE);
61       boolean isRSAKeyValue = XMLUtils.elementIsInSignatureSpace(element,
62                                  Constants._TAG_RSAKEYVALUE);
63
64       if (isKeyValue) {
65             this._rsaKeyElement = XMLUtils.selectDsNode(element.getFirstChild(),
66                     Constants._TAG_RSAKEYVALUE, 0);
67
68             if (this._rsaKeyElement != null) {
69                return true;
70             }
71       } else if (isRSAKeyValue) {
72
73          // this trick is needed to allow the RetrievalMethodResolver to eat a
74
// ds:RSAKeyValue directly (without KeyValue)
75
this._rsaKeyElement = element;
76
77          return true;
78       }
79
80       return false;
81    }
82
83    /** @inheritDoc */
84    public PublicKey JavaDoc engineResolvePublicKey(
85            Element JavaDoc element, String JavaDoc BaseURI, StorageResolver storage) {
86
87       if (this._rsaKeyElement == null) {
88          boolean weCanResolve = this.engineCanResolve(element, BaseURI,
89                                    storage);
90
91          if (!weCanResolve || (this._rsaKeyElement == null)) {
92             return null;
93          }
94       }
95
96       try {
97          RSAKeyValue rsaKeyValue = new RSAKeyValue(this._rsaKeyElement,
98                                                    BaseURI);
99
100          return rsaKeyValue.getPublicKey();
101       } catch (XMLSecurityException ex) {
102          if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
103       }
104
105       return null;
106    }
107
108    /** @inheritDoc */
109    public X509Certificate JavaDoc engineResolveX509Certificate(
110            Element JavaDoc element, String JavaDoc BaseURI, StorageResolver storage) {
111       return null;
112    }
113
114    /** @inheritDoc */
115    public javax.crypto.SecretKey engineResolveSecretKey(
116            Element JavaDoc element, String JavaDoc BaseURI, StorageResolver storage) {
117       return null;
118    }
119 }
120
Popular Tags