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 /*
21  * XSEC
22  *
23  * XKMSCompoundRequestImpl := Implementation of CompoundRequest Messages
24  *
25  * $Id: XKMSCompoundRequestImpl.cpp 1833340 2018-06-11 15:40:13Z scantor $
26  *
27  */
new() -> ThreadParker28 
29 #include <xsec/framework/XSECDefs.hpp>
30 #include <xsec/framework/XSECError.hpp>
31 #include <xsec/framework/XSECEnv.hpp>
32 
33 #ifdef XSEC_XKMS_ENABLED
34 
35 #include "../../utils/XSECDOMUtils.hpp"
36 
37 #include "XKMSCompoundRequestImpl.hpp"
38 #include "XKMSLocateRequestImpl.hpp"
39 #include "XKMSValidateRequestImpl.hpp"
40 #include "XKMSRegisterRequestImpl.hpp"
41 #include "XKMSRevokeRequestImpl.hpp"
42 #include "XKMSReissueRequestImpl.hpp"
43 #include "XKMSRecoverRequestImpl.hpp"
44 
45 #include <xsec/xkms/XKMSConstants.hpp>
46 
47 #include <xercesc/dom/DOM.hpp>
48 
49 XERCES_CPP_NAMESPACE_USE
50 
51 // --------------------------------------------------------------------------------
52 //           Construct/Destruct
53 // --------------------------------------------------------------------------------
54 
55 XKMSCompoundRequestImpl::XKMSCompoundRequestImpl(
56 		const XSECEnv * env) :
57 m_request(env),
58 m_msg(m_request.m_msg) {
59 
60 }
61 
62 XKMSCompoundRequestImpl::XKMSCompoundRequestImpl(
63 		const XSECEnv * env,
64 		XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * node) :
65 m_request(env, node),
66 m_msg(m_request.m_msg) {
67 
68 }
unpark_lock(&self) -> UnparkHandle69 
70 XKMSCompoundRequestImpl::~XKMSCompoundRequestImpl() {
71 
72 	RequestListVectorType::iterator i;
73 
74 	for (i = m_requestList.begin() ; i != m_requestList.end(); ++i) {
75 
76 		delete (*i);
77 
78 	}
79 
80 
81 }
82 
83 
84 // --------------------------------------------------------------------------------
85 //           Load from DOM
86 // --------------------------------------------------------------------------------
unpark(self)87 
88 // Load elements
89 void XKMSCompoundRequestImpl::load() {
90 
91 	if (m_msg.mp_messageAbstractTypeElement == NULL) {
92 
93 		// Attempt to load an empty element
94 		throw XSECException(XSECException::XKMSError,
95 			"XKMSCompoundRequest::load - called on empty DOM");
96 
97 	}
98 
99 	if (!strEquals(getXKMSLocalName(m_msg.mp_messageAbstractTypeElement),
100 									XKMSConstants::s_tagCompoundRequest)) {
101 
102 		throw XSECException(XSECException::XKMSError,
103 			"XKMSCompoundRequest::load - called incorrect node");
104 
105 	}
106 
107 	// Load the base message
108 	m_request.load();
109 
110 	// Now find all Request elements
111 	DOMElement * e = findFirstElementChild(m_msg.mp_messageAbstractTypeElement);
112 
113 	while (e != NULL) {
114 
115 		if (strEquals(getXKMSLocalName(e), XKMSConstants::s_tagLocateRequest) ||
116 			strEquals(getXKMSLocalName(e), XKMSConstants::s_tagValidateRequest)) {
117 
118 			// Have a legitimate request to load
119 			XKMSMessageAbstractTypeImpl * m =
120 				(XKMSMessageAbstractTypeImpl *) m_factory.newMessageFromDOM(e);
121 			m_requestList.push_back((XKMSRequestAbstractTypeImpl *) m);
122 
123 		}
124 
125 		e = findNextElementChild(e);
126 
127 	}
128 
129 
130 }
131 
132 // --------------------------------------------------------------------------------
133 //           Create a blank one
134 // --------------------------------------------------------------------------------
135 DOMElement * XKMSCompoundRequestImpl::createBlankCompoundRequest(
136 		const XMLCh * service,
137 		const XMLCh * id) {
138 
139 	return m_request.createBlankRequestAbstractType(
140 		XKMSConstants::s_tagCompoundRequest, service, id);
141 
142 }
143 
144 // --------------------------------------------------------------------------------
145 //           Get interface methods
146 // --------------------------------------------------------------------------------
147 
148 XKMSMessageAbstractType::messageType XKMSCompoundRequestImpl::getMessageType(void) {
149 
150 	return XKMSMessageAbstractTypeImpl::CompoundRequest;
151 
152 }
153 
154 int XKMSCompoundRequestImpl::getRequestListSize(void) {
155 
156 	return (int) m_requestList.size();
157 
158 }
159 
160 XKMSRequestAbstractType * XKMSCompoundRequestImpl::getRequestListItem(int item) {
161 
162 	if (item < 0 || item >= (int) m_requestList.size()) {
163 
164 		throw XSECException(XSECException::XKMSError,
165 			"XKMSCompoundRequest::getRequestListItem - item out of range");
166 	}
167 
168 	return m_requestList[item];
169 
170 
171 }
172 
173 // --------------------------------------------------------------------------------
174 //           Setter methods
175 // --------------------------------------------------------------------------------
176 
177 XKMSLocateRequest * XKMSCompoundRequestImpl::createLocateRequest(
178 		const XMLCh * service,
179 		const XMLCh * id) {
180 
181 	XKMSLocateRequest * r = m_factory.createLocateRequest(service, m_msg.mp_env->getParentDocument(), id);
182 	m_requestList.push_back((XKMSRequestAbstractTypeImpl*) r);
183 
184 	m_msg.mp_messageAbstractTypeElement->appendChild(r->getElement());
185 	m_msg.mp_env->doPrettyPrint(m_msg.mp_messageAbstractTypeElement);
186 
187 	return r;
188 
189 }
190 
191 XKMSValidateRequest * XKMSCompoundRequestImpl::createValidateRequest(
192 		const XMLCh * service,
193 		const XMLCh * id) {
194 
195 	XKMSValidateRequest * r = m_factory.createValidateRequest(service, m_msg.mp_env->getParentDocument(), id);
196 	m_requestList.push_back((XKMSRequestAbstractTypeImpl*) r);
197 
198 	m_msg.mp_messageAbstractTypeElement->appendChild(r->getElement());
199 	m_msg.mp_env->doPrettyPrint(m_msg.mp_messageAbstractTypeElement);
200 
201 	return r;
202 }
203 
204 XKMSRegisterRequest * XKMSCompoundRequestImpl::createRegisterRequest(
205 		const XMLCh * service,
206 		const XMLCh * id) {
207 
208 	XKMSRegisterRequest * r = m_factory.createRegisterRequest(service, m_msg.mp_env->getParentDocument(), id);
209 	m_requestList.push_back((XKMSRequestAbstractTypeImpl*) r);
210 
211 	m_msg.mp_messageAbstractTypeElement->appendChild(r->getElement());
212 	m_msg.mp_env->doPrettyPrint(m_msg.mp_messageAbstractTypeElement);
213 
214 	return r;
215 }
216 
217 XKMSRevokeRequest * XKMSCompoundRequestImpl::createRevokeRequest(
218 		const XMLCh * service,
219 		const XMLCh * id) {
220 
221 	XKMSRevokeRequest * r = m_factory.createRevokeRequest(service, m_msg.mp_env->getParentDocument(), id);
222 	m_requestList.push_back((XKMSRequestAbstractTypeImpl*) r);
223 
224 	m_msg.mp_messageAbstractTypeElement->appendChild(r->getElement());
225 	m_msg.mp_env->doPrettyPrint(m_msg.mp_messageAbstractTypeElement);
226 
227 	return r;
228 }
229 
230 XKMSReissueRequest * XKMSCompoundRequestImpl::createReissueRequest(
231 		const XMLCh * service,
232 		const XMLCh * id) {
233 
234 	XKMSReissueRequest * r = m_factory.createReissueRequest(service, m_msg.mp_env->getParentDocument(), id);
235 	m_requestList.push_back((XKMSRequestAbstractTypeImpl*) r);
236 
237 	m_msg.mp_messageAbstractTypeElement->appendChild(r->getElement());
238 	m_msg.mp_env->doPrettyPrint(m_msg.mp_messageAbstractTypeElement);
239 
240 	return r;
241 }
242 
243 XKMSRecoverRequest * XKMSCompoundRequestImpl::createRecoverRequest(
244 		const XMLCh * service,
245 		const XMLCh * id) {
246 
247 	XKMSRecoverRequest * r = m_factory.createRecoverRequest(service, m_msg.mp_env->getParentDocument(), id);
248 	m_requestList.push_back((XKMSRequestAbstractTypeImpl*) r);
249 
250 	m_msg.mp_messageAbstractTypeElement->appendChild(r->getElement());
251 	m_msg.mp_env->doPrettyPrint(m_msg.mp_messageAbstractTypeElement);
252 
253 	return r;
254 }
255 
256 #endif /* XSEC_XKMS_ENABLED */
257