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.wss4j.common.token;
21  
22  import org.apache.wss4j.common.WSS4JConstants;
23  import org.apache.wss4j.common.ext.WSSecurityException;
24  import org.apache.wss4j.common.util.DOM2Writer;
25  import org.apache.wss4j.common.util.XMLUtils;
26  import org.w3c.dom.Document;
27  import org.w3c.dom.Element;
28  
29  /**
30   * An X509Data token.
31   */
32  public final class DOMX509Data {
33      private final Element element;
34      private DOMX509IssuerSerial x509IssuerSerial;
35  
36      /**
37       * Constructor.
38       */
39      public DOMX509Data(Element x509DataElement) throws WSSecurityException {
40          element = x509DataElement;
41          //
42          // Parse X509IssuerSerial child
43          //
44          Element issuerSerialElement =
45              XMLUtils.getDirectChildElement(
46                  element, "X509IssuerSerial", WSS4JConstants.SIG_NS
47              );
48          x509IssuerSerial = new DOMX509IssuerSerial(issuerSerialElement);
49      }
50  
51      /**
52       * Constructor.
53       */
54      public DOMX509Data(Document doc, DOMX509IssuerSerial domIssuerSerial) {
55          element =
56              doc.createElementNS(WSS4JConstants.SIG_NS, "ds:X509Data");
57  
58          element.appendChild(domIssuerSerial.getElement());
59      }
60  
61      /**
62       * Return true if this X509Data element contains a X509IssuerSerial element
63       */
64      public boolean containsIssuerSerial() {
65          return x509IssuerSerial != null;
66      }
67  
68      /**
69       * Return a DOMX509IssuerSerial object in this X509Data structure
70       */
71      public DOMX509IssuerSerial getIssuerSerial() {
72          return x509IssuerSerial;
73      }
74  
75      /**
76       * return the dom element.
77       *
78       * @return the dom element.
79       */
80      public Element getElement() {
81          return element;
82      }
83  
84      /**
85       * return the string representation of the token.
86       *
87       * @return the string representation of the token.
88       */
89      public String toString() {
90          return DOM2Writer.nodeToString(element);
91      }
92  
93  }