View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.ws.security.message.token;
21  
22  import org.apache.ws.security.WSConstants;
23  import org.apache.ws.security.WSSecurityException;
24  import org.apache.ws.security.util.DOM2Writer;
25  import org.apache.ws.security.util.WSSecurityUtil;
26  import org.w3c.dom.Document;
27  import org.w3c.dom.Element;
28  import org.w3c.dom.Node;
29  
30  /**
31   * An X509Data token.
32   */
33  public final class DOMX509Data {
34      private final Element element;
35      private DOMX509IssuerSerial x509IssuerSerial;
36      
37      /**
38       * Constructor.
39       */
40      public DOMX509Data(Element x509DataElement) throws WSSecurityException {
41          element = x509DataElement;
42          //
43          // Parse X509IssuerSerial child
44          //
45          Element issuerSerialElement = 
46              WSSecurityUtil.getDirectChildElement(
47                  element, WSConstants.X509_ISSUER_SERIAL_LN, WSConstants.SIG_NS
48              );
49          x509IssuerSerial = new DOMX509IssuerSerial(issuerSerialElement);
50      }
51  
52      /**
53       * Constructor.
54       */
55      public DOMX509Data(Document doc, DOMX509IssuerSerial domIssuerSerial) {
56          element = 
57              doc.createElementNS(
58                  WSConstants.SIG_NS, WSConstants.SIG_PREFIX + ":" + WSConstants.X509_DATA_LN
59              );
60          
61          element.appendChild(domIssuerSerial.getElement());
62      }
63      
64      /**
65       * Return true if this X509Data element contains a X509IssuerSerial element
66       */
67      public boolean containsIssuerSerial() {
68          if (x509IssuerSerial == null) {
69              return false;
70          }
71          return true;
72      }
73      
74      /**
75       * Return a DOMX509IssuerSerial object in this X509Data structure
76       */
77      public DOMX509IssuerSerial getIssuerSerial() {
78          return x509IssuerSerial;
79      }
80  
81      /**
82       * return the dom element.
83       * 
84       * @return the dom element.
85       */
86      public Element getElement() {
87          return element;
88      }
89  
90      /**
91       * return the string representation of the token.
92       * 
93       * @return the string representation of the token.
94       */
95      public String toString() {
96          return DOM2Writer.nodeToString((Node)element);
97      }
98      
99  }