View Javadoc

1   /*
2    * Copyright  2003-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  
18  package org.apache.ws.security;
19  
20  /***
21   * WSDocInfo holds information about the document to process. Together
22   * with the WSDocInfoStore it provides a method to store and access document
23   * information about BinarySecurityToken, used Crypto, and others.
24   * </p>
25   * Using the Document's hash a caller can identify a document and get
26   * the stored information that me be necessary to process the document.
27   * The main usage for this is (are) the transformation functions that
28   * are called during Signature/Verfication process. 
29   * 
30   * @author Werner Dittmann (Werner.Dittmann@siemens.com)
31   *
32   */
33  
34  import org.apache.ws.security.components.crypto.Crypto;
35  import org.w3c.dom.Element;
36  
37  import java.util.Enumeration;
38  import java.util.Vector;
39  
40  public class WSDocInfo {
41      int hash;
42      Crypto crypto = null;
43      Vector bst = null;
44      Element assertion = null;
45  
46      public WSDocInfo(int hash) {
47          this.hash = hash;
48      }
49  
50      /***
51       * Clears the info data except the hash code
52       */
53      public void clear() {
54          crypto = null;
55          assertion = null;
56          if (bst != null && bst.size() > 0) {
57              bst.removeAllElements();
58          }
59          bst = null;
60      }
61  
62      /***
63       * Get a BinarySecurityToken for the given Id
64       *
65       * @param uri is the relative uri (starts with #) of the id
66       * @return the BST element or null if nothing found
67       */
68      public Element getBst(String uri) {
69          String id = uri.substring(1);
70          Element elem = null;
71  
72          if (bst != null) {
73              for (Enumeration e = bst.elements(); e.hasMoreElements();) {
74                  elem = (Element) e.nextElement();
75                  String cId = elem.getAttribute("Id");
76                  if (id.equals(cId)) {
77                      break;
78                  }
79              }
80          }
81          return elem;
82      }
83  
84      /***
85       * @return the signature crypto class used to process
86       *         the signature/verfiy
87       */
88      public Crypto getCrypto() {
89          return crypto;
90      }
91  
92      /***
93       * @return the hash value of the document
94       */
95      public int getHash() {
96          return hash;
97      }
98  
99      /***
100      * @param elem is the BinarySecurityToken to store
101      */
102     public void setBst(Element elem) {
103         if (bst == null) {
104             bst = new Vector();
105         }
106         bst.add(elem);
107     }
108 
109     /***
110      * @param crypto is the signature crypto class used to
111      *               process signature/verify
112      */
113     public void setCrypto(Crypto crypto) {
114         this.crypto = crypto;
115     }
116 
117     /***
118      * @return Returns the assertion.
119      */
120     public Element getAssertion() {
121         return assertion;
122     }
123 
124     /***
125      * @param assertion The assertion to set.
126      */
127     public void setAssertion(Element assertion) {
128         this.assertion = assertion;
129     }
130 }