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 * Constructor.
63 */
64 public DOMX509Data(Document doc, DOMX509SKI x509SKI) {
65 element =
66 doc.createElementNS(WSS4JConstants.SIG_NS, "ds:X509Data");
67
68 element.appendChild(x509SKI.getElement());
69 }
70
71 /**
72 * Return true if this X509Data element contains a X509IssuerSerial element
73 */
74 public boolean containsIssuerSerial() {
75 return x509IssuerSerial != null;
76 }
77
78 /**
79 * Return a DOMX509IssuerSerial object in this X509Data structure
80 */
81 public DOMX509IssuerSerial getIssuerSerial() {
82 return x509IssuerSerial;
83 }
84
85 /**
86 * return the dom element.
87 *
88 * @return the dom element.
89 */
90 public Element getElement() {
91 return element;
92 }
93
94 /**
95 * return the string representation of the token.
96 *
97 * @return the string representation of the token.
98 */
99 public String toString() {
100 return DOM2Writer.nodeToString(element);
101 }
102
103 }