/**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 European Software Marketing Ltd.
+ * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2019 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.service;
import com.google.gson.Gson;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.onap.aai.babel.service.data.BabelRequest;
import org.onap.aai.babel.util.RequestValidationException;
import org.onap.aai.babel.util.RequestValidator;
+import org.springframework.stereotype.Service;
/** Generate SDC Artifacts by passing in a CSAR payload, Artifact Name and Artifact version */
+@Service
public class GenerateArtifactsServiceImpl implements GenerateArtifactsService {
private static final LogHelper applicationLogger = LogHelper.INSTANCE;
private AAIMicroServiceAuth aaiMicroServiceAuth;
- /** @param authorization */
+ /**
+ * @param authorization
+ */
@Inject
public GenerateArtifactsServiceImpl(final AAIMicroServiceAuth authorization) {
this.aaiMicroServiceAuth = authorization;
Response response;
try {
+ // Get last URI path segment to use for authentication
+ List<PathSegment> pathSegments = uriInfo.getPathSegments();
+ String lastPathSegment = pathSegments.isEmpty() ? "" : pathSegments.get(pathSegments.size() - 1).getPath();
+
boolean authorized = aaiMicroServiceAuth.validateRequest(headers, servletRequest,
- AAIMicroServiceAuthCore.HTTP_METHODS.POST, uriInfo.getPath(false));
+ AAIMicroServiceAuthCore.HTTP_METHODS.POST, lastPathSegment);
response = authorized ? generateArtifacts(requestBody)
: buildResponse(Status.UNAUTHORIZED, "User not authorized to perform the operation.");
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
BabelRequest babelRequest = gson.fromJson(requestBody, BabelRequest.class);
- RequestValidator.validateRequest(babelRequest);
+ new RequestValidator().validateRequest(babelRequest);
byte[] csarFile = Base64.getDecoder().decode(babelRequest.getCsar());
List<BabelArtifact> babelArtifacts = new CsarToXmlConverter().generateXmlFromCsar(csarFile,