summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-portal-BE-common')
-rw-r--r--ecomp-portal-BE-common/pom.xml40
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuditLogController.java40
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java9
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java34
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java1
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java36
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLdapServiceImpl.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java13
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java174
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRole.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EcompUserRoles.java20
-rw-r--r--ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml21
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java169
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java4
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java18
16 files changed, 445 insertions, 140 deletions
diff --git a/ecomp-portal-BE-common/pom.xml b/ecomp-portal-BE-common/pom.xml
index 320e77ad..ce394eaf 100644
--- a/ecomp-portal-BE-common/pom.xml
+++ b/ecomp-portal-BE-common/pom.xml
@@ -291,6 +291,12 @@
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.2.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-queryparser</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>io.searchbox</groupId>
@@ -334,7 +340,7 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
- <version>3.17</version>
+ <version>3.15</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
@@ -349,7 +355,7 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
- <version>3.17</version>
+ <version>3.15</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
@@ -441,6 +447,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -505,7 +515,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
- <version>4.5.2</version>
+ <version>4.5.3</version>
</dependency>
<!-- for testing -->
<dependency>
@@ -537,7 +547,7 @@
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
- <version>1.9.2</version>
+ <version>1.9.3</version>
</dependency>
<dependency>
<groupId>com.ecwid.consul</groupId>
@@ -578,7 +588,7 @@
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
- <version>2.9.2</version>
+ <version>2.8.10</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
@@ -601,6 +611,10 @@
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils-core</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -619,11 +633,6 @@
<version>${springframework.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-queryparser</artifactId>
- <version>7.2.1</version>
- </dependency>
- <dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.10</version>
@@ -643,7 +652,16 @@
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
-
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.2</version>
+ </dependency>
</dependencies>
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuditLogController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuditLogController.java
index e0232850..e8fb71a6 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuditLogController.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuditLogController.java
@@ -37,6 +37,10 @@
*/
package org.onap.portalapp.portal.controller;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.UUID;
+
import javax.servlet.http.HttpServletRequest;
import org.slf4j.MDC;
@@ -45,6 +49,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
+
+import com.att.eelf.configuration.Configuration;
+
import org.onap.portalapp.controller.EPRestrictedBaseController;
import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.logging.aop.EPEELFLoggerAdvice;
@@ -56,6 +63,7 @@ import org.onap.portalapp.util.EPUserUtils;
import org.onap.portalsdk.core.domain.AuditLog;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.service.AuditService;
+import org.onap.portalsdk.core.util.SystemProperties;
@RestController
@RequestMapping("/portalApi/auditLog")
@@ -103,19 +111,34 @@ public class AuditLogController extends EPRestrictedBaseController {
AuditLog auditLog = new AuditLog();
auditLog.setActivityCode(cd_type);
/*
- * Check affectedAppId and comment and see if these two values are valid
+ * Check affectedAppId and comment and see if these two values
+ * are valid
*/
if (comment != null && !comment.equals("") && !comment.equals("undefined"))
- auditLog.setComments(EcompPortalUtils.truncateString(comment, PortalConstants.AUDIT_LOG_COMMENT_SIZE));
+ auditLog.setComments(
+ EcompPortalUtils.truncateString(comment, PortalConstants.AUDIT_LOG_COMMENT_SIZE));
if (affectedAppId != null && !affectedAppId.equals("") && !affectedAppId.equals("undefined"))
auditLog.setAffectedRecordId(affectedAppId);
long userId = EPUserUtils.getUserId(request);
auditLog.setUserId(userId);
- auditService.logActivity(auditLog, null);
-
- // Log file
MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ MDC.put(EPCommonSystemProperties.PARTNER_NAME, EPCommonSystemProperties.ECOMP_PORTAL_FE);
+ MDC.put(Configuration.MDC_SERVICE_NAME, EPCommonSystemProperties.ECOMP_PORTAL_BE);
+ if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null) {
+ String requestId = UUID.randomUUID().toString();
+ MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
+ }
+ // Log file
MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ SimpleDateFormat ecompLogDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
+ String beginDateTime = MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
+ Date beginDate = ecompLogDateFormat.parse(beginDateTime);
+ auditService.logActivity(auditLog, null);
+ String endDateTime = MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
+ Date endDate = ecompLogDateFormat.parse(endDateTime);
+ String timeDifference = String.format("%d", endDate.getTime() - beginDate.getTime());
+ MDC.put(SystemProperties.MDC_TIMER, timeDifference);
+ MDC.put(EPCommonSystemProperties.STATUS_CODE, "COMPLETE");
logger.info(EELFLoggerDelegate.auditLogger, EPLogUtil.formatAuditLogMessage(
"AuditLogController.auditLog", cd_type, user.getOrgUserId(), affectedAppId, comment));
MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
@@ -123,6 +146,13 @@ public class AuditLogController extends EPRestrictedBaseController {
}
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "auditLog failed", e);
+ MDC.put(EPCommonSystemProperties.STATUS_CODE, "ERROR");
+ } finally{
+ MDC.remove(Configuration.MDC_SERVICE_NAME);
+ MDC.remove(EPCommonSystemProperties.PARTNER_NAME);
+ MDC.remove(SystemProperties.MDC_TIMER);
+ MDC.remove(Configuration.MDC_KEY_REQUEST_ID);
+ MDC.remove(EPCommonSystemProperties.STATUS_CODE);
}
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java
index 4b364995..964ccb5b 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java
@@ -273,19 +273,26 @@ public class DashboardController extends EPRestrictedBaseController {
auditLog.setUserId(user.getId());
auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_SEARCH);
auditLog.setComments(EcompPortalUtils.truncateString(searchString, PortalConstants.AUDIT_LOG_COMMENT_SIZE));
- MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ MDC.put(EPCommonSystemProperties.PARTNER_NAME, EPCommonSystemProperties.ECOMP_PORTAL_FE);
+ MDC.put(com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME, EPCommonSystemProperties.ECOMP_PORTAL_BE);
auditService.logActivity(auditLog, null);
MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+
+ MDC.put(EPCommonSystemProperties.STATUS_CODE, "COMPLETE");
EcompPortalUtils.calculateDateTimeDifferenceForLog(MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
logger.info(EELFLoggerDelegate.auditLogger, EPLogUtil.formatAuditLogMessage("DashboardController.PortalRestResponse",
EcompAuditLog.CD_ACTIVITY_SEARCH, user.getOrgUserId(), null, searchString));
MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
MDC.remove(SystemProperties.MDC_TIMER);
+ MDC.remove(EPCommonSystemProperties.STATUS_CODE);
return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);
}
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "searchPortal failed", e);
+ MDC.put(EPCommonSystemProperties.STATUS_CODE, "ERROR");
+ MDC.remove(EPCommonSystemProperties.STATUS_CODE);
return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage() + " - check logs.",
new HashMap<String, List<SearchResultItem>>());
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java
index 1e955c8b..f846253f 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java
@@ -209,10 +209,10 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl
@ApiOperation(value = "Gets all role functions for an application for older version.", response = CentralRoleFunction.class, responseContainer="Json")
@RequestMapping(value = {
"/functions" }, method = RequestMethod.GET, produces = "application/json")
- public List<RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
+ public List<CentralRoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
throws Exception {
List<CentralV2RoleFunction> answer = null;
- List<RoleFunction> roleFuncList = null;
+ List<CentralRoleFunction> roleFuncList = null;
logger.debug(EELFLoggerDelegate.debugLogger, "Request received for getRoleFunctionsList");
try {
fieldsValidation(request);
@@ -253,6 +253,7 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl
logger.debug(EELFLoggerDelegate.debugLogger, "Request completed for getV2RoleFunctionsList");
return cenRoleFuncList;
}
+
@ApiOperation(value = "Gets role information for an application.", response = CentralRole.class, responseContainer="Json")
@RequestMapping(value = {
@@ -572,16 +573,32 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl
return new PortalRestResponse<String>(PortalRestStatusEnum.OK, SUCCESSFULLY_DELETED, "Success");
}
- @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
+ @ApiOperation(value = "Gets active roles for an application.", response = CentralRole.class, responseContainer = "Json")
@RequestMapping(value = { "/activeRoles" }, method = RequestMethod.GET, produces = "application/json")
- public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
+ public List<CentralRole> getActiveRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
+ List<CentralRole> roles = null;
+ try {
+ fieldsValidation(request);
+ List<CentralV2Role> cenRoles= externalAccessRolesService.getActiveRoles(request.getHeader(UEBKEY));
+ roles = externalAccessRolesService.convertV2CentralRoleListToOldVerisonCentralRoleList(cenRoles);
+ } catch (Exception e) {
+ sendErrorResponse(response, e);
+ logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
+ }
+ return roles;
+
+ }
+
+ @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
+ @RequestMapping(value = { "/v1/activeRoles" }, method = RequestMethod.GET, produces = "application/json")
+ public List<CentralV2Role> getV2ActiveRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
List<CentralV2Role> cenRole = null;
try {
fieldsValidation(request);
cenRole = externalAccessRolesService.getActiveRoles(request.getHeader(UEBKEY));
} catch (Exception e) {
sendErrorResponse(response, e);
- logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
+ logger.error(EELFLoggerDelegate.errorLogger, "getV2ActiveRoles failed", e);
}
return cenRole;
@@ -831,13 +848,12 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl
@PathVariable("loginId") String loginId) throws Exception {
EcompUser user = null;
ObjectMapper mapper = new ObjectMapper();
- CentralUser answer = null;
+ String answer = null;
try {
fieldsValidation(request);
- answer = externalAccessRolesService.getUserRoles(loginId, request.getHeader(UEBKEY));
+ answer = externalAccessRolesService.getV2UserWithRoles(loginId, request.getHeader(UEBKEY));
if (answer != null) {
- String res = mapper.writeValueAsString(answer);
- User ecompUser = userservice.userMapper(res);
+ User ecompUser = userservice.userMapper(answer);
user = UserUtils.convertToEcompUser(ecompUser);
}
} catch (Exception e) {
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 8f0558aa..dbea91f5 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
@@ -78,6 +78,7 @@ import org.onap.portalapp.portal.utils.PortalConstants;
import org.onap.portalapp.util.EPUserUtils;
import org.onap.portalsdk.core.domain.AuditLog;
import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.domain.RoleFunction;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.service.AuditService;
import org.onap.portalsdk.core.util.SystemProperties;
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java
index c1127758..30795c0e 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java
@@ -38,6 +38,7 @@
package org.onap.portalapp.portal.logging.aop;
import java.net.InetAddress;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
@@ -104,7 +105,7 @@ public class EPEELFLoggerAdvice {
String className = "";
if (passOnArgs.length > 0 && passOnArgs[0] != null)
className = passOnArgs[0].toString();
- String methodName = "";
+ String methodName = EPCommonSystemProperties.ECOMP_PORTAL_BE;
if (passOnArgs.length > 1 && passOnArgs[1] != null)
methodName = passOnArgs[1].toString();
@@ -112,7 +113,7 @@ public class EPEELFLoggerAdvice {
MDC.put(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
MDC.put(EPCommonSystemProperties.TARGET_ENTITY, EPCommonSystemProperties.ECOMP_PORTAL_BE);
MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, methodName);
- if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null || MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){
+ if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){
String requestId = UUID.randomUUID().toString();
MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
}
@@ -149,7 +150,7 @@ public class EPEELFLoggerAdvice {
if (passOnArgs.length > 0 && passOnArgs[0] != null)
className = passOnArgs[0].toString();
// Method Name
- String methodName = "";
+ String methodName = EPCommonSystemProperties.ECOMP_PORTAL_BE;
if (passOnArgs.length > 1 && passOnArgs[1] != null)
methodName = passOnArgs[1].toString();
@@ -160,6 +161,14 @@ public class EPEELFLoggerAdvice {
if (MDC.get(EPCommonSystemProperties.TARGET_ENTITY) == null
|| MDC.get(EPCommonSystemProperties.TARGET_ENTITY) == "")
MDC.put(EPCommonSystemProperties.TARGET_ENTITY, EPCommonSystemProperties.ECOMP_PORTAL_BE);
+
+ if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){
+ String requestId = UUID.randomUUID().toString();
+ MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
+ }
+ MDC.put(EPCommonSystemProperties.PARTNER_NAME, "Unknown");
+ MDC.put(Configuration.MDC_SERVICE_NAME, EPCommonSystemProperties.ECOMP_PORTAL_BE);
+
MDC.put(EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP,
MDC.get(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP));
@@ -173,7 +182,7 @@ public class EPEELFLoggerAdvice {
if (securityEventType != null && args.length > 0 && args[0] != null && args[0] instanceof HttpServletRequest
&& securityEventType == SecurityEventTypeEnum.INCOMING_REST_MESSAGE
&& (MDC.get(EPCommonSystemProperties.FULL_URL) == null
- || MDC.get(EPCommonSystemProperties.FULL_URL).isEmpty())) {
+ || MDC.get(EPCommonSystemProperties.FULL_URL).isEmpty())) {
HttpServletRequest req = (HttpServletRequest) args[0];
this.setHttpRequestBasedDefaultsIntoGlobalLoggingContext(req, securityEventType, methodName);
}
@@ -308,13 +317,12 @@ public class EPEELFLoggerAdvice {
MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
// Load user agent into MDC context, if available.
- String accessingClient = "Unknown";
- accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME);
+ String accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME);
+ accessingClient = (accessingClient == null || accessingClient.trim().length()==0)?"Unknown":accessingClient;
if (accessingClient != null && accessingClient.trim().length()==0 && (accessingClient.contains("Mozilla")
|| accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) {
accessingClient = EPCommonSystemProperties.ECOMP_PORTAL_FE;
- }else if(accessingClient==null || accessingClient.isEmpty())
- accessingClient = "Unknown";
+ }
MDC.put(EPCommonSystemProperties.PARTNER_NAME, accessingClient);
// Load loginId into MDC context.
@@ -333,7 +341,8 @@ public class EPEELFLoggerAdvice {
MDC.put(EPCommonSystemProperties.FULL_URL, EPCommonSystemProperties.UNKNOWN);
MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTP);
restURL = UserUtils.getFullURL(req);
- if (restURL != null && restURL != "") {
+ //if (restURL != null && restURL != "") {
+ if (restURL != null && restURL.trim().length()>0) {
MDC.put(EPCommonSystemProperties.FULL_URL, restURL);
if (restURL.toLowerCase().contains("https")) {
MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTPS);
@@ -341,9 +350,11 @@ public class EPEELFLoggerAdvice {
}
// Rest Path
- MDC.put(Configuration.MDC_SERVICE_NAME, (restMethod==null || restMethod.isEmpty()) ? "Unknown" : restMethod);
+ MDC.put(Configuration.MDC_SERVICE_NAME, restMethod);
String restPath = req.getServletPath();
- if (restPath != null && !restPath.isEmpty()) {
+ //if (restPath != null && restPath != "") {
+ if (restPath != null && restPath.trim().length()>0) {
+
MDC.put(Configuration.MDC_SERVICE_NAME, restPath);
}
@@ -360,7 +371,7 @@ public class EPEELFLoggerAdvice {
MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, "search");
}
} else {
- MDC.put(Configuration.MDC_SERVICE_NAME, (restMethod==null || restMethod.isEmpty()) ? "Unknown" : restMethod);
+ MDC.put(Configuration.MDC_SERVICE_NAME, restMethod);
MDC.put(EPCommonSystemProperties.PARTNER_NAME, EPCommonSystemProperties.ECOMP_PORTAL_FE);
}
@@ -398,4 +409,5 @@ public class EPEELFLoggerAdvice {
public String getInternalResponseCode() {
return MDC.get(EPCommonSystemProperties.RESPONSE_CODE);
}
+
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLdapServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLdapServiceImpl.java
index 941acaf6..0e566a99 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLdapServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLdapServiceImpl.java
@@ -193,7 +193,7 @@ public class EPLdapServiceImpl extends FusionService implements EPLdapService {
for (NamingEnumeration e = resultAttributes.getAll(); e.hasMore();) { // why the nested loop?
Attribute attribute = (Attribute) e.next();
for (NamingEnumeration ie = attribute.getAll(); ie.hasMore();) {
- if (attribute.getID().equalsIgnoreCase("nickname")) {
+ if (attribute.getID().equalsIgnoreCase("givenName")) {
user.setFirstName((String) ie.next());
} else if (attribute.getID().equalsIgnoreCase("initials")) {
user.setMiddleInitial((String) ie.next());
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 bcf806b2..2f72bab2 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
@@ -51,6 +51,7 @@ import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.domain.ExternalRoleDetails;
import org.onap.portalapp.portal.exceptions.InvalidUserException;
import org.onap.portalapp.portal.transport.CentralRole;
+import org.onap.portalapp.portal.transport.CentralRoleFunction;
import org.onap.portalapp.portal.transport.CentralUser;
import org.onap.portalapp.portal.transport.CentralV2Role;
import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
@@ -132,11 +133,11 @@ public interface ExternalAccessRolesService {
CentralV2Role getRoleInfo(Long roleId, String uebkey) throws Exception;
/**
- * It returns the CentralRoleFunction object
+ * It returns the CentralV2RoleFunction object
*
* @param functionCode
* @param uebkey
- * @return CentralRoleFunction
+ * @return CentralV2RoleFunction
* @throws Exception
*/
public CentralV2RoleFunction getRoleFunction(String functionCode, String uebkey) throws Exception;
@@ -150,7 +151,7 @@ public interface ExternalAccessRolesService {
* @throws Exception
*/
public boolean saveCentralRoleFunction(CentralV2RoleFunction domainCentralRoleFunction, EPApp requestedApp) throws Exception;
-
+
/**
* It deletes role function in the DB
*
@@ -335,11 +336,11 @@ public interface ExternalAccessRolesService {
public List<EPRole> getGlobalRolesOfPortal();
/**
- * It converts list of CentralRoleFunction objects to RoleFunction objects
+ * It converts list of CentralV2RoleFunction objects to older version of CentralRoleFunction objects
* @param answer contains list of CentralRoleFunction objects
- * @return List of RoleFunction objects
+ * @return List of CentralRoleFunction objects
*/
- public List<RoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer);
+ public List<CentralRoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer);
/**
*
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 39bd92d6..a2226944 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
@@ -107,6 +107,7 @@ import org.onap.portalsdk.core.domain.Role;
import org.onap.portalsdk.core.domain.RoleFunction;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.restful.domain.EcompRole;
+import org.onap.portalsdk.core.restful.domain.EcompRoleFunction;
import org.onap.portalsdk.core.restful.domain.EcompUser;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.util.SystemProperties;
@@ -1324,8 +1325,10 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
SortedSet<CentralV2RoleFunction> roleFunctionSet = new TreeSet<>();
for (CentralV2RoleFunction roleFunc : appRoleFunctionList) {
String functionCode = EcompPortalUtils.getFunctionCode(roleFunc.getCode());
+ String type = getFunctionCodeType(roleFunc.getCode());
+ String action = getFunctionCodeAction(roleFunc.getCode());
CentralV2RoleFunction cenRoleFunc = new CentralV2RoleFunction(roleFunc.getId(),
- functionCode, roleFunc.getName(), null, null);
+ functionCode, roleFunc.getName(), null, type, action, null);
roleFunctionSet.add(cenRoleFunc);
}
Long userRoleId = null;
@@ -1504,7 +1507,12 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
return roleFunc;
roleFunc = checkIfPipesExitsInFunctionCode(cenV2RoleFunction);
} else {
- roleFunc = getRoleFuncList.get(0);
+ // Check even if single record have pipes
+ if (!getRoleFuncList.isEmpty() && getRoleFuncList.get(0).getCode().contains(FUNCTION_PIPE)) {
+ roleFunc = checkIfPipesExitsInFunctionCode(getRoleFuncList.get(0));
+ } else {
+ roleFunc = getRoleFuncList.get(0);
+ }
}
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction: failed", e);
@@ -3080,79 +3088,116 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
@Override
public List<String> getMenuFunctionsList(String uebkey) throws Exception {
List<String> appMenuFunctionsList = null;
+ List<String> appMenuFunctionsFinalList = new ArrayList<>();
try {
EPApp app = getApp(uebkey).get(0);
final Map<String, Long> appParams = new HashMap<>();
appParams.put(APP_ID, app.getId());
appMenuFunctionsList = dataAccessService.executeNamedQuery("getMenuFunctions", appParams, null);
+ for(String appMenuFunction : appMenuFunctionsList) {
+ if(appMenuFunction.contains(FUNCTION_PIPE)) {
+ appMenuFunctionsFinalList.add(EcompPortalUtils.getFunctionCode(appMenuFunction));
+ } else {
+ appMenuFunctionsFinalList.add(appMenuFunction);
+ }
+ }
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctionsList: Failed", e);
- return appMenuFunctionsList;
+ return appMenuFunctionsFinalList;
}
- return appMenuFunctionsList;
+ return appMenuFunctionsFinalList;
}
@SuppressWarnings({ "unchecked"})
@Override
public List<EcompUser> getAllAppUsers(String uebkey) throws Exception {
List<String> usersList = new ArrayList<>();
- List<EcompUser> usersfinalList = new ArrayList<>();
- try {
- EPApp app = getApp(uebkey).get(0);
- final Map<String, Long> appParams = new HashMap<>();
- appParams.put("appId", app.getId());
- List<EcompUserRoles> userList = (List<EcompUserRoles>) dataAccessService
- .executeNamedQuery("ApplicationUserRoles", appParams, null);
- for (EcompUserRoles ecompUserRole : userList) {
- boolean found = false;
- Set<EcompRole> roles = null;
- for (EcompUser user : usersfinalList) {
- if (user.getOrgUserId().equals(ecompUserRole.getOrgUserId())) {
- EcompRole ecompRole = new EcompRole();
- ecompRole.setId(ecompUserRole.getRoleId());
- ecompRole.setName(ecompUserRole.getRoleName());
- roles = user.getRoles();
- roles.add(ecompRole);
- user.setRoles(roles);
- found = true;
- break;
- }
- }
+ List<EcompUser> usersfinalList = new ArrayList<>();
+ try {
+ EPApp app = getApp(uebkey).get(0);
+ final Map<String, Long> appParams = new HashMap<>();
+ appParams.put("appId", app.getId());
+ List<EcompUserRoles> userList = (List<EcompUserRoles>) dataAccessService
+ .executeNamedQuery("ApplicationUserRoles", appParams, null);
+ for (EcompUserRoles ecompUserRole : userList) {
+ boolean found = false;
+ Set<EcompRole> roles = null;
+ for (EcompUser user : usersfinalList) {
+ if (user.getOrgUserId().equals(ecompUserRole.getOrgUserId())) {
+ EcompRole ecompRole = new EcompRole();
+ ecompRole.setId(ecompUserRole.getRoleId());
+ ecompRole.setName(ecompUserRole.getRoleName());
+ roles = user.getRoles();
+ EcompRole role = roles.stream().filter(x -> x.getName().equals(ecompUserRole.getRoleName())).findAny()
+ .orElse(null);
+ SortedSet<EcompRoleFunction> roleFunctionSet = new TreeSet<>();
+ if(role != null)
+ {
+ roleFunctionSet = (SortedSet<EcompRoleFunction>) role.getRoleFunctions();
+ }
+
+ String functionCode = EcompPortalUtils.getFunctionCode(ecompUserRole.getFunctionCode());
+ functionCode = EPUserUtils.decodeFunctionCode(functionCode);
+ EcompRoleFunction epRoleFunction = new EcompRoleFunction();
+ epRoleFunction.setName(ecompUserRole.getFunctionName());
+ epRoleFunction.setCode(EPUserUtils.decodeFunctionCode(functionCode));
+ epRoleFunction.setType(getFunctionCodeType(ecompUserRole.getFunctionCode()));
+ epRoleFunction.setAction(getFunctionCodeAction(ecompUserRole.getFunctionCode()));
+ roleFunctionSet.add(epRoleFunction);
+ ecompRole.setRoleFunctions(roleFunctionSet);
+ roles.add(ecompRole);
+ user.setRoles(roles);
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ EcompUser epUser = new EcompUser();
+ epUser.setOrgId(ecompUserRole.getOrgId());
+ epUser.setManagerId(ecompUserRole.getManagerId());
+ epUser.setFirstName(ecompUserRole.getFirstName());
+ epUser.setLastName(ecompUserRole.getLastName());
+ epUser.setPhone(ecompUserRole.getPhone());
+ epUser.setEmail(ecompUserRole.getEmail());
+ epUser.setOrgUserId(ecompUserRole.getOrgUserId());
+ epUser.setOrgCode(ecompUserRole.getOrgCode());
+ epUser.setOrgManagerUserId(ecompUserRole.getOrgManagerUserId());
+ epUser.setJobTitle(ecompUserRole.getJobTitle());
+ epUser.setLoginId(ecompUserRole.getLoginId());
+ epUser.setActive(true);
+ roles = new HashSet<>();
+ EcompRole ecompRole = new EcompRole();
+ ecompRole.setId(ecompUserRole.getRoleId());
+ ecompRole.setName(ecompUserRole.getRoleName());
+ SortedSet<EcompRoleFunction> roleFunctionSet = new TreeSet<>();
+
+ String functionCode = EcompPortalUtils.getFunctionCode(ecompUserRole.getFunctionCode());
+ functionCode = EPUserUtils.decodeFunctionCode(functionCode);
+ EcompRoleFunction epRoleFunction = new EcompRoleFunction();
+ epRoleFunction.setName(ecompUserRole.getFunctionName());
+ epRoleFunction.setCode(EPUserUtils.decodeFunctionCode(functionCode));
+ epRoleFunction.setType(getFunctionCodeType(ecompUserRole.getFunctionCode()));
+ epRoleFunction.setAction(getFunctionCodeAction(ecompUserRole.getFunctionCode()));
+ roleFunctionSet.add(epRoleFunction);
+ ecompRole.setRoleFunctions(roleFunctionSet);
+ roles.add(ecompRole);
+ epUser.setRoles(roles);
+ usersfinalList.add(epUser);
+ }
+ }
+ ObjectMapper mapper = new ObjectMapper();
+
+ for (EcompUser u1 : usersfinalList) {
+ String str = mapper.writeValueAsString(u1);
+ usersList.add(str);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getAllUsers failed", e);
+ throw e;
+ }
+ return usersfinalList;
- if (!found) {
- EcompUser epUser = new EcompUser();
- epUser.setOrgId(ecompUserRole.getOrgId());
- epUser.setManagerId(ecompUserRole.getManagerId());
- epUser.setFirstName(ecompUserRole.getFirstName());
- epUser.setLastName(ecompUserRole.getLastName());
- epUser.setPhone(ecompUserRole.getPhone());
- epUser.setEmail(ecompUserRole.getEmail());
- epUser.setOrgUserId(ecompUserRole.getOrgUserId());
- epUser.setOrgCode(ecompUserRole.getOrgCode());
- epUser.setOrgManagerUserId(ecompUserRole.getOrgManagerUserId());
- epUser.setJobTitle(ecompUserRole.getJobTitle());
- epUser.setLoginId(ecompUserRole.getLoginId());
- epUser.setActive(true);
- roles = new HashSet<>();
- EcompRole ecompRole = new EcompRole();
- ecompRole.setId(ecompUserRole.getRoleId());
- ecompRole.setName(ecompUserRole.getRoleName());
- roles.add(ecompRole);
- epUser.setRoles(roles);
- usersfinalList.add(epUser);
- }
- }
- ObjectMapper mapper = new ObjectMapper();
-
- for (EcompUser u1 : usersfinalList) {
- String str = mapper.writeValueAsString(u1);
- usersList.add(str);
- }
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "getAllUsers failed", e);
- throw e;
- }
- return usersfinalList;
}
@@ -3304,10 +3349,10 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
}
@Override
- public List<RoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer) {
- List<RoleFunction> addRoleFuncList = new ArrayList<>();
+ public List<CentralRoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer) {
+ List<CentralRoleFunction> addRoleFuncList = new ArrayList<>();
for(CentralV2RoleFunction cenRoleFunc : answer){
- RoleFunction setRoleFunc = new RoleFunction();
+ CentralRoleFunction setRoleFunc = new CentralRoleFunction();
setRoleFunc.setCode(cenRoleFunc.getCode());
setRoleFunc.setName(cenRoleFunc.getName());
addRoleFuncList.add(setRoleFunc);
@@ -3324,6 +3369,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
sendUserRoles = convertV2UserRolesToOlderVersion(cenV2User);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "getUserRoles: failed", e);
+ throw e;
}
return sendUserRoles;
}
@@ -3393,8 +3439,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
@Override
public List<CentralRole> convertV2CentralRoleListToOldVerisonCentralRoleList(List<CentralV2Role> v2CenRoleList) {
List<CentralRole> cenRoleList = new ArrayList<>();
- SortedSet<CentralRoleFunction> cenRoleFuncList = new TreeSet<>();
for(CentralV2Role v2CenRole : v2CenRoleList){
+ SortedSet<CentralRoleFunction> cenRoleFuncList = new TreeSet<>();
for(CentralV2RoleFunction v2CenRoleFunc: v2CenRole.getRoleFunctions()){
CentralRoleFunction roleFunc = new CentralRoleFunction(v2CenRoleFunc.getCode(), v2CenRoleFunc.getName());
cenRoleFuncList.add(roleFunc);
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRole.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRole.java
index dc1a78fe..7214f80a 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRole.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRole.java
@@ -42,6 +42,8 @@ import java.util.Date;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.onap.portalsdk.core.domain.RoleFunction;
+
public class CentralRole implements Serializable {
private static final long serialVersionUID = -9210905386086213882L;
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java
index 6cc474a1..6d982c27 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CentralRoleFunction.java
@@ -248,4 +248,4 @@ public class CentralRoleFunction implements Serializable, Comparable {
return true;
}
-}
+} \ No newline at end of file
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EcompUserRoles.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EcompUserRoles.java
index 73409ede..a1d2ae30 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EcompUserRoles.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EcompUserRoles.java
@@ -97,7 +97,27 @@ public class EcompUserRoles implements Serializable{
@Id
@Column(name = "active_yn")
private boolean active;
+
+ @Id
+ @Column(name = "function_cd")
+ private String functionCode;
+ @Id
+ @Column(name = "function_name")
+ private String functionName;
+
+ public String getFunctionCode() {
+ return functionCode;
+ }
+ public void setFunctionCode(String functionCode) {
+ this.functionCode = functionCode;
+ }
+ public String getFunctionName() {
+ return functionName;
+ }
+ public void setFunctionName(String functionName) {
+ this.functionName = functionName;
+ }
public Long getOrgId() {
return orgId;
}
diff --git a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml
index 5968b3ce..60174075 100644
--- a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml
+++ b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml
@@ -2101,17 +2101,16 @@ where fn_role.app_id = fn_app.app_id and fn_app.enabled='Y' and fn_role.active_y
<sql-query name="ApplicationUserRoles">
<return alias="ApplicationUserRoles" class="org.onap.portalapp.portal.transport.EcompUserRoles" />
<![CDATA[
- select distinct fu.org_id, fu.manager_id, fu.first_name, fu.middle_name, fu.last_name, fu.phone, fu.email, fu.hrid, fu.org_user_id, fu.org_code, fu.org_manager_userid, fu.job_title, fu.login_id,
- fu.active_yn , fr.app_role_id, fr.role_name
- from fn_user fu, fn_role fr, fn_user_role fur
- where fu.user_id = fur.user_id and fu.active_yn='Y' and fur.role_id = fr.role_id and fr.app_id =:appId and fr.active_yn='Y'
- union
- select distinct fu.org_id, fu.manager_id, fu.first_name, fu.middle_name, fu.last_name, fu.phone,
- fu.email, fu.hrid, fu.org_user_id, fu.org_code, fu.org_manager_userid, fu.job_title,
- fu.login_id, fu.active_yn , fr.role_id, fr.role_name
- from fn_user_role a, fn_role fr, fn_user fu
- where a.role_id in (select b.role_id from ep_app_role_function b where b.role_app_id = 1 and b.app_id =:appId) and a.user_id =fu.user_id and a.role_id = fr.role_id and fr.active_yn='Y' and fu.active_yn='Y'
- ;
+ select distinct fu.org_id, fu.manager_id, fu.first_name, fu.middle_name, fu.last_name, fu.phone, fu.email, fu.hrid, fu.org_user_id, fu.org_code, fu.org_manager_userid, fu.job_title, fu.login_id,
+ fu.active_yn , fr.app_role_id, fr.role_name, epr.function_cd , epf.function_name
+ from fn_user fu, fn_role fr, fn_user_role fur, ep_app_role_function epr , ep_app_function epf
+ where fu.user_id = fur.user_id and fu.active_yn='Y' and fur.role_id = fr.role_id and fr.app_id =:appId and fr.active_yn='Y' and epr.function_cd= epf.function_cd and epf.app_id=epr.app_id and fur.role_id=epr.role_id
+ union
+ select distinct fu.org_id, fu.manager_id, fu.first_name, fu.middle_name, fu.last_name, fu.phone, fu.email, fu.hrid, fu.org_user_id, fu.org_code, fu.org_manager_userid, fu.job_title,
+ fu.login_id, fu.active_yn , fr.role_id, fr.role_name, earf.function_cd , eaf.function_name
+ from fn_user_role a, fn_role fr, fn_user fu , ep_app_role_function earf, ep_app_function eaf
+ where a.role_id in (select b.role_id from ep_app_role_function b where b.role_app_id = 1 and b.app_id =:appId) and a.user_id =fu.user_id and a.role_id = fr.role_id and fr.active_yn='Y' and fu.active_yn='Y'
+ and earf.role_id = a.role_id and earf.function_cd = eaf.function_cd and earf.app_id = eaf.app_id and earf.role_app_id = 1 and fr.active_yn='Y' and fu.active_yn='Y';
]]>
</sql-query>
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java
index 47a1394e..ecfd88f5 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java
@@ -52,8 +52,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Matchers;
import org.mockito.Mock;
@@ -68,13 +68,25 @@ import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
import org.onap.portalapp.portal.service.ExternalAccessRolesService;
import org.onap.portalapp.portal.service.ExternalAccessRolesServiceImpl;
+import org.onap.portalapp.portal.transport.CentralRole;
import org.onap.portalapp.portal.transport.CentralRoleFunction;
import org.onap.portalapp.portal.transport.CentralV2Role;
import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalapp.portal.utils.EcompPortalUtils;
+import org.onap.portalapp.portal.utils.PortalConstants;
import org.onap.portalsdk.core.domain.AuditLog;
import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.restful.domain.EcompRole;
import org.onap.portalsdk.core.restful.domain.EcompUser;
-import org.springframework.beans.BeanUtils;
+import org.onap.portalsdk.core.service.AuditService;
+import org.onap.portalsdk.core.service.UserService;
+import org.onap.portalsdk.core.service.UserServiceCentalizedImpl;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
@@ -82,6 +94,9 @@ import org.springframework.web.client.HttpClientErrorException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ EcompPortalUtils.class, PortalConstants.class, SystemProperties.class,
+ EPCommonSystemProperties.class })
public class ExternalAccessRolesControllerTest {
@Mock
@@ -89,6 +104,11 @@ public class ExternalAccessRolesControllerTest {
@InjectMocks
ExternalAccessRolesController externalAccessRolesController = new ExternalAccessRolesController();
+ @Mock
+ UserService userservice = new UserServiceCentalizedImpl();
+
+ @Mock
+ AuditService auditService;
@Before
public void setup() {
@@ -234,20 +254,27 @@ public class ExternalAccessRolesControllerTest {
@Test
public void getRoleFunctionTest() throws Exception {
- String reason = getInvalidKeyJson();
+ EPApp mockApp = mockApp();
+ mockApp.setCentralAuth(true);
+ List<EPApp> mockAppList = new ArrayList<>();
+ mockAppList.add(mockApp);
StringWriter sw = new StringWriter();
PrintWriter writer = new PrintWriter(sw);
Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
- CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
- CentralRoleFunction centralRoleFunction = new CentralRoleFunction();
+ CentralV2RoleFunction roleFunction1 = new CentralV2RoleFunction();
+ CentralRoleFunction roleFunction2 = new CentralRoleFunction();
+ roleFunction1.setCode("test2");
String code = "test_menu";
- Mockito.when(externalAccessRolesService.getRoleFunction(code, mockedRequest.getHeader(uebKey)))
- .thenReturn(centralV2RoleFunction);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(mockAppList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(mockAppList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getRoleFunction(code, mockedRequest.getHeader("uebkey")))
+ .thenReturn(roleFunction1);
CentralRoleFunction returnedValue = externalAccessRolesController.getRoleFunction(mockedRequest, mockedResponse, code);
- BeanUtils.copyProperties(centralV2RoleFunction, centralRoleFunction, "type","action");
- assertEquals(returnedValue,centralRoleFunction);
+ assertEquals(returnedValue, roleFunction2);
String result = sw.getBuffer().toString().trim();
- assertEquals(reason, result);
+ assertEquals("", result);
}
@Test
@@ -319,19 +346,31 @@ public class ExternalAccessRolesControllerTest {
}
@Test
- @Ignore
public void deleteRoleFunctionTest() throws Exception {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
PortalRestResponse<String> portalRestResponse = null;
PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
expectedportalRestResponse.setMessage("Successfully Deleted");
expectedportalRestResponse.setResponse("Success");
PortalRestStatusEnum portalRestStatusEnum = null;
EPUser user = mockUser.mockEPUser();
+ List<EPUser> userList = new ArrayList<>();
+ userList.add(user);
EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(app);
expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
String code ="testNew";
- Mockito.when(externalAccessRolesService.getUser(mockedRequest.getHeader("LOGIN_ID"))).thenReturn((List<EPUser>) user);
- Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("UEBKEY")).get(0)).thenReturn(app);
+ Mockito.when(mockedRequest.getHeader("LoginId")).thenReturn("guestT");
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getUser(mockedRequest.getHeader("LoginId"))).thenReturn(userList);
Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(code, app)).thenReturn(true);
portalRestResponse = externalAccessRolesController.deleteRoleFunction(mockedRequest, mockedResponse, code);
assertEquals(portalRestResponse, expectedportalRestResponse);
@@ -344,7 +383,7 @@ public class ExternalAccessRolesControllerTest {
PrintWriter writer = new PrintWriter(sw);
Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
Mockito.when(externalAccessRolesService.getActiveRoles(mockedRequest.getHeader(uebKey))).thenReturn(null);
- List<CentralV2Role> expectedCenRole = externalAccessRolesController.getActiveRoles(mockedRequest, mockedResponse);
+ List<CentralRole> expectedCenRole = externalAccessRolesController.getActiveRoles(mockedRequest, mockedResponse);
assertNull(expectedCenRole);
String result = sw.getBuffer().toString().trim();
assertEquals(reason, result);
@@ -719,4 +758,106 @@ public class ExternalAccessRolesControllerTest {
PortalRestResponse<String> actualResponse = externalAccessRolesController.deleteRole(mockedRequest, mockedResponse, (long)1);
assertEquals(actualResponse, null);
}
+
+ @Test
+ public void getEpUserNullTest() throws Exception{
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setUebKey("uebKey");
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(app)).thenReturn(response);
+ assertNull(externalAccessRolesController.getEcompUser(mockedRequest, mockedResponse, "test12"));
+ }
+
+ @Test
+ public void getEpUserTest() throws Exception{
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setUebKey("uebKey");
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(app)).thenReturn(response);
+ String user = "{\"id\":null,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"orgId\":null,\"managerId\":null,\"firstName\":\"test\",\"middleInitial\":null,\"lastName\":null,\"phone\":null,\"fax\":null,\"cellular\":null,\"email\":null,\"addressId\":null,\"alertMethodCd\":null,\"hrid\":null,\"orgUserId\":null,\"orgCode\":null,\"address1\":null,\"address2\":null,\"city\":null,\"state\":null,\"zipCode\":null,\"country\":null,\"orgManagerUserId\":null,\"locationClli\":null,\"businessCountryCode\":null,\"businessCountryName\":null,\"businessUnit\":null,\"businessUnitName\":null,\"department\":null,\"departmentName\":null,\"companyCode\":null,\"company\":null,\"zipCodeSuffix\":null,\"jobTitle\":null,\"commandChain\":null,\"siloStatus\":null,\"costCenter\":null,\"financialLocCode\":null,\"loginId\":null,\"loginPwd\":null,\"lastLoginDate\":null,\"active\":false,\"internal\":false,\"selectedProfileId\":null,\"timeZoneId\":null,\"online\":false,\"chatId\":null,\"userApps\":[],\"pseudoRoles\":[],\"defaultUserApp\":null,\"roles\":[],\"fullName\":\"test null\"}";
+ Mockito.when(externalAccessRolesService.getV2UserWithRoles("test12", mockedRequest.getHeader(uebKey))).thenReturn(user);
+ User EPuser = new User();
+ EPuser.setFirstName("test");
+ Mockito.when(userservice.userMapper(user)).thenReturn(EPuser);
+ String res = "{\"orgId\":null,\"managerId\":null,\"firstName\":\"test\",\"middleInitial\":null,\"lastName\":null,\"phone\":null,\"email\":null,\"hrid\":null,\"orgUserId\":null,\"orgCode\":null,\"orgManagerUserId\":null,\"jobTitle\":null,\"loginId\":null,\"active\":false,\"roles\":[]}";
+ assertEquals(externalAccessRolesController.getEcompUser(mockedRequest, mockedResponse, "test12"),res);
+ }
+
+ @Test
+ public void getEpUserExceptionTest() throws Exception{
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(externalAccessRolesController.getEcompUser(mockedRequest, mockedResponse, "test12"));
+ }
+
+ @Test
+ public void getEPRolesOfApplicationTest() throws Exception
+ {
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setUebKey("uebKey");
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(app)).thenReturn(response);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ List<CentralV2Role> cenRoleList = new ArrayList<>();
+ CentralV2Role role = new CentralV2Role();
+ role.setName("test");
+ cenRoleList.add(role);
+ Mockito.when(externalAccessRolesService.getActiveRoles(mockedRequest.getHeader(uebKey))).thenReturn(cenRoleList);
+ List<EcompRole> ecompRoles = new ArrayList<>();
+ EcompRole eprole = new EcompRole();
+ eprole.setName("test");
+ ecompRoles.add(eprole);
+ assertEquals(ecompRoles,externalAccessRolesController.getEcompRolesOfApplication(mockedRequest, mockedResponse));
+ }
+ @Test
+ public void getEPRolesOfApplicationNullTest() throws Exception
+ {
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setUebKey("uebKey");
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(app)).thenReturn(response);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ List<CentralV2Role> cenRoleList = new ArrayList<>();
+ CentralV2Role role = new CentralV2Role();
+ role.setName("test");
+ cenRoleList.add(role);
+ Mockito.when(externalAccessRolesService.getActiveRoles(mockedRequest.getHeader(uebKey))).thenReturn(null);
+ assertNull(externalAccessRolesController.getEcompRolesOfApplication(mockedRequest, mockedResponse));
+
+ }
+
+ @Test
+ public void getEPRolesOfApplicationExceptionTest() throws Exception
+ {
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(externalAccessRolesController.getEcompRolesOfApplication(mockedRequest, mockedResponse));
+
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java
index 6f9ce496..ca94c8ce 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java
@@ -107,7 +107,7 @@ public class MicroserviceProxyControllerTest extends MockitoTestSuite {
Mockito.when(microserviceProxyService.proxyToDestination(1, user, mockedRequest))
.thenThrow(httpClientErrorException);
String acutualString = microserviceProxyController.getMicroserviceProxy(mockedRequest, getMockedResponse(), 1);
- assertEquals("", acutualString);
+ assertTrue(acutualString.equals("{\"error\":\"\"}"));
}
@Test
@@ -139,6 +139,6 @@ public class MicroserviceProxyControllerTest extends MockitoTestSuite {
.thenThrow(httpClientErrorException);
String acutualString = microserviceProxyController.getMicroserviceProxyByWidgetId(mockedRequest,
getMockedResponse(), 1);
- assertEquals("", acutualString);
+ assertTrue(acutualString.equals("{\"error\":\"\"}"));
}
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java
index 172b9421..295ba74b 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java
@@ -114,7 +114,7 @@ import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ EcompPortalUtils.class, Criterion.class, Restrictions.class, SystemProperties.class,
+@PrepareForTest({ EcompPortalUtils.class, Criterion.class, EPUserUtils.class, Restrictions.class, SystemProperties.class,
EPCommonSystemProperties.class })
public class ExternalAccessRolesServiceImplTest {
@Mock
@@ -533,7 +533,7 @@ public class ExternalAccessRolesServiceImplTest {
.thenReturn(getRoleFuncList);
CentralV2RoleFunction actual = externalAccessRolesServiceImpl.getRoleFunction("test_type|type_code|*",
app.getUebKey());
- assertEquals(getCenRole.getCode(), actual.getCode());
+ assertEquals("type_code", actual.getCode());
}
@Test
@@ -717,6 +717,8 @@ public class ExternalAccessRolesServiceImplTest {
@SuppressWarnings("deprecation")
@Test
public void getAllAppUsersTest() throws Exception {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
EPApp app = new EPApp();
app.setEnabled(true);
app.setId((long) 10);
@@ -737,13 +739,23 @@ public class ExternalAccessRolesServiceImplTest {
ecompUserRoles.setOrgUserId("guestT");
ecompUserRoles.setRoleId((long) 1);
ecompUserRoles.setRoleName("test");
+ ecompUserRoles.setFunctionCode("test_type|test_instance|test_action");
+ ecompUserRoles.setFunctionName("test1");
EcompUserRoles ecompUserRoles2 = new EcompUserRoles();
ecompUserRoles2.setOrgUserId("guestT");
ecompUserRoles2.setRoleId((long) 2);
ecompUserRoles2.setRoleName("test new");
+ ecompUserRoles2.setFunctionCode("test_instance2");
+ ecompUserRoles2.setFunctionName("test2");
userList.add(ecompUserRoles);
userList.add(ecompUserRoles2);
- Mockito.when(dataAccessService.executeNamedQuery("ApplicationUserRoles", appParams, null)).thenReturn(userList);
+ Mockito.when(EcompPortalUtils.getFunctionCode(ecompUserRoles.getFunctionCode())).thenReturn("test_instance");
+ Mockito.when(EPUserUtils.decodeFunctionCode("test_instance")).thenReturn("test_instance");
+ Mockito.when(EcompPortalUtils.getFunctionCode(ecompUserRoles2.getFunctionCode())).thenReturn("test_instance2");
+ Mockito.when(EPUserUtils.decodeFunctionCode("test_instance2")).thenReturn("test_instance2");
+ Mockito.when(EcompPortalUtils.getFunctionType("test_type|test_instance|test_action")).thenReturn("test_type");
+ Mockito.when(EcompPortalUtils.getFunctionAction("test_type|test_instance|test_action")).thenReturn("test_action");
+ Mockito.when(dataAccessService.executeNamedQuery("ApplicationUserRoles", appParams, null)).thenReturn(userList);
List<EcompUser> usersfinalList = externalAccessRolesServiceImpl.getAllAppUsers(app.getUebKey());
assertEquals(usersfinalList.get(0).getRoles().size(), 2);
}