2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.openecomp.crud.service;
26 import org.apache.cxf.jaxrs.ext.PATCH;
27 import org.openecomp.auth.Auth;
28 import org.openecomp.cl.api.Logger;
29 import org.openecomp.cl.eelf.LoggerFactory;
30 import org.openecomp.crud.exception.CrudException;
31 import org.openecomp.crud.logging.CrudServiceMsgs;
32 import org.openecomp.crud.logging.LoggingUtil;
33 import org.openecomp.crud.util.CrudServiceConstants;
36 import java.security.cert.X509Certificate;
37 import java.util.HashMap;
38 import java.util.List;
40 import javax.security.auth.x500.X500Principal;
41 import javax.servlet.http.HttpServletRequest;
42 import javax.ws.rs.Consumes;
43 import javax.ws.rs.DELETE;
44 import javax.ws.rs.Encoded;
45 import javax.ws.rs.GET;
46 import javax.ws.rs.POST;
47 import javax.ws.rs.PUT;
48 import javax.ws.rs.Path;
49 import javax.ws.rs.PathParam;
50 import javax.ws.rs.Produces;
51 import javax.ws.rs.core.Context;
52 import javax.ws.rs.core.HttpHeaders;
53 import javax.ws.rs.core.MediaType;
54 import javax.ws.rs.core.Response;
55 import javax.ws.rs.core.Response.Status;
56 import javax.ws.rs.core.UriInfo;
58 public class CrudRestService {
60 private CrudGraphDataService crudGraphDataService;
61 Logger logger = LoggerFactory.getInstance().getLogger(CrudRestService.class.getName());
62 Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(CrudRestService.class.getName());
65 private String mediaType = MediaType.APPLICATION_JSON;
66 public static final String HTTP_PATCH_METHOD_OVERRIDE = "X-HTTP-Method-Override";
68 public CrudRestService(CrudGraphDataService crudGraphDataService) throws Exception {
69 this.crudGraphDataService = crudGraphDataService;
70 this.auth = new Auth(CrudServiceConstants.CRD_AUTH_FILE);
74 POST, GET, PUT, DELETE, PATCH
79 public void startup() {
84 @Path("/{version}/{type}/{id}")
85 @Consumes({MediaType.APPLICATION_JSON})
86 @Produces({MediaType.APPLICATION_JSON})
87 public Response getVertex(String content, @PathParam("version") String version,
88 @PathParam("type") String type, @PathParam("id") String id,
89 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
90 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
91 LoggingUtil.initMdcContext(req, headers);
93 logger.debug("Incoming request..." + content);
94 Response response = null;
96 if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
99 String result = crudGraphDataService.getVertex(version, id, type);
100 response = Response.status(Status.OK).entity(result).type(mediaType).build();
101 } catch (CrudException ce) {
102 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
103 } catch (Exception e) {
104 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
107 response = Response.status(Status.FORBIDDEN).entity(content)
108 .type(MediaType.APPLICATION_JSON).build();
111 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
116 @Path("/{version}/{type}/")
117 @Consumes({MediaType.APPLICATION_JSON})
118 @Produces({MediaType.APPLICATION_JSON})
119 public Response getVertices(String content, @PathParam("version") String version,
120 @PathParam("type") String type, @PathParam("uri") @Encoded String uri,
121 @Context HttpHeaders headers, @Context UriInfo uriInfo,
122 @Context HttpServletRequest req) {
124 LoggingUtil.initMdcContext(req, headers);
126 logger.debug("Incoming request..." + content);
127 Response response = null;
128 if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
130 Map<String, String> filter = new HashMap<String, String>();
131 for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
132 filter.put(e.getKey(), e.getValue().get(0));
136 String result = crudGraphDataService.getVertices(version, type, filter);
137 response = Response.status(Status.OK).entity(result).type(mediaType).build();
138 } catch (CrudException ce) {
139 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
140 } catch (Exception e) {
141 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
144 response = Response.status(Status.FORBIDDEN).entity(content)
145 .type(MediaType.APPLICATION_JSON).build();
148 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
153 @Path("/relationships/{version}/{type}/{id}")
154 @Consumes({MediaType.APPLICATION_JSON})
155 @Produces({MediaType.APPLICATION_JSON})
156 public Response getEdge(String content, @PathParam("version") String version,
157 @PathParam("type") String type, @PathParam("id") String id,
158 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
159 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
160 LoggingUtil.initMdcContext(req, headers);
162 logger.debug("Incoming request..." + content);
163 Response response = null;
165 if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
169 String result = crudGraphDataService.getEdge(version, id, type);
170 response = Response.status(Status.OK).entity(result).type(mediaType).build();
171 } catch (CrudException ce) {
172 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
173 } catch (Exception e) {
174 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
177 response = Response.status(Status.FORBIDDEN).entity(content)
178 .type(MediaType.APPLICATION_JSON).build();
181 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
186 @Path("/relationships/{version}/{type}/")
187 @Consumes({MediaType.APPLICATION_JSON})
188 @Produces({MediaType.APPLICATION_JSON})
189 public Response getEdges(String content, @PathParam("version") String version,
190 @PathParam("type") String type, @PathParam("uri") @Encoded String uri,
191 @Context HttpHeaders headers, @Context UriInfo uriInfo,
192 @Context HttpServletRequest req) {
194 LoggingUtil.initMdcContext(req, headers);
196 logger.debug("Incoming request..." + content);
197 Response response = null;
199 if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
201 Map<String, String> filter = new HashMap<String, String>();
202 for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
203 filter.put(e.getKey(), e.getValue().get(0));
207 String result = crudGraphDataService.getEdges(version, type, filter);
208 response = Response.status(Status.OK).entity(result).type(mediaType).build();
209 } catch (CrudException ce) {
210 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
211 } catch (Exception e) {
212 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
215 response = Response.status(Status.FORBIDDEN).entity(content)
216 .type(MediaType.APPLICATION_JSON).build();
220 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
225 @Path("/relationships/{version}/{type}/{id}")
226 @Consumes({MediaType.APPLICATION_JSON})
227 @Produces({MediaType.APPLICATION_JSON})
228 public Response updateEdge(String content, @PathParam("version") String version,
229 @PathParam("type") String type, @PathParam("id") String id,
230 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
231 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
233 LoggingUtil.initMdcContext(req, headers);
235 logger.debug("Incoming request..." + content);
236 Response response = null;
238 if (validateRequest(req, uri, content, Action.PUT, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
241 EdgePayload payload = EdgePayload.fromJson(content);
242 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
243 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
245 if (payload.getId() != null && !payload.getId().equals(id)) {
246 throw new CrudException("ID Mismatch", Status.BAD_REQUEST);
250 if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null
251 && headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE)
252 .equalsIgnoreCase("PATCH")) {
253 result = crudGraphDataService.patchEdge(version, id, type, payload);
256 result = crudGraphDataService.updateEdge(version, id, type, payload);
259 response = Response.status(Status.OK).entity(result).type(mediaType).build();
260 } catch (CrudException ce) {
261 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
262 } catch (Exception e) {
263 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
266 response = Response.status(Status.FORBIDDEN).entity(content)
267 .type(MediaType.APPLICATION_JSON).build();
271 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
276 @Path("/relationships/{version}/{type}/{id}")
277 @Consumes({"application/merge-patch+json"})
278 @Produces({MediaType.APPLICATION_JSON})
279 public Response patchEdge(String content, @PathParam("version") String version,
280 @PathParam("type") String type, @PathParam("id") String id,
281 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
282 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
284 LoggingUtil.initMdcContext(req, headers);
286 logger.debug("Incoming request..." + content);
287 Response response = null;
288 if (validateRequest(req, uri, content, Action.PATCH,
289 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
292 EdgePayload payload = EdgePayload.fromJson(content);
293 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
294 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
296 if (payload.getId() != null && !payload.getId().equals(id)) {
297 throw new CrudException("ID Mismatch", Status.BAD_REQUEST);
300 String result = crudGraphDataService.patchEdge(version, id, type, payload);
301 response = Response.status(Status.OK).entity(result).type(mediaType).build();
302 } catch (CrudException ce) {
303 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
304 } catch (Exception e) {
305 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
308 response = Response.status(Status.FORBIDDEN).entity(content)
309 .type(MediaType.APPLICATION_JSON).build();
312 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
317 @Path("/{version}/{type}/{id}")
318 @Consumes({MediaType.APPLICATION_JSON})
319 @Produces({MediaType.APPLICATION_JSON})
320 public Response updateVertex(String content, @PathParam("version") String version,
321 @PathParam("type") String type, @PathParam("id") String id,
322 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
323 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
325 LoggingUtil.initMdcContext(req, headers);
327 logger.debug("Incoming request..." + content);
328 Response response = null;
330 if (validateRequest(req, uri, content, Action.PUT, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
333 VertexPayload payload = VertexPayload.fromJson(content);
334 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
335 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
337 if (payload.getId() != null && !payload.getId().equals(id)) {
338 throw new CrudException("ID Mismatch", Status.BAD_REQUEST);
341 if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null
342 && headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE)
343 .equalsIgnoreCase("PATCH")) {
344 result = crudGraphDataService.patchVertex(version, id, type, payload);
347 result = crudGraphDataService.updateVertex(version, id, type, payload);
349 response = Response.status(Status.OK).entity(result).type(mediaType).build();
350 } catch (CrudException ce) {
351 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
352 } catch (Exception e) {
353 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
356 response = Response.status(Status.FORBIDDEN).entity(content)
357 .type(MediaType.APPLICATION_JSON).build();
360 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
365 @Path("/{version}/{type}/{id}")
366 @Consumes({"application/merge-patch+json"})
367 @Produces({MediaType.APPLICATION_JSON})
368 public Response patchVertex(String content, @PathParam("version") String version,
369 @PathParam("type") String type, @PathParam("id") String id,
370 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
371 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
373 LoggingUtil.initMdcContext(req, headers);
375 logger.debug("Incoming request..." + content);
376 Response response = null;
378 if (validateRequest(req, uri, content, Action.PATCH,
379 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
381 VertexPayload payload = VertexPayload.fromJson(content);
382 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
383 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
385 if (payload.getId() != null && !payload.getId().equals(id)) {
386 throw new CrudException("ID Mismatch", Status.BAD_REQUEST);
389 String result = crudGraphDataService.patchVertex(version, id, type, payload);
390 response = Response.status(Status.OK).entity(result).type(mediaType).build();
391 } catch (CrudException ce) {
392 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
393 } catch (Exception e) {
394 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
397 response = Response.status(Status.FORBIDDEN).entity(content)
398 .type(MediaType.APPLICATION_JSON).build();
401 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
406 @Path("/{version}/{type}/")
407 @Consumes({MediaType.APPLICATION_JSON})
408 @Produces({MediaType.APPLICATION_JSON})
409 public Response addVertex(String content, @PathParam("version") String version,
410 @PathParam("type") String type, @PathParam("uri") @Encoded String uri,
411 @Context HttpHeaders headers, @Context UriInfo uriInfo,
412 @Context HttpServletRequest req) {
414 LoggingUtil.initMdcContext(req, headers);
416 logger.debug("Incoming request..." + content);
417 Response response = null;
419 if (validateRequest(req, uri, content, Action.POST,
420 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
423 VertexPayload payload = VertexPayload.fromJson(content);
424 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
425 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
427 if (payload.getId() != null) {
428 throw new CrudException("ID specified , use Http PUT to update Vertex",
432 if (payload.getType() != null && !payload.getType().equals(type)) {
433 throw new CrudException("Vertex Type mismatch", Status.BAD_REQUEST);
436 String result = crudGraphDataService.addVertex(version, type, payload);
437 response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
438 } catch (CrudException ce) {
439 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
440 } catch (Exception e) {
441 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
444 response = Response.status(Status.FORBIDDEN).entity(content)
445 .type(MediaType.APPLICATION_JSON).build();
448 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
454 @Consumes({MediaType.APPLICATION_JSON})
455 @Produces({MediaType.APPLICATION_JSON})
456 public Response addVertex(String content, @PathParam("version") String version,
457 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
458 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
460 LoggingUtil.initMdcContext(req, headers);
462 logger.debug("Incoming request..." + content);
463 Response response = null;
465 if (validateRequest(req, uri, content, Action.POST,
466 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
469 VertexPayload payload = VertexPayload.fromJson(content);
470 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
471 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
473 if (payload.getId() != null) {
474 throw new CrudException("ID specified , use Http PUT to update Vertex",
478 if (payload.getType() == null || payload.getType().isEmpty()) {
479 throw new CrudException("Missing Vertex Type ", Status.BAD_REQUEST);
481 String result = crudGraphDataService.addVertex(version, payload.getType(), payload);
482 response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
483 } catch (CrudException ce) {
484 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
485 } catch (Exception e) {
486 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
489 response = Response.status(Status.FORBIDDEN).entity(content)
490 .type(MediaType.APPLICATION_JSON).build();
493 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
498 @Path("/relationships/{version}/{type}/")
499 @Consumes({MediaType.APPLICATION_JSON})
500 @Produces({MediaType.APPLICATION_JSON})
501 public Response addEdge(String content, @PathParam("version") String version,
502 @PathParam("type") String type, @PathParam("uri") @Encoded String uri,
503 @Context HttpHeaders headers, @Context UriInfo uriInfo,
504 @Context HttpServletRequest req) {
506 LoggingUtil.initMdcContext(req, headers);
508 logger.debug("Incoming request..." + content);
509 Response response = null;
511 if (validateRequest(req, uri, content, Action.POST,
512 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
516 EdgePayload payload = EdgePayload.fromJson(content);
517 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
518 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
520 if (payload.getId() != null) {
521 throw new CrudException("ID specified , use Http PUT to update Edge", Status.BAD_REQUEST);
524 if (payload.getType() != null && !payload.getType().equals(type)) {
525 throw new CrudException("Edge Type mismatch", Status.BAD_REQUEST);
527 String result = crudGraphDataService.addEdge(version, type, payload);
528 response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
529 } catch (CrudException ce) {
530 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
531 } catch (Exception e) {
532 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
535 response = Response.status(Status.FORBIDDEN).entity(content)
536 .type(MediaType.APPLICATION_JSON).build();
539 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
544 @Path("/relationships/{version}/")
545 @Consumes({MediaType.APPLICATION_JSON})
546 @Produces({MediaType.APPLICATION_JSON})
547 public Response addEdge(String content, @PathParam("version") String version,
548 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
549 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
551 LoggingUtil.initMdcContext(req, headers);
553 logger.debug("Incoming request..." + content);
554 Response response = null;
556 if (validateRequest(req, uri, content, Action.POST,
557 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
561 EdgePayload payload = EdgePayload.fromJson(content);
562 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
563 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
565 if (payload.getId() != null) {
566 throw new CrudException("ID specified , use Http PUT to update Edge", Status.BAD_REQUEST);
569 if (payload.getType() == null || payload.getType().isEmpty()) {
570 throw new CrudException("Missing Edge Type ", Status.BAD_REQUEST);
572 String result = crudGraphDataService.addEdge(version, payload.getType(), payload);
574 response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
575 } catch (CrudException ce) {
576 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
577 } catch (Exception e) {
578 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
581 response = Response.status(Status.FORBIDDEN).entity(content)
582 .type(MediaType.APPLICATION_JSON).build();
585 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
590 @Path("/{version}/{type}/{id}")
591 @Consumes({MediaType.APPLICATION_JSON})
592 @Produces({MediaType.APPLICATION_JSON})
593 public Response deleteVertex(String content, @PathParam("version") String version,
594 @PathParam("type") String type, @PathParam("id") String id,
595 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
596 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
598 LoggingUtil.initMdcContext(req, headers);
600 logger.debug("Incoming request..." + content);
601 Response response = null;
603 if (validateRequest(req, uri, content, Action.DELETE,
604 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
608 String result = crudGraphDataService.deleteVertex(version, id, type);
609 response = Response.status(Status.OK).entity(result).type(mediaType).build();
610 } catch (CrudException ce) {
611 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
612 } catch (Exception e) {
613 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
616 response = Response.status(Status.FORBIDDEN).entity(content)
617 .type(MediaType.APPLICATION_JSON).build();
620 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
625 @Path("/relationships/{version}/{type}/{id}")
626 @Consumes({MediaType.APPLICATION_JSON})
627 @Produces({MediaType.APPLICATION_JSON})
628 public Response deleteEdge(String content, @PathParam("version") String version,
629 @PathParam("type") String type, @PathParam("id") String id,
630 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
631 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
633 LoggingUtil.initMdcContext(req, headers);
635 logger.debug("Incoming request..." + content);
636 Response response = null;
637 if (validateRequest(req, uri, content, Action.DELETE,
638 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
641 String result = crudGraphDataService.deleteEdge(version, id, type);
642 response = Response.status(Status.OK).entity(result).type(mediaType).build();
643 } catch (CrudException ce) {
644 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
645 } catch (Exception e) {
646 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
649 response = Response.status(Status.FORBIDDEN).entity(content)
650 .type(MediaType.APPLICATION_JSON).build();
653 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
657 protected boolean validateRequest(HttpServletRequest req, String uri, String content,
658 Action action, String authPolicyFunctionName) {
660 String cipherSuite = (String) req.getAttribute("javax.servlet.request.cipher_suite");
661 String authUser = null;
662 if (cipherSuite != null) {
663 X509Certificate[] certChain = (X509Certificate[]) req
664 .getAttribute("javax.servlet.request.X509Certificate");
665 X509Certificate clientCert = certChain[0];
666 X500Principal subjectDn = clientCert.getSubjectX500Principal();
667 authUser = subjectDn.toString();
669 return this.auth.validateRequest(authUser.toLowerCase(), action.toString()
670 + ":" + authPolicyFunctionName);
671 } catch (Exception e) {
672 logResult(action, uri, e);
677 void logResult(Action op, String uri, Exception e) {
679 logger.error(CrudServiceMsgs.EXCEPTION_DURING_METHOD_CALL, op.toString(), uri,
680 e.getStackTrace().toString());
682 // Clear the MDC context so that no other transaction inadvertently
683 // uses our transaction id.