summaryrefslogtreecommitdiffstats
path: root/portal-BE/src/main/java/org/onap
diff options
context:
space:
mode:
authorDominik Mizyn <d.mizyn@samsung.com>2020-03-02 15:22:37 +0100
committerDominik Mizyn <d.mizyn@samsung.com>2020-03-02 15:22:41 +0100
commit786310021cda6f7cd181da7aed8afa38e3f10efa (patch)
treea48e57b5325c3a33b21409c91005948a25f59605 /portal-BE/src/main/java/org/onap
parentca3d9f4b725774763f12488940033a294b778244 (diff)
UserRolesController methods up
UserRolesController methods up and all needed services Issue-ID: PORTAL-710 Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com> Change-Id: Id9dc0b7c52ab50d9e5914195c352026b5bc5971d
Diffstat (limited to 'portal-BE/src/main/java/org/onap')
-rw-r--r--portal-BE/src/main/java/org/onap/portal/controller/UserRolesController.java891
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java5
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUserRole.java4
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java44
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/SearchService.java179
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java4
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/user/FnUserDao.java3
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/user/FnUserService.java244
-rw-r--r--portal-BE/src/main/java/org/onap/portal/utils/EPSystemProperties.java61
9 files changed, 943 insertions, 492 deletions
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/UserRolesController.java b/portal-BE/src/main/java/org/onap/portal/controller/UserRolesController.java
index 2298e4d3..120b8bc5 100644
--- a/portal-BE/src/main/java/org/onap/portal/controller/UserRolesController.java
+++ b/portal-BE/src/main/java/org/onap/portal/controller/UserRolesController.java
@@ -66,6 +66,7 @@ import org.onap.portal.logging.aop.EPEELFLoggerAdvice;
import org.onap.portal.logging.logic.EPLogUtil;
import org.onap.portal.service.AdminRolesService;
import org.onap.portal.service.ApplicationsRestClientService;
+import org.onap.portal.service.SearchService;
import org.onap.portal.service.userRole.FnUserRoleService;
import org.onap.portal.service.user.FnUserService;
import org.onap.portal.utils.EPCommonSystemProperties;
@@ -79,6 +80,7 @@ import org.onap.portalsdk.core.util.SystemProperties;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
+import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -90,481 +92,488 @@ import org.springframework.web.bind.annotation.RestController;
@Configuration
public class UserRolesController {
- private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserRolesController.class);
-
- private final FnUserService fnUserService;
- private final FnUserRoleService fnUserRoleService;
- private final AdminRolesService adminRolesService;
- private final ApplicationsRestClientService applicationsRestClientService;
- private final AuditServiceImpl auditService = new AuditServiceImpl();
-
- private static final String FAILURE = "failure";
-
- @Autowired
- public UserRolesController(final FnUserService fnUserService,
- FnUserRoleService fnUserRoleService,
- final AdminRolesService adminRolesService,
- ApplicationsRestClientService applicationsRestClientService) {
- this.fnUserService = fnUserService;
- this.fnUserRoleService = fnUserRoleService;
- this.adminRolesService = adminRolesService;
- this.applicationsRestClientService = applicationsRestClientService;
- }
-
-
- /*
- @RequestMapping(value = {"/portalApi/queryUsers"}, method = RequestMethod.GET, produces = "application/json")
- @PreAuthorize("hasRole('System_Administrator') and hasRole('Account_Administrator')")
- public String getPhoneBookSearchResult(Principal principal, @RequestParam("search") String searchString,
- HttpServletResponse response) {
- FnUser user = fnUserService.loadUserByUsername(principal.getName());
-
- String searchResult = null;
- if (!adminRolesService.isSuperAdmin(user) && !adminRolesService.isAccountAdmin(user)
- && !adminRolesService.isRoleAdmin(user)) {
- EcompPortalUtils.setBadPermissions(user, response, "getPhoneBookSearchResult");
- } else {
- searchString = searchString.trim();
- if (searchString.length() > 2) {
- searchResult = searchService.searchUsersInPhoneBook(searchString);
- } else {
- logger.info(EELFLoggerDelegate.errorLogger,
- "getPhoneBookSearchResult - too short search string: " + searchString);
- }
- }
- EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/queryUsers", "result =", searchResult);
-
- return searchResult;
- }
-
-
- @RequestMapping(value = {"/portalApi/adminAppsRoles"}, method = {
- RequestMethod.GET}, produces = "application/json")
- public AppsListWithAdminRole getAppsWithAdminRoleStateForUser(Principal principal,
- @RequestParam("user") String orgUserId, HttpServletResponse response) {
-
- FnUser user = fnUserService.loadUserByUsername(principal.getName());
-
- AppsListWithAdminRole result = null;
- if (!adminRolesService.isSuperAdmin(user)) {
- EcompPortalUtils.setBadPermissions(user, response, "getAppsWithAdminRoleStateForUser");
- } else {
- if (EcompPortalUtils.legitimateUserId(orgUserId)) {
- result = adminRolesService.getAppsWithAdminRoleStateForUser(orgUserId);
- } else {
- logger.info(EELFLoggerDelegate.errorLogger,
- "getAppsWithAdminRoleStateForUser - parms error, no Organization User ID");
- response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- }
- }
+ private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserRolesController.class);
+
+ private final SearchService searchService;
+ private final FnUserService fnUserService;
+ private final FnUserRoleService fnUserRoleService;
+ private final AdminRolesService adminRolesService;
+ private final ApplicationsRestClientService applicationsRestClientService;
+ private final AuditServiceImpl auditService = new AuditServiceImpl();
+
+ private static final String FAILURE = "failure";
+
+ @Autowired
+ public UserRolesController(SearchService searchService, final FnUserService fnUserService,
+ FnUserRoleService fnUserRoleService,
+ final AdminRolesService adminRolesService,
+ ApplicationsRestClientService applicationsRestClientService) {
+ this.searchService = searchService;
+ this.fnUserService = fnUserService;
+ this.fnUserRoleService = fnUserRoleService;
+ this.adminRolesService = adminRolesService;
+ this.applicationsRestClientService = applicationsRestClientService;
+ }
- StringBuilder adminAppRoles = new StringBuilder();
- if (result != null) {
- if (!result.appsRoles.isEmpty()) {
- adminAppRoles.append("User '" + result.orgUserId + "' has admin role to the apps = {");
- for (AppNameIdIsAdmin adminAppRole : result.appsRoles) {
- if (adminAppRole.isAdmin) {
- adminAppRoles.append(adminAppRole.appName + ", ");
- }
- }
- adminAppRoles.append("}.");
- } else {
- adminAppRoles.append("User '" + result.orgUserId + "' has no Apps with Admin Role.");
- }
- } else {
- logger.error(EELFLoggerDelegate.errorLogger,
- "putAppWithUserRoleStateForUser: getAppsWithAdminRoleStateForUser result is null");
- }
- logger.info(EELFLoggerDelegate.errorLogger, adminAppRoles.toString());
-
- EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/adminAppsRoles", "get result =", result);
-
- return result;
- }
-*/
- @RequestMapping(value = {"/portalApi/adminAppsRoles"}, method = {
- RequestMethod.PUT}, produces = "application/json")
- public FieldsValidator putAppsWithAdminRoleStateForUser(Principal principal,
- @RequestBody AppsListWithAdminRole newAppsListWithAdminRoles, HttpServletResponse response) {
- // newAppsListWithAdminRoles.appsRoles
- FieldsValidator fieldsValidator = new FieldsValidator();
- StringBuilder newAppRoles = new StringBuilder();
- if (newAppsListWithAdminRoles != null) {
- if (!newAppsListWithAdminRoles.getAppsRoles().isEmpty()) {
- newAppRoles.append("User '").append(newAppsListWithAdminRoles.getOrgUserId())
- .append("' has admin role to the apps = { ");
- for (AppNameIdIsAdmin adminAppRole : newAppsListWithAdminRoles.getAppsRoles()) {
- if (adminAppRole.getIsAdmin()) {
- newAppRoles.append(adminAppRole.getAppName()).append(" ,");
- }
+ @RequestMapping(value = {"/portalApi/queryUsers"}, method = RequestMethod.GET, produces = "application/json")
+ @PreAuthorize("hasRole('System_Administrator') and hasRole('Account_Administrator')")
+ public String getPhoneBookSearchResult(Principal principal, @RequestParam("search") String searchString,
+ HttpServletResponse response) {
+ FnUser user = fnUserService.loadUserByUsername(principal.getName());
+
+ String searchResult = null;
+ if (!adminRolesService.isSuperAdmin(user.getLoginId()) && !adminRolesService
+ .isAccountAdmin(user.getId(), user.getOrgUserId(), user.getUserApps())
+ && !adminRolesService.isRoleAdmin(user.getId())) {
+ EcompPortalUtils.setBadPermissions(user, response, "getPhoneBookSearchResult");
+ } else {
+ searchString = searchString.trim();
+ if (searchString.length() > 2) {
+ searchResult = searchService.searchUsersInPhoneBook(searchString);
+ } else {
+ logger.info(EELFLoggerDelegate.errorLogger,
+ "getPhoneBookSearchResult - too short search string: " + searchString);
+ }
}
- newAppRoles.deleteCharAt(newAppRoles.length() - 1);
- newAppRoles.append("}.");
- } else {
- newAppRoles.append("User '").append(newAppsListWithAdminRoles.getOrgUserId())
- .append("' has no Apps with Admin Role.");
- }
- } else {
- logger.error(EELFLoggerDelegate.errorLogger,
- "putAppWithUserRoleStateForUser: putAppsWithAdminRoleStateForUser result is null");
- fieldsValidator.setHttpStatusCode((long) HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
+ EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/queryUsers", "result =", searchResult);
- logger.info(EELFLoggerDelegate.errorLogger, newAppRoles.toString());
-
- FnUser user = fnUserService.loadUserByUsername(principal.getName());
-
- boolean changesApplied = false;
-
- if (!adminRolesService.isSuperAdmin(user.getLoginId())) {
- EcompPortalUtils.setBadPermissions(user, response, "putAppsWithAdminRoleStateForUser");
- } else {
- changesApplied = adminRolesService.setAppsWithAdminRoleStateForUser(newAppsListWithAdminRoles);
- AuditLog auditLog = new AuditLog();
- auditLog.setUserId(user.getId());
- auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN);
- if (newAppsListWithAdminRoles != null) {
- auditLog.setAffectedRecordId(newAppsListWithAdminRoles.getOrgUserId());
- }
- auditLog.setComments(
- EcompPortalUtils
- .truncateString(newAppRoles.toString(), PortalConstants.AUDIT_LOG_COMMENT_SIZE));
- auditService.logActivity(auditLog, null);
-
- MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
- EPEELFLoggerAdvice.getCurrentDateTimeUTC());
- MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,
- EPEELFLoggerAdvice.getCurrentDateTimeUTC());
- EcompPortalUtils.calculateDateTimeDifferenceForLog(
- MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
- MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
- if (newAppsListWithAdminRoles != null) {
- logger.info(EELFLoggerDelegate.auditLogger,
- EPLogUtil.formatAuditLogMessage(
- "UserRolesController.putAppsWithAdminRoleStateForUser",
- EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN, user.getOrgUserId(),
- newAppsListWithAdminRoles.getOrgUserId(), newAppRoles.toString()));
- }
- MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
- MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
- MDC.remove(SystemProperties.MDC_TIMER);
+ return searchResult;
}
- EcompPortalUtils
- .logAndSerializeObject(logger, "/portalApi/adminAppsRoles", "put result =", changesApplied);
-
- return fieldsValidator;
- }
-
- @RequestMapping(value = {"/portalApi/userAppRoles"}, method = {
- RequestMethod.GET}, produces = "application/json")
- public List<RoleInAppForUser> getAppRolesForUser(Principal principal,
- @RequestParam("user") String orgUserId,
- @RequestParam("app") Long appid, @RequestParam("externalRequest") Boolean extRequestValue,
- @RequestParam("isSystemUser") Boolean isSystemUser,
- HttpServletResponse response) {
- FnUser user = fnUserService.loadUserByUsername(principal.getName());
- List<RoleInAppForUser> result = null;
- String feErrorString = "";
- if (!adminRolesService.isAccountAdmin(user.getId(), user.getOrgUserId(), user.getUserApps()) && !adminRolesService.isRoleAdmin(user.getId())) {
- logger.debug(EELFLoggerDelegate.debugLogger,
- "getAppRolesForUser: Accountadminpermissioncheck {}, RoleAdmincheck {}",
- adminRolesService.isAccountAdmin(user.getId(), user.getOrgUserId(), user.getUserApps()), adminRolesService.isRoleAdmin(user.getId()));
- EcompPortalUtils.setBadPermissions(user, response, "getAppRolesForUser");
- feErrorString = EcompPortalUtils.getFEErrorString(true, response.getStatus());
- } else {
- if (isSystemUser || EcompPortalUtils.legitimateUserId(orgUserId)) {
- result = adminRolesService.getAppRolesForUser(appid, orgUserId, extRequestValue, user.getId());
- logger.debug(EELFLoggerDelegate.debugLogger, "getAppRolesForUser: result {}, appId {}",
- result, appid);
- int responseCode = EcompPortalUtils.getExternalAppResponseCode();
- if (responseCode != 0 && responseCode != 200) {
- // external error
- response.setStatus(responseCode);
- feErrorString = EcompPortalUtils.getFEErrorString(false, responseCode);
- } else if (result == null) {
- // If the result is null, there was an internal onap error
- // in the service call.
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- feErrorString = EcompPortalUtils.getFEErrorString(true,
- HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+
+
+ @RequestMapping(value = {"/portalApi/adminAppsRoles"}, method = {
+ RequestMethod.GET}, produces = "application/json")
+ public AppsListWithAdminRole getAppsWithAdminRoleStateForUser(Principal principal,
+ @RequestParam("user") String orgUserId, HttpServletResponse response) {
+
+ FnUser user = fnUserService.loadUserByUsername(principal.getName());
+
+ AppsListWithAdminRole result = null;
+ if (!adminRolesService.isSuperAdmin(user.getLoginId())) {
+ EcompPortalUtils.setBadPermissions(user, response, "getAppsWithAdminRoleStateForUser");
+ } else {
+ if (EcompPortalUtils.legitimateUserId(orgUserId)) {
+ result = adminRolesService.getAppsWithAdminRoleStateForUser(orgUserId);
+ } else {
+ logger.info(EELFLoggerDelegate.errorLogger,
+ "getAppsWithAdminRoleStateForUser - parms error, no Organization User ID");
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ }
}
- } else {
- logger.info(EELFLoggerDelegate.errorLogger, "getAppRolesForUser - no Organization User ID");
- response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- feErrorString = EcompPortalUtils.getFEErrorString(true, HttpServletResponse.SC_BAD_REQUEST);
- }
- }
- StringBuilder sbUserApps = new StringBuilder();
- if (result != null && !result.isEmpty()) {
- sbUserApps.append("User '").append(orgUserId).append("' has Roles={");
- for (RoleInAppForUser appRole : result) {
- if (appRole.getIsApplied()) {
- sbUserApps.append(appRole.getRoleName()).append(", ");
+ StringBuilder adminAppRoles = new StringBuilder();
+ if (result != null) {
+ if (!result.getAppsRoles().isEmpty()) {
+ adminAppRoles.append("User '").append(result.getOrgUserId())
+ .append("' has admin role to the apps = {");
+ for (AppNameIdIsAdmin adminAppRole : result.getAppsRoles()) {
+ if (adminAppRole.getIsAdmin()) {
+ adminAppRoles.append(adminAppRole.getAppName()).append(", ");
+ }
+ }
+ adminAppRoles.append("}.");
+ } else {
+ adminAppRoles.append("User '").append(result.getOrgUserId())
+ .append("' has no Apps with Admin Role.");
+ }
+ } else {
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "putAppWithUserRoleStateForUser: getAppsWithAdminRoleStateForUser result is null");
}
- }
- sbUserApps.append("} assigned to the appId '").append(appid).append("'.");
- } else {
- // Not sure creating an empty object will make any difference
- // but would like to give it a shot for defect #DE221057
- if (result == null) {
- result = new ArrayList<>();
- }
- sbUserApps.append("User '").append(orgUserId).append("' and appid ").append(appid).append(" has no roles");
- }
- logger.info(EELFLoggerDelegate.errorLogger, sbUserApps.toString());
- EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppRoles", "get result =", result);
- if (!feErrorString.isEmpty()) {
- logger.debug(EELFLoggerDelegate.debugLogger, "LR: FEErrorString to header: " + feErrorString);
+ logger.info(EELFLoggerDelegate.errorLogger, adminAppRoles.toString());
+
+ EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/adminAppsRoles", "get result =", result);
- response.addHeader("FEErrorString", feErrorString);
- response.addHeader("Access-Control-Expose-Headers", "FEErrorString");
+ return result;
}
- return result;
- }
-
-
- @RequestMapping(value = {"/portalApi/userAppRoles"}, method = {
- RequestMethod.PUT}, produces = "application/json")
- public PortalRestResponse<String> putAppWithUserRoleStateForUser(Principal principal,
- @RequestBody AppWithRolesForUser newAppRolesForUser, HttpServletResponse response) {
- // FieldsValidator fieldsValidator = new FieldsValidator();
- PortalRestResponse<String> portalResponse = new PortalRestResponse<>();
- StringBuilder sbUserApps = new StringBuilder();
- if (newAppRolesForUser != null) {
- sbUserApps.append("User '").append(newAppRolesForUser.getOrgUserId());
- if (newAppRolesForUser.getAppId() != null && !newAppRolesForUser.getAppRoles().isEmpty()) {
- sbUserApps.append("' has roles = { ");
- for (RoleInAppForUser appRole : newAppRolesForUser.getAppRoles()) {
- if (appRole.getIsApplied()) {
- sbUserApps.append(appRole.getRoleName()).append(" ,");
- }
+
+ @RequestMapping(value = {"/portalApi/adminAppsRoles"}, method = {
+ RequestMethod.PUT}, produces = "application/json")
+ public FieldsValidator putAppsWithAdminRoleStateForUser(Principal principal,
+ @RequestBody AppsListWithAdminRole newAppsListWithAdminRoles, HttpServletResponse response) {
+ // newAppsListWithAdminRoles.appsRoles
+ FieldsValidator fieldsValidator = new FieldsValidator();
+ StringBuilder newAppRoles = new StringBuilder();
+ if (newAppsListWithAdminRoles != null) {
+ if (!newAppsListWithAdminRoles.getAppsRoles().isEmpty()) {
+ newAppRoles.append("User '").append(newAppsListWithAdminRoles.getOrgUserId())
+ .append("' has admin role to the apps = { ");
+ for (AppNameIdIsAdmin adminAppRole : newAppsListWithAdminRoles.getAppsRoles()) {
+ if (adminAppRole.getIsAdmin()) {
+ newAppRoles.append(adminAppRole.getAppName()).append(" ,");
+ }
+ }
+ newAppRoles.deleteCharAt(newAppRoles.length() - 1);
+ newAppRoles.append("}.");
+ } else {
+ newAppRoles.append("User '").append(newAppsListWithAdminRoles.getOrgUserId())
+ .append("' has no Apps with Admin Role.");
+ }
+ } else {
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "putAppWithUserRoleStateForUser: putAppsWithAdminRoleStateForUser result is null");
+ fieldsValidator.setHttpStatusCode((long) HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ logger.info(EELFLoggerDelegate.errorLogger, newAppRoles.toString());
+
+ FnUser user = fnUserService.loadUserByUsername(principal.getName());
+
+ boolean changesApplied = false;
+
+ if (!adminRolesService.isSuperAdmin(user.getLoginId())) {
+ EcompPortalUtils.setBadPermissions(user, response, "putAppsWithAdminRoleStateForUser");
+ } else {
+ changesApplied = adminRolesService.setAppsWithAdminRoleStateForUser(newAppsListWithAdminRoles);
+ AuditLog auditLog = new AuditLog();
+ auditLog.setUserId(user.getId());
+ auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN);
+ if (newAppsListWithAdminRoles != null) {
+ auditLog.setAffectedRecordId(newAppsListWithAdminRoles.getOrgUserId());
+ }
+ auditLog.setComments(
+ EcompPortalUtils
+ .truncateString(newAppRoles.toString(), PortalConstants.AUDIT_LOG_COMMENT_SIZE));
+ auditService.logActivity(auditLog, null);
+
+ MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
+ EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,
+ EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ EcompPortalUtils.calculateDateTimeDifferenceForLog(
+ MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
+ MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
+ if (newAppsListWithAdminRoles != null) {
+ logger.info(EELFLoggerDelegate.auditLogger,
+ EPLogUtil.formatAuditLogMessage(
+ "UserRolesController.putAppsWithAdminRoleStateForUser",
+ EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN, user.getOrgUserId(),
+ newAppsListWithAdminRoles.getOrgUserId(), newAppRoles.toString()));
+ }
+ MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
+ MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
+ MDC.remove(SystemProperties.MDC_TIMER);
}
- sbUserApps.deleteCharAt(sbUserApps.length() - 1);
- sbUserApps.append("} assigned for the app ").append(newAppRolesForUser.getAppId());
- } else {
- sbUserApps.append("' has no roles assigned for app ").append(newAppRolesForUser.getAppId());
- }
+ EcompPortalUtils
+ .logAndSerializeObject(logger, "/portalApi/adminAppsRoles", "put result =", changesApplied);
+
+ return fieldsValidator;
}
- logger.info(EELFLoggerDelegate.applicationLogger, "putAppWithUserRoleStateForUser: {}",
- sbUserApps.toString());
-
- FnUser user = fnUserService.loadUserByUsername(principal.getName());
- // boolean changesApplied = false;
- ExternalRequestFieldsValidator changesApplied = null;
-
- if (!adminRolesService.isAccountAdmin(user.getId(), user.getOrgUserId(), user.getUserApps()) && !adminRolesService.isRoleAdmin(user.getId())) {
- EcompPortalUtils.setBadPermissions(user, response, "putAppWithUserRoleStateForUser");
- } else if (newAppRolesForUser == null) {
- logger.error(EELFLoggerDelegate.errorLogger,
- "putAppWithUserRoleStateForUser: newAppRolesForUser is null");
- } else {
- changesApplied = adminRolesService.setAppWithUserRoleStateForUser(user, newAppRolesForUser);
- try {
- if (changesApplied.isResult()) {
- logger.info(EELFLoggerDelegate.applicationLogger,
- "putAppWithUserRoleStateForUser: succeeded for app {}, user {}",
- newAppRolesForUser.getAppId(),
- newAppRolesForUser.getAppId());
-
- MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
- EPEELFLoggerAdvice.getCurrentDateTimeUTC());
- AuditLog auditLog = new AuditLog();
- auditLog.setUserId(user.getId());
- auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_UPDATE_USER);
- auditLog.setAffectedRecordId(newAppRolesForUser.getOrgUserId());
- auditLog.setComments(EcompPortalUtils.truncateString(sbUserApps.toString(),
- PortalConstants.AUDIT_LOG_COMMENT_SIZE));
- auditService.logActivity(auditLog, null);
-
- MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,
- EPEELFLoggerAdvice.getCurrentDateTimeUTC());
- EcompPortalUtils.calculateDateTimeDifferenceForLog(
- MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
- MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
- logger.info(EELFLoggerDelegate.auditLogger,
- EPLogUtil.formatAuditLogMessage(
- "UserRolesController.putAppWithUserRoleStateForUser",
- EcompAuditLog.CD_ACTIVITY_UPDATE_USER, user.getOrgUserId(),
- newAppRolesForUser.getOrgUserId(), sbUserApps.toString()));
- MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
- MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
- MDC.remove(SystemProperties.MDC_TIMER);
- portalResponse = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", null);
+ @RequestMapping(value = {"/portalApi/userAppRoles"}, method = {
+ RequestMethod.GET}, produces = "application/json")
+ public List<RoleInAppForUser> getAppRolesForUser(Principal principal,
+ @RequestParam("user") String orgUserId,
+ @RequestParam("app") Long appid, @RequestParam("externalRequest") Boolean extRequestValue,
+ @RequestParam("isSystemUser") Boolean isSystemUser,
+ HttpServletResponse response) {
+ FnUser user = fnUserService.loadUserByUsername(principal.getName());
+ List<RoleInAppForUser> result = null;
+ String feErrorString = "";
+ if (!adminRolesService.isAccountAdmin(user.getId(), user.getOrgUserId(), user.getUserApps())
+ && !adminRolesService.isRoleAdmin(user.getId())) {
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "getAppRolesForUser: Accountadminpermissioncheck {}, RoleAdmincheck {}",
+ adminRolesService.isAccountAdmin(user.getId(), user.getOrgUserId(), user.getUserApps()),
+ adminRolesService.isRoleAdmin(user.getId()));
+ EcompPortalUtils.setBadPermissions(user, response, "getAppRolesForUser");
+ feErrorString = EcompPortalUtils.getFEErrorString(true, response.getStatus());
+ } else {
+ if (isSystemUser || EcompPortalUtils.legitimateUserId(orgUserId)) {
+ result = adminRolesService.getAppRolesForUser(appid, orgUserId, extRequestValue, user.getId());
+ logger.debug(EELFLoggerDelegate.debugLogger, "getAppRolesForUser: result {}, appId {}",
+ result, appid);
+ int responseCode = EcompPortalUtils.getExternalAppResponseCode();
+ if (responseCode != 0 && responseCode != 200) {
+ // external error
+ response.setStatus(responseCode);
+ feErrorString = EcompPortalUtils.getFEErrorString(false, responseCode);
+ } else if (result == null) {
+ // If the result is null, there was an internal onap error
+ // in the service call.
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ feErrorString = EcompPortalUtils.getFEErrorString(true,
+ HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ } else {
+ logger.info(EELFLoggerDelegate.errorLogger, "getAppRolesForUser - no Organization User ID");
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ feErrorString = EcompPortalUtils.getFEErrorString(true, HttpServletResponse.SC_BAD_REQUEST);
+ }
}
- if (!changesApplied.isResult()) {
- throw new Exception(changesApplied.getDetailMessage());
+
+ StringBuilder sbUserApps = new StringBuilder();
+ if (result != null && !result.isEmpty()) {
+ sbUserApps.append("User '").append(orgUserId).append("' has Roles={");
+ for (RoleInAppForUser appRole : result) {
+ if (appRole.getIsApplied()) {
+ sbUserApps.append(appRole.getRoleName()).append(", ");
+ }
+ }
+ sbUserApps.append("} assigned to the appId '").append(appid).append("'.");
+ } else {
+ // Not sure creating an empty object will make any difference
+ // but would like to give it a shot for defect #DE221057
+ if (result == null) {
+ result = new ArrayList<>();
+ }
+ sbUserApps.append("User '").append(orgUserId).append("' and appid ").append(appid).append(" has no roles");
}
+ logger.info(EELFLoggerDelegate.errorLogger, sbUserApps.toString());
+
+ EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppRoles", "get result =", result);
+ if (!feErrorString.isEmpty()) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "LR: FEErrorString to header: " + feErrorString);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,
- "putAppWithUserRoleStateForUser: failed for app {}, user {}",
- newAppRolesForUser.getAppId(),
- newAppRolesForUser.getOrgUserId(), e);
- portalResponse = new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), null);
- }
+ response.addHeader("FEErrorString", feErrorString);
+ response.addHeader("Access-Control-Expose-Headers", "FEErrorString");
+ }
+ return result;
}
- EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppRoles", "put result =", changesApplied);
- return portalResponse;
- }
-
- @RequestMapping(value = {"/portalApi/updateRemoteUserProfile"}, method = {
- RequestMethod.GET}, produces = "application/json")
- public PortalRestResponse<String> updateRemoteUserProfile(HttpServletRequest request) {
-
- String updateRemoteUserFlag = FAILURE;
- try {
- // saveNewUser = userService.saveNewUser(newUser);
- String orgUserId = request.getParameter("loginId");
- long appId = Long.parseLong(request.getParameter("appId"));
- fnUserRoleService.updateRemoteUserProfile(orgUserId, appId);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "updateRemoteUserProfile failed", e);
- return new PortalRestResponse<>(PortalRestStatusEnum.OK, updateRemoteUserFlag, e.getMessage());
+
+ @RequestMapping(value = {"/portalApi/userAppRoles"}, method = {
+ RequestMethod.PUT}, produces = "application/json")
+ public PortalRestResponse<String> putAppWithUserRoleStateForUser(Principal principal,
+ @RequestBody AppWithRolesForUser newAppRolesForUser, HttpServletResponse response) {
+ // FieldsValidator fieldsValidator = new FieldsValidator();
+ PortalRestResponse<String> portalResponse = new PortalRestResponse<>();
+ StringBuilder sbUserApps = new StringBuilder();
+ if (newAppRolesForUser != null) {
+ sbUserApps.append("User '").append(newAppRolesForUser.getOrgUserId());
+ if (newAppRolesForUser.getAppId() != null && !newAppRolesForUser.getAppRoles().isEmpty()) {
+ sbUserApps.append("' has roles = { ");
+ for (RoleInAppForUser appRole : newAppRolesForUser.getAppRoles()) {
+ if (appRole.getIsApplied()) {
+ sbUserApps.append(appRole.getRoleName()).append(" ,");
+ }
+ }
+ sbUserApps.deleteCharAt(sbUserApps.length() - 1);
+ sbUserApps.append("} assigned for the app ").append(newAppRolesForUser.getAppId());
+ } else {
+ sbUserApps.append("' has no roles assigned for app ").append(newAppRolesForUser.getAppId());
+ }
+ }
+ logger.info(EELFLoggerDelegate.applicationLogger, "putAppWithUserRoleStateForUser: {}",
+ sbUserApps.toString());
+
+ FnUser user = fnUserService.loadUserByUsername(principal.getName());
+ // boolean changesApplied = false;
+ ExternalRequestFieldsValidator changesApplied = null;
+
+ if (!adminRolesService.isAccountAdmin(user.getId(), user.getOrgUserId(), user.getUserApps())
+ && !adminRolesService.isRoleAdmin(user.getId())) {
+ EcompPortalUtils.setBadPermissions(user, response, "putAppWithUserRoleStateForUser");
+ } else if (newAppRolesForUser == null) {
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "putAppWithUserRoleStateForUser: newAppRolesForUser is null");
+ } else {
+ changesApplied = adminRolesService.setAppWithUserRoleStateForUser(user, newAppRolesForUser);
+ try {
+ if (changesApplied.isResult()) {
+ logger.info(EELFLoggerDelegate.applicationLogger,
+ "putAppWithUserRoleStateForUser: succeeded for app {}, user {}",
+ newAppRolesForUser.getAppId(),
+ newAppRolesForUser.getAppId());
+
+ MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
+ EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ AuditLog auditLog = new AuditLog();
+ auditLog.setUserId(user.getId());
+ auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_UPDATE_USER);
+ auditLog.setAffectedRecordId(newAppRolesForUser.getOrgUserId());
+ auditLog.setComments(EcompPortalUtils.truncateString(sbUserApps.toString(),
+ PortalConstants.AUDIT_LOG_COMMENT_SIZE));
+ auditService.logActivity(auditLog, null);
+
+ MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,
+ EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ EcompPortalUtils.calculateDateTimeDifferenceForLog(
+ MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
+ MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
+ logger.info(EELFLoggerDelegate.auditLogger,
+ EPLogUtil.formatAuditLogMessage(
+ "UserRolesController.putAppWithUserRoleStateForUser",
+ EcompAuditLog.CD_ACTIVITY_UPDATE_USER, user.getOrgUserId(),
+ newAppRolesForUser.getOrgUserId(), sbUserApps.toString()));
+ MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
+ MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
+ MDC.remove(SystemProperties.MDC_TIMER);
+ portalResponse = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", null);
+
+ }
+ if (!changesApplied.isResult()) {
+ throw new Exception(changesApplied.getDetailMessage());
+ }
+
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "putAppWithUserRoleStateForUser: failed for app {}, user {}",
+ newAppRolesForUser.getAppId(),
+ newAppRolesForUser.getOrgUserId(), e);
+ portalResponse = new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), null);
+ }
+ }
+
+ EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppRoles", "put result =", changesApplied);
+ return portalResponse;
}
- return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, updateRemoteUserFlag, "");
-
- }
-
- @RequestMapping(value = {"/portalApi/app/{appId}/users"}, method = {
- RequestMethod.GET}, produces = "application/json")
- public List<UserApplicationRoles> getUsersFromAppEndpoint(@PathVariable("appId") Long appId) {
- try {
- logger.debug(EELFLoggerDelegate.debugLogger, "/portalApi/app/{}/users was invoked", appId);
- return fnUserRoleService.getUsersFromAppEndpoint(appId);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "getUsersFromAppEndpoint failed", e);
- return new ArrayList<>();
+
+ @RequestMapping(value = {"/portalApi/updateRemoteUserProfile"}, method = {
+ RequestMethod.GET}, produces = "application/json")
+ public PortalRestResponse<String> updateRemoteUserProfile(HttpServletRequest request) {
+
+ String updateRemoteUserFlag = FAILURE;
+ try {
+ // saveNewUser = userService.saveNewUser(newUser);
+ String orgUserId = request.getParameter("loginId");
+ long appId = Long.parseLong(request.getParameter("appId"));
+ fnUserRoleService.updateRemoteUserProfile(orgUserId, appId);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "updateRemoteUserProfile failed", e);
+ return new PortalRestResponse<>(PortalRestStatusEnum.OK, updateRemoteUserFlag, e.getMessage());
+ }
+ return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, updateRemoteUserFlag, "");
+
}
- }
-
- @RequestMapping(value = {"/portalApi/app/{appId}/roles"}, method = {
- RequestMethod.GET}, produces = "application/json")
- public List<EcompRole> testGetRoles(HttpServletRequest request, @PathVariable("appId") Long appId)
- throws HTTPException {
- EcompRole[] appRoles = applicationsRestClientService.get(EcompRole[].class, appId, "/roles");
- List<EcompRole> rolesList = Arrays.asList(appRoles);
- EcompPortalUtils
- .logAndSerializeObject(logger, "/portalApi/app/{appId}/roles", "response for appId=" + appId,
- rolesList);
-
- return rolesList;
- }
-
-
- @RequestMapping(value = {"/portalApi/admin/import/app/{appId}/roles"}, method = {
- RequestMethod.GET}, produces = "application/json")
- public List<FnRole> importRolesFromRemoteApplication(@PathVariable("appId") Long appId) throws HTTPException {
- List<FnRole> rolesList = fnUserRoleService.importRolesFromRemoteApplication(appId);
- EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/admin/import/app/{appId}/roles",
- "response for appId=" + appId, rolesList);
-
- return rolesList;
- }
-
-
- @RequestMapping(value = {"/portalApi/app/{appId}/user/{orgUserId}/roles"}, method = {
- RequestMethod.GET}, produces = "application/json")
- public EcompRole testGetRoles(@PathVariable("appId") Long appId,
- @PathVariable("orgUserId") String orgUserId) throws Exception {
- if (!EcompPortalUtils.legitimateUserId(orgUserId)) {
- String msg = "Error /user/<user>/roles not legitimate orgUserId = " + orgUserId;
- logger.error(EELFLoggerDelegate.errorLogger, msg);
- throw new Exception(msg);
+
+ @RequestMapping(value = {"/portalApi/app/{appId}/users"}, method = {
+ RequestMethod.GET}, produces = "application/json")
+ public List<UserApplicationRoles> getUsersFromAppEndpoint(@PathVariable("appId") Long appId) {
+ try {
+ logger.debug(EELFLoggerDelegate.debugLogger, "/portalApi/app/{}/users was invoked", appId);
+ return fnUserRoleService.getUsersFromAppEndpoint(appId);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getUsersFromAppEndpoint failed", e);
+ return new ArrayList<>();
+ }
}
- EcompRole[] roles = applicationsRestClientService.get(EcompRole[].class, appId,
- String.format("/user/%s/roles", orgUserId));
- if (roles.length != 1) {
- String msg =
- "Error /user/<user>/roles returned array. expected size 1 recieved size = " + roles.length;
- logger.error(EELFLoggerDelegate.errorLogger, msg);
- throw new Exception(msg);
+
+ @RequestMapping(value = {"/portalApi/app/{appId}/roles"}, method = {
+ RequestMethod.GET}, produces = "application/json")
+ public List<EcompRole> testGetRoles(HttpServletRequest request, @PathVariable("appId") Long appId)
+ throws HTTPException {
+ EcompRole[] appRoles = applicationsRestClientService.get(EcompRole[].class, appId, "/roles");
+ List<EcompRole> rolesList = Arrays.asList(appRoles);
+ EcompPortalUtils
+ .logAndSerializeObject(logger, "/portalApi/app/{appId}/roles", "response for appId=" + appId,
+ rolesList);
+
+ return rolesList;
}
- EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/app/{appId}/user/{orgUserId}/roles",
- "response for appId='" + appId + "' and orgUserId='" + orgUserId + "'", roles[0]);
- return roles[0];
- }
+ @RequestMapping(value = {"/portalApi/admin/import/app/{appId}/roles"}, method = {
+ RequestMethod.GET}, produces = "application/json")
+ public List<FnRole> importRolesFromRemoteApplication(@PathVariable("appId") Long appId) throws HTTPException {
+ List<FnRole> rolesList = fnUserRoleService.importRolesFromRemoteApplication(appId);
+ EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/admin/import/app/{appId}/roles",
+ "response for appId=" + appId, rolesList);
- @RequestMapping(value = {"/portalApi/saveUserAppRoles"}, method = {
- RequestMethod.PUT}, produces = "application/json")
- public FieldsValidator putAppWithUserRoleRequest(Principal principal,
- @RequestBody AppWithRolesForUser newAppRolesForUser, HttpServletResponse response) {
- FieldsValidator fieldsValidator = null;
- FnUser user = fnUserService.loadUserByUsername(principal.getName());
- try {
- fieldsValidator = fnUserRoleService.putUserAppRolesRequest(newAppRolesForUser, user);
- response.setStatus(0);
+ return rolesList;
+ }
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "putAppWithUserRoleRequest failed", e);
+ @RequestMapping(value = {"/portalApi/app/{appId}/user/{orgUserId}/roles"}, method = {
+ RequestMethod.GET}, produces = "application/json")
+ public EcompRole testGetRoles(@PathVariable("appId") Long appId,
+ @PathVariable("orgUserId") String orgUserId) throws Exception {
+ if (!EcompPortalUtils.legitimateUserId(orgUserId)) {
+ String msg = "Error /user/<user>/roles not legitimate orgUserId = " + orgUserId;
+ logger.error(EELFLoggerDelegate.errorLogger, msg);
+ throw new Exception(msg);
+ }
+ EcompRole[] roles = applicationsRestClientService.get(EcompRole[].class, appId,
+ String.format("/user/%s/roles", orgUserId));
+ if (roles.length != 1) {
+ String msg =
+ "Error /user/<user>/roles returned array. expected size 1 recieved size = " + roles.length;
+ logger.error(EELFLoggerDelegate.errorLogger, msg);
+ throw new Exception(msg);
+ }
+
+ EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/app/{appId}/user/{orgUserId}/roles",
+ "response for appId='" + appId + "' and orgUserId='" + orgUserId + "'", roles[0]);
+ return roles[0];
}
- // return fieldsValidator;
- EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/saveUserAppRoles", "PUT result =",
- response.getStatus());
- return fieldsValidator;
- }
-
-
- @SuppressWarnings("ConstantConditions")
- @RequestMapping(value = {"/portalApi/appCatalogRoles"}, method = {
- RequestMethod.GET}, produces = "application/json")
- public List<EPUserAppCatalogRoles> getUserAppCatalogRoles(Principal principal,
- @RequestParam("appName") String appName) {
- FnUser user = fnUserService.loadUserByUsername(principal.getName());
- List<EPUserAppCatalogRoles> userAppRoleList = null;
- try {
- userAppRoleList = fnUserRoleService.getUserAppCatalogRoles(user, appName);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "putUserWidgetsSortPref failed", e);
+
+ @RequestMapping(value = {"/portalApi/saveUserAppRoles"}, method = {
+ RequestMethod.PUT}, produces = "application/json")
+ public FieldsValidator putAppWithUserRoleRequest(Principal principal,
+ @RequestBody AppWithRolesForUser newAppRolesForUser, HttpServletResponse response) {
+ FieldsValidator fieldsValidator = null;
+ FnUser user = fnUserService.loadUserByUsername(principal.getName());
+ try {
+ fieldsValidator = fnUserRoleService.putUserAppRolesRequest(newAppRolesForUser, user);
+ response.setStatus(0);
+
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "putAppWithUserRoleRequest failed", e);
+
+ }
+ // return fieldsValidator;
+ EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/saveUserAppRoles", "PUT result =",
+ response.getStatus());
+ return fieldsValidator;
}
- userAppRoleList.sort(getUserAppCatalogRolesComparator);
- EcompPortalUtils
- .logAndSerializeObject(logger, "/portalApi/userApplicationRoles", "result =", userAppRoleList);
-
- return userAppRoleList;
-
- }
-
-
- private final Comparator<EPUserAppCatalogRoles> getUserAppCatalogRolesComparator =
- Comparator.comparing(EPUserAppCatalogRoles::getRoleName);
-
- @RequestMapping(value = "/portalApi/externalRequestAccessSystem", method = RequestMethod.GET,
- produces = "application/json")
- public ExternalSystemAccess readExternalRequestAccess() {
- ExternalSystemAccess result = null;
- try {
- result = fnUserRoleService.getExternalRequestAccess();
- EcompPortalUtils
- .logAndSerializeObject(logger, "/portalApi/externalRequestAccessSystem", "GET result =",
- result);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,
- "readExternalRequestAccess failed: " + e.getMessage());
+
+
+ @SuppressWarnings("ConstantConditions")
+ @RequestMapping(value = {"/portalApi/appCatalogRoles"}, method = {
+ RequestMethod.GET}, produces = "application/json")
+ public List<EPUserAppCatalogRoles> getUserAppCatalogRoles(Principal principal,
+ @RequestParam("appName") String appName) {
+ FnUser user = fnUserService.loadUserByUsername(principal.getName());
+ List<EPUserAppCatalogRoles> userAppRoleList = null;
+ try {
+ userAppRoleList = fnUserRoleService.getUserAppCatalogRoles(user, appName);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "putUserWidgetsSortPref failed", e);
+
+ }
+ userAppRoleList.sort(getUserAppCatalogRolesComparator);
+ EcompPortalUtils
+ .logAndSerializeObject(logger, "/portalApi/userApplicationRoles", "result =", userAppRoleList);
+
+ return userAppRoleList;
+
}
- return result;
- }
- @RequestMapping(value = {"/portalApi/checkIfUserIsSuperAdmin"}, method = RequestMethod.GET,
- produces = "application/json")
- public boolean checkIfUserIsSuperAdmin(Principal principal) {
- FnUser user = fnUserService.loadUserByUsername(principal.getName());
+ private final Comparator<EPUserAppCatalogRoles> getUserAppCatalogRolesComparator =
+ Comparator.comparing(EPUserAppCatalogRoles::getRoleName);
+
+ @RequestMapping(value = "/portalApi/externalRequestAccessSystem", method = RequestMethod.GET,
+ produces = "application/json")
+ public ExternalSystemAccess readExternalRequestAccess() {
+ ExternalSystemAccess result = null;
+ try {
+ result = fnUserRoleService.getExternalRequestAccess();
+ EcompPortalUtils
+ .logAndSerializeObject(logger, "/portalApi/externalRequestAccessSystem", "GET result =",
+ result);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "readExternalRequestAccess failed: " + e.getMessage());
+ }
+ return result;
+
+ }
+
+ @RequestMapping(value = {"/portalApi/checkIfUserIsSuperAdmin"}, method = RequestMethod.GET,
+ produces = "application/json")
+ public boolean checkIfUserIsSuperAdmin(Principal principal) {
+ FnUser user = fnUserService.loadUserByUsername(principal.getName());
- boolean isSuperAdmin = false;
- try {
- isSuperAdmin = adminRolesService.isSuperAdmin(user.getLoginId());
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "checkIfUserIsSuperAdmin failed: " + e.getMessage());
+ boolean isSuperAdmin = false;
+ try {
+ isSuperAdmin = adminRolesService.isSuperAdmin(user.getLoginId());
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "checkIfUserIsSuperAdmin failed: " + e.getMessage());
+ }
+ return isSuperAdmin;
}
- return isSuperAdmin;
- }
}
diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java
index b8307b90..375838e2 100644
--- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java
+++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java
@@ -162,7 +162,10 @@ CREATE TABLE `fn_user` (
query = "FROM FnUser WHERE activeYn = 'Y'"),
@NamedQuery(
name = "FnUser.getUsersByOrgIds",
- query = "FROM FnUser WHERE orgUserId IN :orgIds"
+ query = "FROM FnUser WHERE orgUserId IN :orgIds"),
+ @NamedQuery(
+ name = "FnUSer.findByFirstNameAndLastName",
+ query = "FROM FnUser WHERE firstName = :firstName AND lastName = :lastName"
)
})
diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUserRole.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUserRole.java
index e2913e05..581b7ab4 100644
--- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUserRole.java
+++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUserRole.java
@@ -186,7 +186,7 @@ public class FnUserRole implements Serializable {
@Digits(integer = 4, fraction = 0)
private Long priority;
@ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
- @JoinColumn(name = "fn_App_Id", columnDefinition = "bigint")
+ @JoinColumn(name = "fn_app_id", columnDefinition = "bigint")
@Valid
private FnApp fnAppId;
-} \ No newline at end of file
+}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java b/portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java
index a103f44e..f8ef4a99 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/AdminRolesService.java
@@ -78,6 +78,7 @@ import org.onap.portal.domain.db.fn.FnRole;
import org.onap.portal.domain.db.fn.FnRoleFunction;
import org.onap.portal.domain.db.fn.FnUser;
import org.onap.portal.domain.db.fn.FnUserRole;
+import org.onap.portal.domain.dto.ecomp.EPUserApp;
import org.onap.portal.domain.dto.transport.AppNameIdIsAdmin;
import org.onap.portal.domain.dto.transport.AppWithRolesForUser;
import org.onap.portal.domain.dto.transport.AppsListWithAdminRole;
@@ -1932,4 +1933,47 @@ public class AdminRolesService {
return finalRoleFunctionSet;
}
+
+ public AppsListWithAdminRole getAppsWithAdminRoleStateForUser(String orgUserId) {
+ AppsListWithAdminRole appsListWithAdminRole = null;
+
+ try {
+ List<FnUser> userList = fnUserService.getUserWithOrgUserId(orgUserId);
+ HashMap<Long, Long> appsUserAdmin = new HashMap<>();
+ if (userList!= null && userList.size() > 0) {
+ FnUser user = userList.get(0);
+ List<FnUserRole> userAppList = new ArrayList<>();
+ try {
+ userAppList = fnUserRoleService.retrieveByUserIdAndRoleId(user.getId(), ACCOUNT_ADMIN_ROLE_ID);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getAppsWithAdminRoleStateForUser 1 failed", e);
+ EPLogUtil.logEcompError(EPAppMessagesEnum.BeDaoSystemError);
+ }
+ for (FnUserRole userApp : userAppList) {
+ appsUserAdmin.put(userApp.getFnAppId().getId(), userApp.getUserId().getId());
+ }
+ }
+
+ appsListWithAdminRole = new AppsListWithAdminRole();
+ appsListWithAdminRole.setOrgUserId(orgUserId);
+ List<FnApp> appsList = new ArrayList<>();
+ try {
+ appsList = fnAppService.findAll();
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getAppsWithAdminRoleStateForUser 2 failed", e);
+ EPLogUtil.logEcompError(EPAppMessagesEnum.BeDaoSystemError);
+ }
+ for (FnApp app : appsList) {
+ AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin();
+ appNameIdIsAdmin.setId(app.getId());
+ appNameIdIsAdmin.setAppName(app.getAppName());
+ appNameIdIsAdmin.setIsAdmin(appsUserAdmin.containsKey(app.getId()));
+ appNameIdIsAdmin.setRestrictedApp(app.isRestrictedApp());
+ appsListWithAdminRole.getAppsRoles().add(appNameIdIsAdmin);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getAppsWithAdminRoleStateForUser 3 failed", e);
+ }
+ return appsListWithAdminRole;
+ }
}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/SearchService.java b/portal-BE/src/main/java/org/onap/portal/service/SearchService.java
new file mode 100644
index 00000000..0829239d
--- /dev/null
+++ b/portal-BE/src/main/java/org/onap/portal/service/SearchService.java
@@ -0,0 +1,179 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
+ *
+ * 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============================================
+ *
+ *
+ */
+
+package org.onap.portal.service;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.onap.portal.domain.db.fn.FnUser;
+import org.onap.portal.domain.dto.transport.UserWithNameSurnameTitle;
+import org.onap.portal.service.user.FnUserService;
+import org.onap.portal.utils.EcompPortalUtils;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional
+public class SearchService {
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SearchService.class);
+
+ private static final int maxSizeOfSearchResult = 100;
+
+ private final FnUserService userService;
+
+ @Autowired
+ public SearchService(FnUserService userService) {
+ this.userService = userService;
+ }
+
+ public String searchUsersInPhoneBook(final String searchString) {
+ List<String> tokens = EcompPortalUtils.parsingByRegularExpression(searchString, " ");
+ while (tokens.size() > 2) { // we use no more then first 2 tokens (userId is removed, see above)
+ tokens.remove(tokens.size() - 1);
+ }
+ FnUser attrUser = new FnUser();
+ List<UserWithNameSurnameTitle> resultOfSearch = new ArrayList<UserWithNameSurnameTitle>(), resultOfAdditionalSearch = null,
+ resultOfSearchUserId = new ArrayList<UserWithNameSurnameTitle>();
+ if (tokens.size() == 2) {
+ attrUser.setFirstName(tokens.get(0));
+ attrUser.setLastName(tokens.get(1));
+ resultOfSearch = this.searchUsersByName(attrUser);
+ resultOfSearch = this.removeWrongFirstNames(resultOfSearch, tokens.get(0));
+ resultOfSearch = this.removeWrongLastNames(resultOfSearch, tokens.get(1));
+ if (resultOfSearch.size() < maxSizeOfSearchResult) {
+ attrUser.setFirstName(tokens.get(1));
+ attrUser.setLastName(tokens.get(0));
+ resultOfAdditionalSearch = this.searchUsersByName(attrUser);
+ resultOfAdditionalSearch = this.removeWrongFirstNames(resultOfAdditionalSearch, tokens.get(1));
+ resultOfAdditionalSearch = this.removeWrongLastNames(resultOfAdditionalSearch, tokens.get(0));
+ }
+ } else if (tokens.size() == 1) {
+ attrUser.setFirstName(tokens.get(0));
+ attrUser.setOrgUserId(tokens.get(0));
+ resultOfSearch = this.searchUsersByName(attrUser);
+ resultOfSearchUserId = this.searchUsersByUserId(attrUser);
+ resultOfSearch = this.removeWrongFirstNames(resultOfSearch, tokens.get(0));
+ if (resultOfSearch.size() < maxSizeOfSearchResult) {
+ attrUser.setFirstName(null);
+ attrUser.setLastName(tokens.get(0));
+ resultOfAdditionalSearch = this.searchUsersByName(attrUser);
+ resultOfAdditionalSearch = this.removeWrongLastNames(resultOfAdditionalSearch, tokens.get(0));
+ }
+ }
+ if (resultOfAdditionalSearch != null) {
+ resultOfSearch.addAll(resultOfAdditionalSearch);
+ }
+ resultOfSearch.addAll(resultOfSearchUserId);
+ resultOfSearch.stream().distinct().collect(Collectors.toList());
+ resultOfSearch = this.cutSearchResultToMaximumSize(resultOfSearch);
+ ObjectMapper mapper = new ObjectMapper();
+ String result = "[]";
+ try {
+ result = mapper.writeValueAsString(resultOfSearch);
+ } catch (JsonProcessingException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "searchUsersInFnTable failed", e);
+ }
+ return result;
+ }
+
+ public List<UserWithNameSurnameTitle> searchUsersByUserId(FnUser attrUser) {
+ List<UserWithNameSurnameTitle> foundUsers = new ArrayList<UserWithNameSurnameTitle>();
+ try {
+ List<FnUser> searchResult = this.userService.getUserByUserId(attrUser.getOrgUserId());
+ for (FnUser user : searchResult) {
+ UserWithNameSurnameTitle foundUser = new UserWithNameSurnameTitle(user.getOrgUserId(), user.getFirstName(), user.getLastName(), user.getJobTitle());
+ foundUsers.add(foundUser);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "searchUsersByUserId failed", e);
+ }
+ return foundUsers;
+ }
+
+ public List<UserWithNameSurnameTitle> searchUsersByName(FnUser attrUser) {
+ List<UserWithNameSurnameTitle> foundUsers = new ArrayList<UserWithNameSurnameTitle>();
+ try {
+ List<FnUser> searchResult = this.userService.getUserByFirstLastName(attrUser.getFirstName(),attrUser.getLastName());
+ for (Object obj : searchResult) {
+ FnUser user = (FnUser) obj;
+ UserWithNameSurnameTitle foundUser = new UserWithNameSurnameTitle(user.getOrgUserId(), user.getFirstName(), user.getLastName(), user.getJobTitle());
+ foundUsers.add(foundUser);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "searchUsersByName failed", e);
+ }
+ return foundUsers;
+ }
+
+ private List<UserWithNameSurnameTitle> removeWrongFirstNames(List<UserWithNameSurnameTitle> resultOfSearch, String firstName) {
+ firstName = firstName.toUpperCase();
+ for (int i = resultOfSearch.size() - 1; i >= 0; i--) {
+ UserWithNameSurnameTitle user = resultOfSearch.get(i);
+ if ((user.getFirstName() == null) || !user.getFirstName().toUpperCase().startsWith(firstName)) {
+ resultOfSearch.remove(i);
+ }
+ }
+ return resultOfSearch;
+ }
+
+ private List<UserWithNameSurnameTitle> removeWrongLastNames(List<UserWithNameSurnameTitle> resultOfSearch, String lastName) {
+ lastName = lastName.toUpperCase();
+ for (int i = resultOfSearch.size() - 1; i >= 0; i--) {
+ UserWithNameSurnameTitle user = resultOfSearch.get(i);
+ if ((user.getLastName() == null) || !user.getLastName().toUpperCase().startsWith(lastName)) {
+ resultOfSearch.remove(i);
+ }
+ }
+ return resultOfSearch;
+ }
+
+ private List<UserWithNameSurnameTitle> cutSearchResultToMaximumSize(List<UserWithNameSurnameTitle> resultOfSearch) {
+ if (resultOfSearch.size() > maxSizeOfSearchResult) {
+ resultOfSearch.subList(maxSizeOfSearchResult, resultOfSearch.size()).clear();
+ }
+ return resultOfSearch;
+ }
+}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java b/portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java
index 13d0911a..1a7c2fa5 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/app/FnAppService.java
@@ -138,4 +138,8 @@ public class FnAppService {
public List<FnApp> saveAll(List<FnApp> fnApps) {
return fnAppDao.saveAll(fnApps);
}
+
+ public List<FnApp> findAll() {
+ return Optional.of(fnAppDao.findAll()).orElse(new ArrayList<>());
+ }
}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/user/FnUserDao.java b/portal-BE/src/main/java/org/onap/portal/service/user/FnUserDao.java
index f7a150d3..197b2b28 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/user/FnUserDao.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/user/FnUserDao.java
@@ -68,4 +68,7 @@ interface FnUserDao extends JpaRepository<FnUser, Long> {
@Query
Optional<List<FnUser>> getActiveUsers();
+ @Query
+ Optional<List<FnUser>> findByFirstNameAndLastName(final @Param("firstName") String firstName, final @Param("lastName") String lastName);
+
}
diff --git a/portal-BE/src/main/java/org/onap/portal/service/user/FnUserService.java b/portal-BE/src/main/java/org/onap/portal/service/user/FnUserService.java
index 23732d69..7962755f 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/user/FnUserService.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/user/FnUserService.java
@@ -40,12 +40,27 @@
package org.onap.portal.service.user;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
+import org.json.JSONArray;
+import org.json.JSONObject;
import org.onap.portal.domain.db.fn.FnUser;
+import org.onap.portal.utils.EPCommonSystemProperties;
+import org.onap.portal.utils.EPSystemProperties;
+import org.onap.portalsdk.core.domain.FusionObject.Utilities;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.util.SystemProperties;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.repository.query.Param;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@@ -55,66 +70,199 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
public class FnUserService implements UserDetailsService {
- private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnUserService.class);
+ private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnUserService.class);
- private final FnUserDao fnUserDao;
+ private final FnUserDao fnUserDao;
- @Autowired
- public FnUserService(FnUserDao fnUserDao) {
- this.fnUserDao = fnUserDao;
- }
+ @Autowired
+ public FnUserService(FnUserDao fnUserDao) {
+ this.fnUserDao = fnUserDao;
+ }
- @Override
- public FnUser loadUserByUsername(final String username) throws UsernameNotFoundException {
- Optional<FnUser> fnUser = fnUserDao.findByLoginId(username);
- if (fnUser.isPresent()) {
- return fnUser.get();
- } else {
- throw new UsernameNotFoundException("User not found for username: " + username);
- }
- }
+ @Override
+ public FnUser loadUserByUsername(final String username) throws UsernameNotFoundException {
+ Optional<FnUser> fnUser = fnUserDao.findByLoginId(username);
+ if (fnUser.isPresent()) {
+ return fnUser.get();
+ } else {
+ throw new UsernameNotFoundException("User not found for username: " + username);
+ }
+ }
- public FnUser saveFnUser(final FnUser fnUser) {
- return fnUserDao.save(fnUser);
- }
+ public FnUser saveFnUser(final FnUser fnUser) {
+ return fnUserDao.save(fnUser);
+ }
- public Optional<FnUser> getUser(final Long id) {
- return Optional.of(fnUserDao.getOne(id));
- }
+ public Optional<FnUser> getUser(final Long id) {
+ return Optional.of(fnUserDao.getOne(id));
+ }
- public List<FnUser> getUserWithOrgUserId(final String orgUserIdValue) {
- return fnUserDao.getUserWithOrgUserId(orgUserIdValue).orElse(new ArrayList<>());
- }
+ public List<FnUser> getUserWithOrgUserId(final String orgUserIdValue) {
+ return fnUserDao.getUserWithOrgUserId(orgUserIdValue).orElse(new ArrayList<>());
+ }
- public List<FnUser> getUsersByOrgIds(final List<String> orgIds) {
- return fnUserDao.getUsersByOrgIds(orgIds).orElse(new ArrayList<>());
- }
+ public List<FnUser> getUsersByOrgIds(final List<String> orgIds) {
+ return fnUserDao.getUsersByOrgIds(orgIds).orElse(new ArrayList<>());
+ }
- public List<FnUser> getActiveUsers() {
- return fnUserDao.getActiveUsers().orElse(new ArrayList<>());
- }
+ public List<FnUser> getActiveUsers() {
+ return fnUserDao.getActiveUsers().orElse(new ArrayList<>());
+ }
- public void deleteUser(final FnUser fnUser) {
- fnUserDao.delete(fnUser);
- }
+ public void deleteUser(final FnUser fnUser) {
+ fnUserDao.delete(fnUser);
+ }
- public boolean existById(final Long userId) {
- return fnUserDao.existsById(userId);
- }
+ public boolean existById(final Long userId) {
+ return fnUserDao.existsById(userId);
+ }
- public List<FnUser> findAll() {
- return fnUserDao.findAll();
- }
+ public List<FnUser> findAll() {
+ return fnUserDao.findAll();
+ }
- public List<FnUser> saveAll(final List<FnUser> fnUsers) {
- return fnUserDao.saveAll(fnUsers);
- }
+ public List<FnUser> saveAll(final List<FnUser> fnUsers) {
+ return fnUserDao.saveAll(fnUsers);
+ }
- public FnUser save(final FnUser user) {
- return fnUserDao.save(user);
- }
+ public FnUser save(final FnUser user) {
+ return fnUserDao.save(user);
+ }
- public void delete(final FnUser user) {
- fnUserDao.delete(user);
- }
+ public void delete(final FnUser user) {
+ fnUserDao.delete(user);
+ }
+
+ public List<FnUser> findByFirstNameAndLastName(final String firstName, final String lastName) {
+ return fnUserDao.findByFirstNameAndLastName(firstName, lastName).orElse(new ArrayList<>());
+ }
+
+ public List<FnUser> getUserByUserId(String userId) {
+ if (SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC")) {
+ List<FnUser> users = new ArrayList<>();
+ List<FnUser> filterdUsers = new ArrayList<>();
+ BufferedReader in = null;
+ HttpURLConnection con = null;
+ try {
+ String url = EPSystemProperties.getProperty(EPSystemProperties.AUTH_USER_SERVER);
+ URL obj = new URL(url);
+
+ con = (HttpURLConnection) obj.openConnection();
+
+ // optional default is GET
+ con.setRequestMethod("GET");
+ con.setConnectTimeout(3000);
+ con.setReadTimeout(8000);
+
+ StringBuffer response = new StringBuffer();
+
+ in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ response.append(inputLine);
+ }
+ JSONObject jObject = new JSONObject(response.toString()); // json
+ JSONArray jsonUsers = jObject.getJSONArray("response"); // get data object
+ for (int i = 0; i < jsonUsers.length(); i++) {
+ JSONObject eachObject = jsonUsers.getJSONObject(i);
+ FnUser eachUser = new FnUser();
+ eachUser.setOrgUserId(eachObject.get("id").toString());// getString("id"));
+ eachUser.setFirstName(eachObject.get("givenName").toString());
+ eachUser.setLastName(eachObject.get("familyName").toString());
+ eachUser.setEmail(eachObject.get("email").toString());
+ users.add(eachUser);
+ }
+
+ for (FnUser user : users) {
+
+ if (Utilities.nvl(userId).length() > 0) {
+ if (!userId.equalsIgnoreCase(user.getOrgUserId())) {
+ continue;
+ }
+ }
+ filterdUsers.add(user);
+
+ }
+
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getUserByUserId failed", e);
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ con.disconnect();
+ } catch (IOException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getUserByUserId 2 failed", e);
+ }
+ }
+ return filterdUsers;
+ } else {
+ List<FnUser> list = this.getUserWithOrgUserId(userId);
+ return (list == null || list.size() == 0) ? null : list;
+ }
+
+ }
+
+ public List<FnUser> getUserByFirstLastName(String firstName, String lastName) {
+ if (!SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC")) {
+ List<FnUser> list = this.findByFirstNameAndLastName(firstName, lastName);
+ return (list == null || list.size() == 0) ? null : list;
+ } else {
+ List<FnUser> users = new ArrayList<>();
+ List<FnUser> filterdUsers = new ArrayList<>();
+ BufferedReader in = null;
+ HttpURLConnection con = null;
+ try {
+ String url = EPCommonSystemProperties.getProperty(EPCommonSystemProperties.AUTH_USER_SERVER);
+ URL obj = new URL(url);
+ con = (HttpURLConnection) obj.openConnection();
+ con.setRequestMethod("GET");
+ con.setConnectTimeout(3000);
+ con.setReadTimeout(8000);
+ StringBuffer response = new StringBuffer();
+ in = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ response.append(inputLine);
+ }
+ JSONObject jObject = new JSONObject(response.toString());
+ JSONArray jsonUsers = jObject.getJSONArray("response");
+ for (int i = 0; i < jsonUsers.length(); i++) {
+ JSONObject eachObject = jsonUsers.getJSONObject(i);
+ FnUser eachUser = new FnUser();
+ eachUser.setOrgUserId(eachObject.get("id").toString());
+ eachUser.setFirstName(eachObject.get("givenName").toString());
+ eachUser.setLastName(eachObject.get("familyName").toString());
+ eachUser.setEmail(eachObject.get("email").toString());
+ users.add(eachUser);
+ }
+ for (FnUser user : users) {
+ if (Utilities.nvl(firstName).length() > 0) {
+ if (!firstName.equalsIgnoreCase(user.getFirstName())) {
+ continue;
+ }
+ }
+ if (Utilities.nvl(lastName).length() > 0) {
+ if (!lastName.equalsIgnoreCase(user.getLastName())) {
+ continue;
+ }
+ }
+ filterdUsers.add(user);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getUserByFirstLastName failed", e);
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ con.disconnect();
+ }
+ } catch (IOException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getUserByFirstLastName failed to close", e);
+ }
+ }
+ return filterdUsers;
+ }
+ }
}
diff --git a/portal-BE/src/main/java/org/onap/portal/utils/EPSystemProperties.java b/portal-BE/src/main/java/org/onap/portal/utils/EPSystemProperties.java
new file mode 100644
index 00000000..9db97ce7
--- /dev/null
+++ b/portal-BE/src/main/java/org/onap/portal/utils/EPSystemProperties.java
@@ -0,0 +1,61 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
+ *
+ * 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============================================
+ *
+ *
+ */
+
+package org.onap.portal.utils;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.PropertySources;
+
+@Configuration
+@PropertySources({
+ @PropertySource("classpath:/WEB-INF/conf/system.properties"),
+ @PropertySource("classpath:/WEB-INF/conf/sql.properties"),
+ @PropertySource("classpath:/WEB-INF/fusion/conf/fusion.properties"),
+ //@PropertySource(value = "file:${catalina.home}/conf/system.properties", ignoreResourceNotFound = true),
+ //@PropertySource(value = "file:${catalina.home}/conf/fusion.properties", ignoreResourceNotFound = true)
+})
+
+public class EPSystemProperties extends EPCommonSystemProperties {
+
+ public static final String CONTACT_US_URL = "contact_us_link";
+ public static final String ECOMP_CONTEXT_ROOT = "context_root";
+
+}