summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosephKeenan <joseph.keenan@est.tech>2022-01-28 10:02:24 +0000
committerJosephKeenan <joseph.keenan@est.tech>2022-01-28 12:33:28 +0000
commit3c8f982b00c1f20981cecdd25ebb5a027e674cd3 (patch)
treec41f042edcf0e39b496b0faf5814b22c22ac7c63
parenta5ce86d02493f141848f9d609c65883d2198894a (diff)
[TECHDEBT] Align CPS Core REST API Specification and Implementationmr/822/126848/5
Issue-ID: CPS-822 Signed-off-by: JosephKeenan <joseph.keenan@est.tech> Change-Id: Idde7525628f7e1425602069e0d75506ac621113e
-rw-r--r--cps-application/src/test/java/org/onap/cps/architecture/LayeredArchitectureTest.java5
-rw-r--r--cps-rest/docs/openapi/components.yml11
-rw-r--r--cps-rest/docs/openapi/cpsAdmin.yml40
-rw-r--r--cps-rest/docs/openapi/cpsData.yml27
-rw-r--r--cps-rest/docs/openapi/cpsQuery.yml5
5 files changed, 62 insertions, 26 deletions
diff --git a/cps-application/src/test/java/org/onap/cps/architecture/LayeredArchitectureTest.java b/cps-application/src/test/java/org/onap/cps/architecture/LayeredArchitectureTest.java
index bc5ad18963..817bd58351 100644
--- a/cps-application/src/test/java/org/onap/cps/architecture/LayeredArchitectureTest.java
+++ b/cps-application/src/test/java/org/onap/cps/architecture/LayeredArchitectureTest.java
@@ -42,6 +42,7 @@ public class LayeredArchitectureTest {
private static final String SPI_REPOSITORY_PACKAGE = "org.onap.cps.spi.repository..";
private static final String YANG_SCHEMA_PACKAGE = "org.onap.cps.yang..";
private static final String NOTIFICATION_PACKAGE = "org.onap.cps.notification..";
+ private static final String CPS_UTILS_PACKAGE = "org.onap.cps.utils..";
@ArchTest
static final ArchRule restControllerShouldOnlyDependOnRestController =
@@ -49,11 +50,11 @@ public class LayeredArchitectureTest {
.resideInAPackage(REST_CONTROLLER_PACKAGE);
@ArchTest
- static final ArchRule apiOrSpiServiceShouldOnlyBeDependedOnByControllerAndServices =
+ static final ArchRule apiOrSpiServiceShouldOnlyBeDependedOnByControllerAndServicesAndCommonUtilityPackages =
freeze(classes().that().resideInAPackage(API_SERVICE_PACKAGE)
.or().resideInAPackage(SPI_SERVICE_PACKAGE).should().onlyHaveDependentClassesThat()
.resideInAnyPackage(REST_CONTROLLER_PACKAGE, API_SERVICE_PACKAGE, SPI_SERVICE_PACKAGE, NCMP_REST_PACKAGE,
- NCMP_SERVICE_PACKAGE, YANG_SCHEMA_PACKAGE, NOTIFICATION_PACKAGE));
+ NCMP_SERVICE_PACKAGE, YANG_SCHEMA_PACKAGE, NOTIFICATION_PACKAGE, CPS_UTILS_PACKAGE));
@ArchTest
static final ArchRule repositoryShouldOnlyBeDependedOnByServicesAndRepository =
diff --git a/cps-rest/docs/openapi/components.yml b/cps-rest/docs/openapi/components.yml
index ff2816af6d..694c2207af 100644
--- a/cps-rest/docs/openapi/components.yml
+++ b/cps-rest/docs/openapi/components.yml
@@ -1,5 +1,6 @@
# ============LICENSE_START=======================================================
# Copyright (c) 2021 Bell Canada.
+# Modifications Copyright (C) 2021-2022 Nordix Foundation
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -277,6 +278,16 @@ components:
schema:
type: string
example: my-resource
+ InternalServerError:
+ description: Internal Server Error
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/ErrorMessage"
+ example:
+ status: 500
+ message: Internal Server Error
+ details: Internal Server Error occured
NoContent:
description: No Content
content: {}
diff --git a/cps-rest/docs/openapi/cpsAdmin.yml b/cps-rest/docs/openapi/cpsAdmin.yml
index 869cb6e724..a25f81eafc 100644
--- a/cps-rest/docs/openapi/cpsAdmin.yml
+++ b/cps-rest/docs/openapi/cpsAdmin.yml
@@ -1,5 +1,6 @@
# ============LICENSE_START=======================================================
# Copyright (c) 2021 Bell Canada.
+# Modifications Copyright (C) 2021-2022 Nordix Foundation
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -28,13 +29,14 @@ dataspaces:
responses:
'201':
$ref: 'components.yml#/components/responses/Created'
- '400':
- $ref: 'components.yml#/components/responses/BadRequest'
'401':
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
-
+ '409':
+ $ref: 'components.yml#/components/responses/Conflict'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
delete:
description: Delete a dataspace
tags:
@@ -54,6 +56,8 @@ dataspaces:
$ref: 'components.yml#/components/responses/Forbidden'
'409':
$ref: 'components.yml#/components/responses/Conflict'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
schemaSet:
post:
@@ -71,7 +75,6 @@ schemaSet:
multipart/form-data:
schema:
$ref: 'components.yml#/components/schemas/MultipartFile'
-
responses:
'201':
$ref: 'components.yml#/components/responses/Created'
@@ -81,6 +84,10 @@ schemaSet:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
+ '409':
+ $ref: 'components.yml#/components/responses/Conflict'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
schemaSetBySchemaSetName:
get:
@@ -105,9 +112,8 @@ schemaSetBySchemaSetName:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
- '404':
- $ref: 'components.yml#/components/responses/NotFound'
-
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
delete:
description: Delete a schema set given a schema set name and a dataspace
tags:
@@ -128,6 +134,8 @@ schemaSetBySchemaSetName:
$ref: 'components.yml#/components/responses/Forbidden'
'409':
$ref: 'components.yml#/components/responses/Conflict'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
anchorsByDataspace:
get:
@@ -153,9 +161,8 @@ anchorsByDataspace:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
- '404':
- $ref: 'components.yml#/components/responses/NotFound'
-
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
post:
description: Create a new anchor in the given dataspace
tags:
@@ -175,6 +182,10 @@ anchorsByDataspace:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
+ '409':
+ $ref: 'components.yml#/components/responses/Conflict'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
anchorByDataspaceAndAnchorName:
get:
@@ -199,9 +210,8 @@ anchorByDataspaceAndAnchorName:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
- '404':
- $ref: 'components.yml#/components/responses/NotFound'
-
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
delete:
description: Delete an anchor given an anchor name and a dataspace
tags:
@@ -219,4 +229,6 @@ anchorByDataspaceAndAnchorName:
'401':
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
- $ref: 'components.yml#/components/responses/Forbidden' \ No newline at end of file
+ $ref: 'components.yml#/components/responses/Forbidden'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError' \ No newline at end of file
diff --git a/cps-rest/docs/openapi/cpsData.yml b/cps-rest/docs/openapi/cpsData.yml
index 15f8a1c71b..099512d7dc 100644
--- a/cps-rest/docs/openapi/cpsData.yml
+++ b/cps-rest/docs/openapi/cpsData.yml
@@ -1,5 +1,6 @@
# ============LICENSE_START=======================================================
# Copyright (c) 2021 Bell Canada.
+# Modifications Copyright (C) 2021-2022 Nordix Foundation
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -44,8 +45,8 @@ nodeByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
- '404':
- $ref: 'components.yml#/components/responses/NotFound'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
x-codegen-request-body-name: xpath
listElementByDataspaceAndAnchor:
@@ -78,7 +79,8 @@ listElementByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
-
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
put:
description: Replace list content under a given parent, anchor and dataspace
tags:
@@ -108,7 +110,8 @@ listElementByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
-
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
delete:
description: Delete one or all list element(s) for a given anchor and dataspace
deprecated: true
@@ -130,6 +133,8 @@ listElementByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
nodesByDataspaceAndAnchor:
post:
@@ -161,7 +166,10 @@ nodesByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
-
+ '409':
+ $ref: 'components.yml#/components/responses/Conflict'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
patch:
description: Update a data node leaves for a given dataspace and anchor and a parent node xpath
tags:
@@ -191,7 +199,8 @@ nodesByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
-
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
delete:
description: Delete a datanode for a given dataspace and anchor given a node xpath.
tags:
@@ -212,8 +221,8 @@ nodesByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
-
-
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
put:
description: Replace a node with descendants for a given dataspace, anchor and a parent node xpath
tags:
@@ -243,3 +252,5 @@ nodesByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
diff --git a/cps-rest/docs/openapi/cpsQuery.yml b/cps-rest/docs/openapi/cpsQuery.yml
index 4f938aa891..06c9ca2a24 100644
--- a/cps-rest/docs/openapi/cpsQuery.yml
+++ b/cps-rest/docs/openapi/cpsQuery.yml
@@ -1,5 +1,6 @@
# ============LICENSE_START=======================================================
# Copyright (C) 2021 Nordix Foundation
+# Copyright (C) 2021-2022 Nordix Foundation
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -44,6 +45,6 @@ nodesByDataspaceAndAnchorAndCpsPath:
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
$ref: 'components.yml#/components/responses/Forbidden'
- '404':
- $ref: 'components.yml#/components/responses/NotFound'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
x-codegen-request-body-name: xpath
class="nn">org.onap.portalsdk.core.domain.RoleFunction; import org.onap.portalsdk.core.domain.User; import org.onap.portalsdk.core.domain.UserApp; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.util.CipherUtil; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.portalsdk.external.authorization.domain.ExternalAccessPerms; import org.onap.portalsdk.external.authorization.domain.ExternalAccessRole; import org.onap.portalsdk.external.authorization.domain.ExternalAccessUserRoleDetail; import org.onap.portalsdk.external.authorization.exception.UserNotFoundException; import org.onap.portalsdk.external.authorization.service.AAFRestServiceImpl; import org.onap.portalsdk.external.authorization.service.AAFService; import org.onap.portalsdk.external.authorization.util.EcompExternalAuthProperties; import org.onap.portalsdk.external.authorization.util.EcompExternalAuthUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.TypeFactory; @Service("userApiService") public class UserApiServiceImpl implements UserApiService { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserApiServiceImpl.class); @Autowired private LoginExternalAuthService loginAAFService; @Autowired private LdapService ldapService; @Autowired private PostSearchService postSearchService; @Autowired private DataAccessService dataAccessService; RestTemplate template = new RestTemplate(); @Autowired private AppService appService; private AAFService aafService = new AAFRestServiceImpl(); @Override public User getUser(String orgUserId, HttpServletRequest request) throws UserNotFoundException { User user = null; try { String namespace = EcompExternalAuthProperties .getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_NAMESPACE); HttpHeaders headers = getBasicAuthHeaders(); String userRoles = aafService.getUser(orgUserId, request, headers); ObjectMapper mapper = new ObjectMapper(); List<ExternalAccessUserRoleDetail> userRoleDetailList = setExternalAccessUserRoles(namespace, userRoles, mapper); if (userRoleDetailList.isEmpty()) { throw new UserNotFoundException("User roles not found!"); } else { user = convertAAFUserRolesToEcompSDKUser(userRoleDetailList, orgUserId, namespace, request); } } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "getUser: Failed! ", e); } return user; } private List<ExternalAccessUserRoleDetail> setExternalAccessUserRoles(String namespace, String userRoles, ObjectMapper mapper) throws IOException, JsonParseException, JsonMappingException, UserNotFoundException { JSONObject userJsonObj; JSONArray userJsonArray; List<ExternalAccessUserRoleDetail> userRoleDetailList = new ArrayList<>(); if (!userRoles.equals(EcompExternalAuthUtils.EXT_EMPTY_JSON_STRING)) { userJsonObj = new JSONObject(userRoles); userJsonArray = userJsonObj.getJSONArray(EcompExternalAuthUtils.EXT_ROLE_FIELD); ExternalAccessUserRoleDetail userRoleDetail = null; for (int i = 0; i < userJsonArray.length(); i++) { JSONObject role = userJsonArray.getJSONObject(i); if (!role.getString(EcompExternalAuthUtils.EXT_ROLE_FIELD_NAME) .endsWith(EcompExternalAuthUtils.EXT_ROLE_FIELD_ADMIN) && !role.getString(EcompExternalAuthUtils.EXT_ROLE_FIELD_NAME) .endsWith(EcompExternalAuthUtils.EXT_ROLE_FIELD_OWNER)) { List<ExternalAccessPerms> ecPerms = new ArrayList<>(); if (role.has(EcompExternalAuthUtils.EXT_FIELD_PERMS)) { JSONArray perms = role.getJSONArray(EcompExternalAuthUtils.EXT_FIELD_PERMS); ecPerms = mapper.readValue(perms.toString(), TypeFactory.defaultInstance() .constructCollectionType(List.class, ExternalAccessPerms.class)); } ExternalAccessRole ecRole = new ExternalAccessRole( role.getString(EcompExternalAuthUtils.EXT_ROLE_FIELD_NAME), ecPerms); userRoleDetail = new ExternalAccessUserRoleDetail(ecRole); userRoleDetailList.add(userRoleDetail); } } } else { throw new UserNotFoundException("User roles not found!"); } return userRoleDetailList; } private User convertAAFUserRolesToEcompSDKUser(List<ExternalAccessUserRoleDetail> userRoleDetailList, String orgUserId, String namespace, HttpServletRequest request) throws Exception { User user = loginAAFService.findUserWithoutPwd(orgUserId); PostSearchBean postSearchBean = new PostSearchBean(); if (user == null) { postSearchBean.setOrgUserId(orgUserId); postSearchService.process(request, postSearchBean); postSearchBean.setSearchResult(loadSearchResultData(postSearchBean)); user = (User) postSearchBean.getSearchResult().get(0); user.setActive(true); user.setLoginId(orgUserId); dataAccessService.saveDomainObject(user, null); } App app = appService.getApp(1l); try { Set userApps = setUserApps(userRoleDetailList, namespace, user, app); user.setUserApps(userApps); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "createEPUser: createEPUser failed", e); throw e; } return user; } @SuppressWarnings({ "rawtypes", "unchecked" }) private Set setUserApps(List<ExternalAccessUserRoleDetail> userRoleDetailList, String namespace, User user, App app) { Set userApps = new TreeSet(); //As External Auth System does not provide roleId's we are setting counter value for roleId. These values should not be stored in DB. Long tempRoleId = 0l; for (ExternalAccessUserRoleDetail userRoleDetail : userRoleDetailList) { ExternalAccessRole ecRole = userRoleDetail.getRole(); UserApp userApp = new UserApp(); Role role = new Role(); Set roleFunctions = new TreeSet<>(); role.setId(tempRoleId); role.setActive(true); role.setName(ecRole.getName()); for (ExternalAccessPerms extPerm : ecRole.getPerms()) { RoleFunction roleFunction = new RoleFunction(); roleFunction.setCode(extPerm.getInstance()); roleFunction.setAction(extPerm.getAction()); if (extPerm.getDescription() != null && EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { roleFunction.setName(extPerm.getDescription()); } else if (extPerm.getDescription() == null && EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { roleFunction.setName(extPerm.getType().substring(namespace.length() + 1) + "|" + extPerm.getInstance() + "|" + extPerm.getAction()); } else if (extPerm.getDescription() == null && !EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { roleFunction.setName(extPerm.getType() + "|" + extPerm.getInstance() + "|" + extPerm.getAction()); } if (EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { roleFunction.setType(extPerm.getType().substring(namespace.length() + 1)); } else { roleFunction.setType(extPerm.getType()); } roleFunctions.add(roleFunction); } role.setRoleFunctions(roleFunctions); userApp.setApp(app); userApp.setRole(role); userApp.setUserId(user.getId()); userApps.add(userApp); tempRoleId++; } return userApps; } @Override public List<RoleFunction> getRoleFunctions(String orgUserId) throws Exception { HttpHeaders headers = getBasicAuthHeaders(); return aafService.getRoleFunctions(orgUserId, headers); } @SuppressWarnings("unused") private ResponseEntity<String> getPermsFromExternalAuthSystem(HttpEntity<String> entity, String endPoint) { ResponseEntity<String> getResponse = template.exchange( EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_URL) + endPoint, HttpMethod.GET, entity, String.class); if (getResponse.getStatusCode().value() == 200) { logger.debug(EELFLoggerDelegate.debugLogger, "getPermsFromExternalAuthSystem: Finished GET user perms from external auth system and body: {}", getResponse.getBody()); } return getResponse; } private HttpHeaders getBasicAuthHeaders() throws Exception { String userName = EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_USER_NAME); String encryptedPass = EcompExternalAuthProperties .getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_PASSWORD); String decryptedPass = decryptPass(encryptedPass); return EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth(userName, decryptedPass); } public static String decryptPass(String encrypted) throws Exception { String result = ""; if (encrypted != null && encrypted.length() > 0) { try { result = CipherUtil.decryptPKC(encrypted, SystemProperties.getProperty(SystemProperties.Decryption_Key)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed", e); throw e; } } return result; } private SearchResult loadSearchResultData(PostSearchBean searchCriteria) throws NamingException { return ldapService.searchPost(searchCriteria.getUser(), searchCriteria.getSortBy1(), searchCriteria.getSortBy2(), searchCriteria.getSortBy3(), searchCriteria.getPageNo(), searchCriteria.getNewDataSize(), 1); } @Override public ResponseEntity<String> checkUserExists(String username, String password) throws Exception { String encryptedPass = EcompExternalAuthProperties .getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_PASSWORD); String appPassword = decryptPass(encryptedPass); return aafService.checkUserExists(username, password, appPassword); } @Override public List<ExternalAccessPerms> getIfUserPermsExists(String username) throws Exception { HttpHeaders headers = getBasicAuthHeaders(); return aafService.getIfUserPermsExists(username, headers); } }