KickJava   Java API By Example, From Geeks To Geeks.

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


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

38 public class DSAKeyValueResolver extends KeyResolverSpi {
39
40    /** Field _dsaKeyElement */
41    private Element JavaDoc _dsaKeyElement = null;
42
43    /** @inheritDoc */
44    public boolean engineCanResolve(Element JavaDoc element, String JavaDoc BaseURI,
45                                    StorageResolver storage) {
46
47       if (element == null) {
48          return false;
49       }
50
51       boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element,
52                               Constants._TAG_KEYVALUE);
53       boolean isDSAKeyValue = XMLUtils.elementIsInSignatureSpace(element,
54                                  Constants._TAG_DSAKEYVALUE);
55
56       if (isKeyValue) {
57      
58             this._dsaKeyElement =
59                 XMLUtils.selectDsNode(element.getFirstChild(),Constants._TAG_DSAKEYVALUE,0);
60
61             if (this._dsaKeyElement != null) {
62                return true;
63             }
64       } else if (isDSAKeyValue) {
65
66          // this trick is needed to allow the RetrievalMethodResolver to eat a
67
// ds:DSAKeyValue directly (without KeyValue)
68
this._dsaKeyElement = element;
69
70          return true;
71       }
72
73       return false;
74    }
75
76    /**
77     * Method engineResolvePublicKey
78     *
79     * @param element
80     * @param BaseURI
81     * @param storage
82     * @return null if no {@link PublicKey} could be obtained
83     */

84    public PublicKey JavaDoc engineResolvePublicKey(
85            Element JavaDoc element, String JavaDoc BaseURI, StorageResolver storage) {
86
87       if (this._dsaKeyElement == null) {
88          boolean weCanResolve = this.engineCanResolve(element, BaseURI,
89                                    storage);
90
91          if (!weCanResolve || (this._dsaKeyElement == null)) {
92             return null;
93          }
94       }
95
96       try {
97          DSAKeyValue dsaKeyValue = new DSAKeyValue(this._dsaKeyElement,
98                                                    BaseURI);
99          PublicKey JavaDoc pk = dsaKeyValue.getPublicKey();
100
101          return pk;
102       } catch (XMLSecurityException ex) {
103         //do nothing
104
}
105
106       return null;
107    }
108
109    
110    /** @inheritDoc */
111    public X509Certificate JavaDoc engineResolveX509Certificate(
112            Element JavaDoc element, String JavaDoc BaseURI, StorageResolver storage) {
113       return null;
114    }
115
116    /** @inheritDoc */
117    public javax.crypto.SecretKey engineResolveSecretKey(
118            Element JavaDoc element, String JavaDoc BaseURI, StorageResolver storage){
119       return null;
120    }
121 }
122
Popular Tags