summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common/src/main
diff options
context:
space:
mode:
authorGUJJA <kg811t@research.att.com>2018-02-22 12:21:33 -0500
committerGUJJA <kg811t@research.att.com>2018-02-22 12:22:29 -0500
commitf59a56b7c12badbb41bb2155b6de47e9c9c48bcd (patch)
tree9911a3b302494fb1c6cd2798a97d680a38a04217 /ecomp-portal-BE-common/src/main
parentad024fa2186f73cfb54ecc3cd422d57d7ea87f93 (diff)
Added Junits
Issue-ID: PORTAL-136 Includes JUNITS Change-Id: I859aa9de0ce51a1ac699c81e98c2af7fda7ae660 Signed-off-by:GUJJA <kg811t@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common/src/main')
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/config/SecurityInitializer.java44
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java39
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPAppMessagesEnum.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java18
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java63
5 files changed, 117 insertions, 49 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/config/SecurityInitializer.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/config/SecurityInitializer.java
new file mode 100644
index 00000000..2a0a4b15
--- /dev/null
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/config/SecurityInitializer.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.config;
+
+import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
+
+public class SecurityInitializer extends AbstractSecurityWebApplicationInitializer {
+
+}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java
index c9a6f5d1..d0932d2f 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java
@@ -108,6 +108,8 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
@EnableAspectJAutoProxy
@EPAuditLog
public class RoleManageController extends EPRestrictedBaseController {
+ private static final String PIPE = "|";
+
private static final String ROLE_INVALID_CHARS = "%=():,\"\"";
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleManageController.class);
@@ -340,7 +342,7 @@ public class RoleManageController extends EPRestrictedBaseController {
+ " and action: " + roleFunction.getAction() + " found while saving!");
}
roleFunction.setCode(externalAccessRolesService.encodeFunctionCode(roleFunction.getCode()));
- roleFunction.setCode(roleFunction.getType() + "|" + roleFunction.getCode() + "|"
+ roleFunction.setCode(roleFunction.getType() + PIPE + roleFunction.getCode() + PIPE
+ roleFunction.getAction());
domainRole.addRoleFunction((CentralV2RoleFunction) roleFunction);
}
@@ -500,8 +502,12 @@ public class RoleManageController extends EPRestrictedBaseController {
if (isAuthorizedUser(user, requestedApp)) {
fieldsValidation(requestedApp);
if (requestedApp.getCentralAuth()) {
- CentralV2RoleFunction domainRoleFunction = externalAccessRolesService.getRoleFunction(roleFunc.getCode(),
+ String code = roleFunc.getType()+PIPE+roleFunc.getCode()+PIPE+roleFunc.getAction();
+ CentralV2RoleFunction domainRoleFunction = externalAccessRolesService.getRoleFunction(code,
requestedApp.getUebKey());
+ if(domainRoleFunction.getType() == null || domainRoleFunction.getAction() == null) {
+ addIfTypeActionDoesNotExits(domainRoleFunction);
+ }
if (domainRoleFunction != null && domainRoleFunction.getCode().equals(roleFunc.getCode())
&& domainRoleFunction.getType().equals(roleFunc.getType())
&& domainRoleFunction.getAction().equals(roleFunc.getAction())) {
@@ -558,6 +564,24 @@ public class RoleManageController extends EPRestrictedBaseController {
return new PortalRestResponse<>(PortalRestStatusEnum.OK, "Saved Successfully!", "Success");
}
+
+
+ private void addIfTypeActionDoesNotExits(CentralV2RoleFunction domainRoleFunction) {
+ if(domainRoleFunction.getCode().contains(PIPE)) {
+ String newfunctionCodeFormat = EcompPortalUtils.getFunctionCode(domainRoleFunction.getCode());
+ String newfunctionTypeFormat = EcompPortalUtils.getFunctionType(domainRoleFunction.getCode());
+ String newfunctionActionFormat = EcompPortalUtils.getFunctionAction(domainRoleFunction.getCode());
+ domainRoleFunction.setType(newfunctionTypeFormat);
+ domainRoleFunction.setAction(newfunctionActionFormat);
+ domainRoleFunction.setCode(newfunctionCodeFormat);
+ } else {
+ String type = externalAccessRolesService.getFunctionCodeType(domainRoleFunction.getCode());
+ String action = externalAccessRolesService.getFunctionCodeAction(domainRoleFunction.getCode());
+ domainRoleFunction.setType(type);
+ domainRoleFunction.setAction(action);
+ }
+ }
+
@RequestMapping(value = { "/portalApi/role_function_list/removeRoleFunction/{appId}" }, method = RequestMethod.POST)
public PortalRestResponse<String> removeRoleFunction(HttpServletRequest request, HttpServletResponse response,
@RequestBody String roleFunc, @PathVariable("appId") Long appId) throws Exception {
@@ -571,17 +595,12 @@ public class RoleManageController extends EPRestrictedBaseController {
String data = roleFunc;
boolean getDelFuncResponse = false;
CentralV2RoleFunction availableRoleFunction = mapper.readValue(data, CentralV2RoleFunction.class);
- String code = availableRoleFunction.getType() + "|" + availableRoleFunction.getCode() + "|"
+ String code = availableRoleFunction.getType() + PIPE + availableRoleFunction.getCode() + PIPE
+ availableRoleFunction.getAction();
CentralV2RoleFunction domainRoleFunction = externalAccessRolesService.getRoleFunction(code,
requestedApp.getUebKey());
- if (domainRoleFunction.getCode().contains("|")) {
- getDelFuncResponse = externalAccessRolesService
- .deleteCentralRoleFunction(code, requestedApp);
- } else {
- getDelFuncResponse = externalAccessRolesService
- .deleteCentralRoleFunction(domainRoleFunction.getCode(), requestedApp);
- }
+ getDelFuncResponse = externalAccessRolesService
+ .deleteCentralRoleFunction(domainRoleFunction.getCode(), requestedApp);
if (getDelFuncResponse) {
logger.info(EELFLoggerDelegate.applicationLogger,
"deleteRoleFunction: succeeded for app {}, role {}", requestedApp.getId(),
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPAppMessagesEnum.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPAppMessagesEnum.java
index d7536bf7..a93be650 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPAppMessagesEnum.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPAppMessagesEnum.java
@@ -224,7 +224,7 @@ public enum EPAppMessagesEnum {
"ERR540E", "Unexpected Scheduler error", "Details: {0}.", "Please check logs for more information."),
SchedulerInvalidAttributeError(EPErrorCodesEnum.SCHEDULER_INVALID_ATTRIBUTEERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR,
- "ERR505E", "Unable to create Scheduler", "Details: {0}.", "Please check logs for more information."),
+ "ERR515E", "Unable to create Scheduler", "Details: {0}.", "Please check logs for more information."),
;
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java
index 1d198f76..bcf806b2 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java
@@ -433,5 +433,23 @@ public interface ExternalAccessRolesService {
ObjectMapper mapper, JSONArray extRole) throws IOException, JsonParseException, JsonMappingException;
public JSONArray getAllUsersByRole(String roleName) throws Exception;
+
+ /**
+ *
+ * It check function code has any pipes, if found return function type
+ *
+ * @param roleFuncItem
+ * @param type
+ * @return function type
+ */
+ String getFunctionCodeType(String roleFuncItem);
+
+ /**
+ * It return function action
+ *
+ * @param roleFuncItem
+ * @return String action
+ */
+ String getFunctionCodeAction(String roleFuncItem);
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java
index b1804d8c..39bd92d6 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java
@@ -513,8 +513,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
String action = "";
if (roleFunc.getCode().contains(FUNCTION_PIPE)) {
code = EcompPortalUtils.getFunctionCode(roleFunc.getCode());
- type = getFunctionType(roleFunc.getCode());
- action = getFunctionAction(roleFunc.getCode());
+ type = getFunctionCodeType(roleFunc.getCode());
+ action = getFunctionCodeAction(roleFunc.getCode());
} else {
code = roleFunc.getCode();
type = roleFunc.getCode().contains("menu") ? "menu" : "url";
@@ -663,8 +663,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
String action = "";
if (addFunction.getCode().contains(FUNCTION_PIPE)) {
code = EcompPortalUtils.getFunctionCode(addFunction.getCode());
- type = getFunctionType(addFunction.getCode());
- action = getFunctionAction(addFunction.getCode());
+ type = getFunctionCodeType(addFunction.getCode());
+ action = getFunctionCodeAction(addFunction.getCode());
} else {
code = addFunction.getCode();
type = addFunction.getCode().contains("menu") ? "menu" : "url";
@@ -720,8 +720,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
String action = "";
if (roleFunc.getCode().contains(FUNCTION_PIPE)) {
code = EcompPortalUtils.getFunctionCode(roleFunc.getCode());
- type = getFunctionType(roleFunc.getCode());
- action = getFunctionAction(roleFunc.getCode());
+ type = getFunctionCodeType(roleFunc.getCode());
+ action = getFunctionCodeAction(roleFunc.getCode());
} else {
code = roleFunc.getCode();
type = roleFunc.getCode().contains("menu") ? "menu" : "url";
@@ -1191,8 +1191,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
List<CentralV2RoleFunction> getRoleFuncList = dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null);
for (CentralV2RoleFunction roleFuncItem : getRoleFuncList) {
String code = EcompPortalUtils.getFunctionCode(roleFuncItem.getCode());
- String type = getFunctionType(roleFuncItem.getCode());
- String action = getFunctionAction(roleFuncItem.getCode());
+ String type = getFunctionCodeType(roleFuncItem.getCode());
+ String action = getFunctionCodeAction(roleFuncItem.getCode());
roleFuncItem.setCode(EPUserUtils.decodeFunctionCode(code));
roleFuncItem.setType(type);
roleFuncItem.setAction(action);
@@ -1202,26 +1202,14 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
}
- /**
- * It return function action
- *
- * @param roleFuncItem
- * @return String action
- */
- private String getFunctionAction(String roleFuncItem) {
+ @Override
+ public String getFunctionCodeAction(String roleFuncItem) {
return (!roleFuncItem.contains(FUNCTION_PIPE)) ? "*"
: EcompPortalUtils.getFunctionAction(roleFuncItem);
}
- /**
- *
- * It check function code has any pipes, if found return function type
- *
- * @param roleFuncItem
- * @param type
- * @return function type
- */
- private String getFunctionType(String roleFuncItem) {
+ @Override
+ public String getFunctionCodeType(String roleFuncItem) {
String type = null;
if ((roleFuncItem.contains(FUNCTION_PIPE) && roleFuncItem.contains("menu"))
|| (!roleFuncItem.contains(FUNCTION_PIPE) && roleFuncItem.contains("menu"))) {
@@ -1467,8 +1455,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
for (CentralV2RoleFunction roleFunc : cenRoleFuncList) {
String functionCode = EcompPortalUtils.getFunctionCode(roleFunc.getCode());
functionCode = EPUserUtils.decodeFunctionCode(functionCode);
- String type = getFunctionType(roleFunc.getCode());
- String action = getFunctionAction(roleFunc.getCode());
+ String type = getFunctionCodeType(roleFunc.getCode());
+ String action = getFunctionCodeAction(roleFunc.getCode());
CentralV2RoleFunction cenRoleFunc = new CentralV2RoleFunction(role.getId(), functionCode,
roleFunc.getName(), null, type, action, null);
roleFunctionSet.add(cenRoleFunc);
@@ -1509,15 +1497,14 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
if (getRoleFuncList.isEmpty()) {
return roleFunc;
}
+ }
+ if (getRoleFuncList.size() > 1) {
+ CentralV2RoleFunction cenV2RoleFunction = appFunctionListFilter(encodedCode, getRoleFuncList);
+ if (cenV2RoleFunction == null)
+ return roleFunc;
+ roleFunc = checkIfPipesExitsInFunctionCode(cenV2RoleFunction);
} else {
- if (getRoleFuncList.size() > 1) {
- CentralV2RoleFunction cenV2RoleFunction = appFunctionListFilter(encodedCode, getRoleFuncList);
- if (cenV2RoleFunction == null)
- return roleFunc;
- roleFunc = checkIfPipesExitsInFunctionCode(cenV2RoleFunction);
- } else {
- roleFunc = checkIfPipesExitsInFunctionCode(getRoleFuncList.get(0));
- }
+ roleFunc = getRoleFuncList.get(0);
}
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction: failed", e);
@@ -1693,8 +1680,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
ObjectMapper mapper = new ObjectMapper();
ExternalAccessPerms extPerms = new ExternalAccessPerms();
String instanceValue = EcompPortalUtils.getFunctionCode(domainCentralRoleFunction.getCode());
- String checkType = getFunctionType(domainCentralRoleFunction.getCode());
- String actionValue = getFunctionAction(domainCentralRoleFunction.getCode());
+ String checkType = getFunctionCodeType(domainCentralRoleFunction.getCode());
+ String actionValue = getFunctionCodeAction(domainCentralRoleFunction.getCode());
HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth();
extPerms.setAction(actionValue);
extPerms.setInstance(instanceValue);
@@ -3290,8 +3277,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
action = EcompPortalUtils.getFunctionAction(role.getFunctionCd());
cenRoleFun = new CentralV2RoleFunction(null, instance, role.getFunctionName(), null, type, action, null);
} else{
- type = getFunctionType(role.getFunctionCd());
- action = getFunctionAction(role.getFunctionCd());
+ type = getFunctionCodeType(role.getFunctionCd());
+ action = getFunctionCodeAction(role.getFunctionCd());
cenRoleFun = new CentralV2RoleFunction(null, role.getFunctionCd(), role.getFunctionName(), null, type, action, null);
}
return cenRoleFun;