X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Fservice%2FEPAppCommonServiceImpl.java;h=bbb83827a93c9f92d0c71c50e2f65c00b848f15b;hb=8b67487fa29e61ad15ac961231ebb3b6621d39dc;hp=24572fb2fc13a906ebdab215a1464f1b154b7734;hpb=2edaa4d6a5f7066e0c718f85a7bf7b8dabd0c59b;p=portal.git diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java index 24572fb2..bbb83827 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java @@ -4,6 +4,8 @@ * =================================================================== * Copyright (C) 2017 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"); @@ -143,12 +145,15 @@ public class EPAppCommonServiceImpl implements EPAppService { EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e); return null; } + } else { logger.error(EELFLoggerDelegate.errorLogger, "getUserAsAdminApps: only Account Admin may invoke this function!"); return new ArrayList(); } } + + @Override public List getUserByOrgUserIdAsAdminApps(String orgUserId) { @@ -195,7 +200,7 @@ public class EPAppCommonServiceImpl implements EPAppService { ecompApp.setUrl(app.getUrl()); ecompApp.setAlternateUrl(app.getAlternateUrl()); ecompApp.setUebTopicName(app.getUebTopicName()); - ecompApp.setUebKey(app.getUebKey()); + //ecompApp.setUebKey(app.getUebKey()); ecompApp.setUebSecret(app.getUebSecret()); ecompApp.setEnabled(app.getEnabled()); ecompApp.setCentralAuth(app.getCentralAuth()); @@ -216,25 +221,66 @@ public class EPAppCommonServiceImpl implements EPAppService { } } + + @SuppressWarnings("unchecked") @Override public List getAdminApps(EPUser user) { - if (adminRolesService.isAccountAdmin(user)) { - String format = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app inner join FN_USER_ROLE userrole ON userrole.APP_ID=app.APP_ID " - + "where userrole.USER_ID = %d AND userrole.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID - + " AND (app.ENABLED = 'Y' OR app.APP_ID=1)"; - String sql = String.format(format, user.getId()); - // sql += " AND app.APP_REST_ENDPOINT IS NOT NULL AND - // app.APP_REST_ENDPOINT <> ''"; - logQuery(sql); + + if (adminRolesService.isAccountAdmin(user) && adminRolesService.isRoleAdmin(user)) { + final Map params = new HashMap<>(); + params.put("userId", user.getId()); + List applicationRoleswithAccountandRoleadmin = dataAccessService + .executeNamedQuery("getApplicationsofTheUserwithAdminAndRoleAdmin", params, null); try { - return dataAccessService.executeSQLQuery(sql, AppIdAndNameTransportModel.class, null); + return applicationRoleswithAccountandRoleadmin; } catch (Exception e) { EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e); logger.error(EELFLoggerDelegate.errorLogger, - "Exception occurred while fetching the adminApps for user " + user.getLoginId(), e); + "Exception occurred while fetching the list of user who has type account and role approver " + + user.getLoginId(), + e); } } + + else { + if (adminRolesService.isAccountAdmin(user)) { + String format = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app inner join FN_USER_ROLE userrole ON userrole.APP_ID=app.APP_ID " + + "where userrole.USER_ID = %d AND userrole.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID + + " AND (app.ENABLED = 'Y' OR app.APP_ID=1)"; + String sql = String.format(format, user.getId()); + logQuery(sql); + try { + return dataAccessService.executeSQLQuery(sql, AppIdAndNameTransportModel.class, null); + } catch (Exception e) { + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e); + logger.error(EELFLoggerDelegate.errorLogger, + "Exception occurred while fetching the adminApps for user " + user.getLoginId(), e); + } + + } + + if (adminRolesService.isRoleAdmin(user)) { + final Map params = new HashMap<>(); + params.put("userId", user.getId()); + List applicationRoles = dataAccessService.executeNamedQuery("getApplicationsofTheUserContainsApprover", + params, null); + + try { + return applicationRoles; + } catch (Exception e) { + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e); + logger.error(EELFLoggerDelegate.errorLogger, + "Exception occurred while fetching the list of user who has type approver " + + user.getLoginId(), + e); + } + + } + } + // sql += " AND app.APP_REST_ENDPOINT IS NOT NULL AND + // app.APP_REST_ENDPOINT <> ''"; + return new ArrayList(); } @@ -444,17 +490,40 @@ public class EPAppCommonServiceImpl implements EPAppService { protected FieldsValidator onboardingAppFieldsChecker(OnboardingApp onboardingApp) { FieldsValidator fieldsValidator = new FieldsValidator(); + if(onboardingApp.isCentralAuth){ if (onboardingApp.name == null || onboardingApp.name.length() == 0 || onboardingApp.url == null || onboardingApp.url.length() == 0 || onboardingApp.restrictedApp == null || onboardingApp.isOpen == null || onboardingApp.isEnabled == null - || (onboardingApp.id != null && onboardingApp.id.equals(ECOMP_APP_ID)) - // For a normal app (appType==1), these fields must be filled + || (onboardingApp.id != null && ECOMP_APP_ID.equals(onboardingApp.id.toString())) + // For a normal app (appType == PortalConstants.PortalAppId), + // these fields must be filled // in. // For a restricted app (appType==2), they will be empty. - || ((!onboardingApp.restrictedApp) - && (onboardingApp.username == null || onboardingApp.username.length() == 0 - || onboardingApp.appPassword == null || onboardingApp.appPassword.length() == 0))) { + || ((!onboardingApp.restrictedApp) && (onboardingApp.myLoginsAppName == null + || onboardingApp.myLoginsAppName.length() == 0 || onboardingApp.myLoginsAppOwner == null + || onboardingApp.myLoginsAppOwner.length() == 0 || onboardingApp.username == null + || onboardingApp.username.length() == 0 ))) { fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); + } + }else{ + + if (onboardingApp.name == null || onboardingApp.name.length() == 0 || onboardingApp.url == null + || onboardingApp.url.length() == 0 || onboardingApp.restrictedApp == null + || onboardingApp.isOpen == null || onboardingApp.isEnabled == null + || (onboardingApp.id != null && ECOMP_APP_ID.equals(onboardingApp.id.toString())) + // For a normal app (appType == PortalConstants.PortalAppId), + // these fields must be filled + // in. + // For a restricted app (appType==2), they will be empty. + || ((!onboardingApp.restrictedApp) && (onboardingApp.myLoginsAppName == null + || onboardingApp.myLoginsAppName.length() == 0 || onboardingApp.myLoginsAppOwner == null + || onboardingApp.myLoginsAppOwner.length() == 0 || onboardingApp.username == null + || onboardingApp.username.length() == 0 || onboardingApp.appPassword == null + || onboardingApp.appPassword.length() == 0))) { + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); + } + + } return fieldsValidator; } @@ -1426,7 +1495,7 @@ public class EPAppCommonServiceImpl implements EPAppService { // Don't encrypt or decrypt the password if it is null or the empty string private String decryptedPassword(String encryptedAppPwd, EPApp app) { String result = ""; - if (encryptedAppPwd != null & encryptedAppPwd.length() > 0) { + if (encryptedAppPwd != null && !encryptedAppPwd.isEmpty()) { try { result = CipherUtil.decryptPKC(encryptedAppPwd, SystemProperties.getProperty(SystemProperties.Decryption_Key)); @@ -1439,7 +1508,7 @@ public class EPAppCommonServiceImpl implements EPAppService { protected String encryptedPassword(String decryptedAppPwd, EPApp app) { String result = ""; - if (decryptedAppPwd != null & decryptedAppPwd.length() > 0) { + if (decryptedAppPwd != null && !decryptedAppPwd.isEmpty()) { try { result = CipherUtil.encryptPKC(decryptedAppPwd, SystemProperties.getProperty(SystemProperties.Decryption_Key)); @@ -1732,4 +1801,4 @@ public class EPAppCommonServiceImpl implements EPAppService { return userAndRoles; } -} \ No newline at end of file +}