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=3d2432cbcc225d0b8527e2ab6e9b42300df388b6;hb=a94388ed941c82a38b2e631cc4fd77bac212335b;hp=bbb83827a93c9f92d0c71c50e2f65c00b848f15b;hpb=325e4dac24bcbeaf357d9950dee4f01a5b3059e0;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 bbb83827..3d2432cb 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 @@ -50,6 +50,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.servlet.http.HttpServletResponse; @@ -60,6 +61,8 @@ import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Restrictions; +import org.json.JSONArray; +import org.json.JSONObject; import org.onap.portalapp.portal.domain.AdminUserApp; import org.onap.portalapp.portal.domain.AdminUserApplications; import org.onap.portalapp.portal.domain.AppIdAndNameTransportModel; @@ -72,6 +75,7 @@ import org.onap.portalapp.portal.domain.EPUserAppsManualSortPreference; import org.onap.portalapp.portal.domain.EPUserAppsSortPreference; import org.onap.portalapp.portal.domain.EPWidgetsManualSortPreference; import org.onap.portalapp.portal.domain.EcompApp; +import org.onap.portalapp.portal.domain.MicroserviceData; import org.onap.portalapp.portal.domain.UserRole; import org.onap.portalapp.portal.domain.UserRoles; import org.onap.portalapp.portal.ecomp.model.AppCatalogItem; @@ -91,11 +95,20 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.ueb.Helper; import org.onap.portalsdk.core.onboarding.ueb.TopicManager; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; import com.att.nsa.apiClient.http.HttpException; import com.att.nsa.cambria.client.CambriaClient.CambriaApiException; @@ -110,7 +123,9 @@ public class EPAppCommonServiceImpl implements EPAppService { protected String ACCOUNT_ADMIN_ROLE_ID = "999"; protected String RESTRICTED_APP_ROLE_ID = "900"; - private static final String urlField = "url"; + //private static final String urlField = "url"; + private static final String nameSpaceField = "url"; + private static final String nameField = "name"; private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAppCommonServiceImpl.class); @@ -121,6 +136,8 @@ public class EPAppCommonServiceImpl implements EPAppService { protected SessionFactory sessionFactory; @Autowired private DataAccessService dataAccessService; + + RestTemplate template = new RestTemplate(); @PostConstruct private void init() { @@ -129,6 +146,65 @@ public class EPAppCommonServiceImpl implements EPAppService { ECOMP_APP_ID = SystemProperties.getProperty(EPCommonSystemProperties.ECOMP_APP_ID); RESTRICTED_APP_ROLE_ID = SystemProperties.getProperty(EPCommonSystemProperties.RESTRICTED_APP_ROLE_ID); } + + public Boolean onboardingAppFieldsValidation(OnboardingApp onboardingApp) { + //FieldsValidator fieldsValidator = new FieldsValidator(); + + if ((!onboardingApp.getRestrictedApp()) &&( onboardingApp.getAppName() == null || onboardingApp.getAppName().length() == 0 || onboardingApp.getRestrictedApp() == null + || onboardingApp.getLandingPage() == null || onboardingApp.getLandingPage().length() == 0 || onboardingApp.getRestUrl() == null || onboardingApp.getRestUrl().length() == 0 + || onboardingApp.getAppBasicAuthUsername() == null || onboardingApp.getAppBasicAuthUsername().length() == 0 + || onboardingApp.getIsOpen() == null + || (onboardingApp.getId() != null && onboardingApp.getId().equals(ECOMP_APP_ID))) + // For a normal app (appType == PortalConstants.PortalAppId), + // these fields must be filled + // in. + // For a restricted app (appType==2), they will be empty. + || ((onboardingApp.getRestrictedApp()) && (onboardingApp.getAppName() == null || onboardingApp.getAppName().length() == 0 + || onboardingApp.getLandingPage() == null || onboardingApp.getLandingPage().length() == 0 || onboardingApp.getIsOpen() == null))) { + return false; + } + return true; + + } + + private Boolean onboardingInactiveAppFieldsForValidation(OnboardingApp onboardingApp) { + if (onboardingApp.getAppName() == null || onboardingApp.getAppName().length() == 0 + || onboardingApp.getIsOpen() == null) { + return false; + } + return true; + } + + protected FieldsValidator onboardingAppFieldsChecker(OnboardingApp onboardingApp) { + FieldsValidator fieldsValidator = new FieldsValidator(); + if (onboardingApp.getRolesInAAF()) { + if (!onboardingApp.getIsEnabled()) { + if (!onboardingInactiveAppFieldsForValidation(onboardingApp)) { + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); + } + } else if (onboardingApp.getIsEnabled()) { + if (onboardingAppFieldsValidation(onboardingApp) == false || onboardingApp.getNameSpace() == null + || onboardingApp.getNameSpace().length() == 0) { + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); + } + } + } else { + if (!onboardingApp.getIsEnabled()) { + if (!onboardingInactiveAppFieldsForValidation(onboardingApp)) { + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); + } + } else if (onboardingApp.getIsEnabled()) { + if(onboardingApp.getRestrictedApp() && onboardingAppFieldsValidation(onboardingApp) == false){ + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); + } + else if (!onboardingApp.getRestrictedApp() && (onboardingAppFieldsValidation(onboardingApp) == false || onboardingApp.getAppBasicAuthPassword() == null + || onboardingApp.getAppBasicAuthPassword().length() == 0)) { + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); + } + } + } + return fieldsValidator; + } @Override public List getUserAsAdminApps(EPUser user) { @@ -195,15 +271,15 @@ public class EPAppCommonServiceImpl implements EPAppService { ecompApp.setId(app.getId()); ecompApp.setName(app.getName()); ecompApp.setImageUrl(app.getImageUrl()); - ecompApp.setDescription(app.getDescription()); - ecompApp.setNotes(app.getNotes()); - ecompApp.setUrl(app.getUrl()); - ecompApp.setAlternateUrl(app.getAlternateUrl()); + ecompApp.setDescription(app.getAppDescription()); + ecompApp.setNotes(app.getAppNotes()); + ecompApp.setUrl(app.getLandingPage()); + ecompApp.setAlternateUrl(app.getAlternateLandingPage()); ecompApp.setUebTopicName(app.getUebTopicName()); //ecompApp.setUebKey(app.getUebKey()); ecompApp.setUebSecret(app.getUebSecret()); ecompApp.setEnabled(app.getEnabled()); - ecompApp.setCentralAuth(app.getCentralAuth()); + ecompApp.setCentralAuth(app.getRolesInAAF()); ecompApp.setNameSpace(app.getNameSpace()); ecompApp.setRestrictedApp(app.isRestrictedApp()); ecompAppList.add(ecompApp); @@ -308,7 +384,7 @@ public class EPAppCommonServiceImpl implements EPAppService { if (apps.size() > 0) { EPApp app = apps.get(0); if (!EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) { - app.setCentralAuth(false); + app.setRolesInAAF(false); } return app; } else{ @@ -406,6 +482,23 @@ public class EPAppCommonServiceImpl implements EPAppService { return appsModified; } + + @Override + public List getAllApplications(Boolean all) { + // If all is true, return both active and inactive apps. Otherwise, just + // active apps. + @SuppressWarnings("unchecked") + // Sort the list by application name so the drop-down looks pretty. + List apps = all + ? (List) dataAccessService.getList(EPApp.class, " where id != " + ECOMP_APP_ID, "name", null) + :dataAccessService.getList(EPApp.class, null); + + List appsModified = new ArrayList(); + for (EPApp app : apps) { + appsModified.add(new AppsResponse(app.getId(), app.getName(), app.isRestrictedApp(), app.getEnabled())); + } + return appsModified; + } @Override public UserRoles getUserProfile(String loginId) { final Map params = new HashMap<>(); @@ -488,18 +581,18 @@ public class EPAppCommonServiceImpl implements EPAppService { return query.toString(); } - protected FieldsValidator onboardingAppFieldsChecker(OnboardingApp onboardingApp) { + /*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 && ECOMP_APP_ID.equals(onboardingApp.id.toString())) + || onboardingApp.url.length() == 0 || onboardingApp.getRestrictedApp() == null + || onboardingApp.getIsOpen() == null || onboardingApp.getIsEnabled() == null + || (onboardingApp.getId() != null && ECOMP_APP_ID.equals(onboardingApp.getId().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.getRestrictedApp()) && (onboardingApp.myLoginsAppName == null || onboardingApp.myLoginsAppName.length() == 0 || onboardingApp.myLoginsAppOwner == null || onboardingApp.myLoginsAppOwner.length() == 0 || onboardingApp.username == null || onboardingApp.username.length() == 0 ))) { @@ -508,14 +601,14 @@ public class EPAppCommonServiceImpl implements EPAppService { }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())) + || onboardingApp.url.length() == 0 || onboardingApp.getRestrictedApp() == null + || onboardingApp.getIsOpen() == null || onboardingApp.getIsEnabled() == null + || (onboardingApp.getId() != null && ECOMP_APP_ID.equals(onboardingApp.getId().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.getRestrictedApp()) && (onboardingApp.myLoginsAppName == null || onboardingApp.myLoginsAppName.length() == 0 || onboardingApp.myLoginsAppOwner == null || onboardingApp.myLoginsAppOwner.length() == 0 || onboardingApp.username == null || onboardingApp.username.length() == 0 || onboardingApp.appPassword == null @@ -526,7 +619,7 @@ public class EPAppCommonServiceImpl implements EPAppService { } return fieldsValidator; - } + }*/ @Override public List getUserApps(EPUser user) { @@ -725,7 +818,7 @@ public class EPAppCommonServiceImpl implements EPAppService { } return finalsortedAppsByManual; } - + @Override public List getOnboardingApps() { @SuppressWarnings("unchecked") @@ -733,22 +826,43 @@ public class EPAppCommonServiceImpl implements EPAppService { List onboardingAppsList = new ArrayList(); for (EPApp app : apps) { OnboardingApp onboardingApp = new OnboardingApp(); - app.setAppPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD);//to hide password from get request + app.setAppBasicAuthPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD);//to hide password from get request createOnboardingFromApp(app, onboardingApp); onboardingAppsList.add(onboardingApp); } return onboardingAppsList; } + + @SuppressWarnings("unchecked") + @Override + public List getAdminAppsOfUser(EPUser user) { + + List onboardingAppsList = new ArrayList(); + List userAdminApps = new ArrayList<>(); + final Map userParams = new HashMap<>(); + userParams.put("userId", user.getId()); + userAdminApps = dataAccessService.executeNamedQuery("getAllAdminAppsofTheUser", userParams, null); + +// userAdminApps.removeIf(x -> x == Integer.valueOf(ECOMP_APP_ID)); + + logger.debug(EELFLoggerDelegate.debugLogger, "Is account admin for userAdminApps() - for user {}, found userAdminAppsSize {}", user.getOrgUserId(), userAdminApps.size()); + onboardingAppsList = getOnboardingApps(); + + final List userAdminApps1 = userAdminApps; + List userApplicationAdmins = onboardingAppsList.stream().filter(x -> userAdminApps1.contains((int) (long)x.getId())).collect(Collectors.toList()); + + return userApplicationAdmins; + } @Override public List getEnabledNonOpenOnboardingApps() { @SuppressWarnings("unchecked") List apps = dataAccessService.getList(EPApp.class, - " where enabled = true and open = false and id!=" + ECOMP_APP_ID, null, null); + " where enabled = true and open = false and app_type!= 3 and id!=" + ECOMP_APP_ID, null, null); + List onboardingAppsList = new ArrayList(); for (EPApp app : apps) { OnboardingApp onboardingApp = new OnboardingApp(); - app.setAppPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD); //to hide password from get request createOnboardingFromApp(app, onboardingApp); onboardingAppsList.add(onboardingApp); } @@ -757,50 +871,59 @@ public class EPAppCommonServiceImpl implements EPAppService { @SuppressWarnings("unchecked") private void validateOnboardingApp(OnboardingApp onboardingApp, FieldsValidator fieldsValidator) { - boolean duplicatedUrl = false; + boolean duplicatedNameSpace = false; boolean duplicatedName = false; List apps; - if (onboardingApp.id == null) { + if (onboardingApp.getId() == null) { List restrictionsList = new ArrayList(); - Criterion urlCrit =Restrictions.eq("url", onboardingApp.url); - Criterion nameCrit = Restrictions.eq("name",onboardingApp.name); - Criterion orCrit = Restrictions.or(urlCrit, nameCrit); - + Criterion nameCrit = Restrictions.eq("name",onboardingApp.getAppName()); + Criterion nameSpaceCrit = null; + Criterion orCrit = null; + if (onboardingApp.getRolesInAAF()) { + nameSpaceCrit = Restrictions.eq("nameSpace", onboardingApp.getNameSpace()); + orCrit = Restrictions.or(nameCrit, nameSpaceCrit); + } else + orCrit = Restrictions.or(nameCrit); restrictionsList.add(orCrit); apps = (List) dataAccessService.getList(EPApp.class, null, restrictionsList, null); - - } else { List restrictionsList = new ArrayList(); - Criterion idCrit =Restrictions.eq("id", onboardingApp.id); - Criterion urlCrit =Restrictions.eq("url", onboardingApp.url); - Criterion nameCrit = Restrictions.eq("name",onboardingApp.name); - Criterion orCrit = Restrictions.or(idCrit, urlCrit, nameCrit); + Criterion idCrit =Restrictions.eq("id", onboardingApp.getId()); + Criterion nameCrit = Restrictions.eq("name",onboardingApp.getAppName()); + Criterion nameSpaceCrit = null; + Criterion orCrit= null; + if (onboardingApp.getRolesInAAF()) { + nameSpaceCrit = Restrictions.eq("nameSpace",onboardingApp.getNameSpace()); + orCrit = Restrictions.or(idCrit, nameSpaceCrit, nameCrit); + } + else + orCrit = Restrictions.or(idCrit, nameCrit); restrictionsList.add(orCrit); apps = (List) dataAccessService.getList(EPApp.class, null, restrictionsList, null); } for (EPApp app : apps) { - if (onboardingApp.id != null && onboardingApp.id.equals(app.getId())) { + if (onboardingApp.getId() != null && onboardingApp.getId().equals(app.getId())) { continue; } - if (!duplicatedUrl && app.getUrl().equalsIgnoreCase(onboardingApp.url)) { - duplicatedUrl = true; + if (!duplicatedName && app.getName().equalsIgnoreCase(onboardingApp.getAppName())) { + duplicatedName = true; if (duplicatedName) { break; } } - if (!duplicatedName && app.getName().equalsIgnoreCase(onboardingApp.name)) { - duplicatedName = true; - if (duplicatedUrl) { + if (!duplicatedNameSpace && app.getNameSpace().equalsIgnoreCase(onboardingApp.getNameSpace())) { + duplicatedNameSpace = true; + if (duplicatedNameSpace) { break; } } + } - if (duplicatedUrl || duplicatedName) { - if (duplicatedUrl) { - fieldsValidator.addProblematicFieldName(urlField); + if (duplicatedNameSpace || duplicatedName) { + if (duplicatedNameSpace) { + fieldsValidator.addProblematicFieldName(nameSpaceField); } if (duplicatedName) { fieldsValidator.addProblematicFieldName(nameField); @@ -818,8 +941,8 @@ public class EPAppCommonServiceImpl implements EPAppService { validateOnboardingApp(modifiedOnboardingApp, fieldsValidator); } if (fieldsValidator.httpStatusCode.intValue() == HttpServletResponse.SC_OK) { - if (modifiedOnboardingApp.id != null) { - updateApp(modifiedOnboardingApp.id, modifiedOnboardingApp, fieldsValidator, user); + if (modifiedOnboardingApp.getId() != null) { + updateApp(modifiedOnboardingApp.getId(), modifiedOnboardingApp, fieldsValidator, user); } else { fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); } @@ -834,7 +957,7 @@ public class EPAppCommonServiceImpl implements EPAppService { validateOnboardingApp(newOnboardingApp, fieldsValidator); } if (fieldsValidator.httpStatusCode.intValue() == HttpServletResponse.SC_OK) { - if (newOnboardingApp.id == null) { + if (newOnboardingApp.getId() == null) { updateApp(null, newOnboardingApp, fieldsValidator, user); } else { fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST); @@ -853,6 +976,16 @@ public class EPAppCommonServiceImpl implements EPAppService { } final Map params = new HashMap<>(); params.put("app_id", appid); + + //Checking if App is associated with any exiting microservices- ep_microservice: + final Map queryparams = new HashMap<>(); + queryparams.put("applicationId", appid); + List microservicesList = dataAccessService.executeNamedQuery( "getMicroservicesByAppId", queryparams, null); + if(microservicesList!=null && microservicesList.size()>0) { + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_METHOD_NOT_ALLOWED); + return fieldsValidator; + } + List EPUserAppRolesRequestList= new ArrayList<>(); EPUserAppRolesRequestList = dataAccessService.executeNamedQuery( "getRequestIdsForApp", params, null); for(int i=0;i 1) { @@ -1473,7 +1619,7 @@ public class EPAppCommonServiceImpl implements EPAppService { app.setImageUrl(constructImageName(onboardingApp)); app.setThumbnail(decodedImage); } - } else if (app.getThumbnail() != null && onboardingApp.imageLink == null) { + } else if (app.getThumbnail() != null && onboardingApp.getImageLink() == null) { // The thumbnail that came in from the json is empty; the previous // thumbnail is NOT empty. Must delete it. logger.debug(EELFLoggerDelegate.debugLogger, @@ -1488,7 +1634,11 @@ public class EPAppCommonServiceImpl implements EPAppService { } protected String constructImageName(OnboardingApp onboardingApp) { - return "portal_" + String.valueOf(onboardingApp.url.hashCode() + "_" + (int) (Math.random() * 100000.0)) + String appLandingPageURL = onboardingApp.getLandingPage(); + if(appLandingPageURL == null) { + appLandingPageURL = ""; + } + return "portal_" + String.valueOf(appLandingPageURL.hashCode() + "_" + (int) (Math.random() * 100000.0)) + ".png"; } @@ -1498,7 +1648,7 @@ public class EPAppCommonServiceImpl implements EPAppService { if (encryptedAppPwd != null && !encryptedAppPwd.isEmpty()) { try { result = CipherUtil.decryptPKC(encryptedAppPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed for app " + app.getName(), e); } @@ -1511,7 +1661,7 @@ public class EPAppCommonServiceImpl implements EPAppService { if (decryptedAppPwd != null && !decryptedAppPwd.isEmpty()) { try { result = CipherUtil.encryptPKC(decryptedAppPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "encryptedPassword failed for app " + app.getName(), e); } @@ -1801,4 +1951,60 @@ public class EPAppCommonServiceImpl implements EPAppService { return userAndRoles; } + + @SuppressWarnings("unused") + @Override + public ResponseEntity checkIfNameSpaceIsValid(String namespace) throws Exception { + HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth(); + HttpEntity entity = new HttpEntity<>(headers); + logger.debug(EELFLoggerDelegate.debugLogger, "checkIfNameSpaceExists: Connecting to External Auth system for : "+namespace); + ResponseEntity response = null; + try { + + String namespaceUrl = SystemProperties. + getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "nss/" + namespace; + + response = template.exchange(namespaceUrl, HttpMethod.GET, entity, String.class); + logger.debug(EELFLoggerDelegate.debugLogger, "checkIfNameSpaceExists for"+ namespace , + response.getStatusCode().value()); + if (response.getStatusCode().value() == 200) { + String res = response.getBody(); + JSONObject jsonObj = new JSONObject(res); + JSONArray namespaceArray = jsonObj.getJSONArray("ns"); + if(!namespaceArray.getJSONObject(0).has("admin")){ + logger.error(EELFLoggerDelegate.errorLogger, + "No admins are available for requested namespace:" + namespace); + throw new HttpClientErrorException(HttpStatus.UNAUTHORIZED, + "Portal Mechid is not an admin of" + namespace); + } + + JSONArray namespaceAdminArray = namespaceArray.getJSONObject(0).getJSONArray("admin"); + ArrayList list = new ArrayList(); + if (namespaceAdminArray != null) { + int len = namespaceAdminArray.length(); + for (int i = 0; i < len; i++) { + list.add(namespaceAdminArray.get(i).toString()); + } + } + logger.debug(EELFLoggerDelegate.debugLogger, "List of Admins of requested namespace" + list); + final String userName = SystemProperties + .getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_AUTH_USER_NAME); + boolean idExists = list.stream().anyMatch(t -> userName.equals(t)); + if (false) { + logger.error(EELFLoggerDelegate.errorLogger, + "Portal mechid is not admin of requested namespace:" + namespace); + throw new HttpClientErrorException(HttpStatus.UNAUTHORIZED, + "Portal Mechid is not an admin of" + namespace); + } + } + + } catch (HttpClientErrorException e) { + logger.error(EELFLoggerDelegate.errorLogger, "checkIfNameSpaceExists failed", e); + EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode()); + throw e; + } + return response; + + } } +