From 39a2ffd9ccd28539ec00e7fc16c7c9c051b1809a Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Tue, 1 Aug 2017 14:04:04 -0400 Subject: [PATCH] Repair ONAP portal release problems - Remove duplicate & buggy code blocking widget authentication - Set UEB URL list property to ueb.api.simpledemo.openecomp.org - Refactor to generate app key without using UEB - Abbreviate WMS connection string to drop "&timeout=2000" Issue: PORTAL-30, PORTAL-37, PORTAL-48 Change-Id: I5ff5844aba05781e2c5a2d833403e821e355811c Signed-off-by: Christopher Lott (cl778h) --- deliveries/etc.zip | Bin 11469 -> 11448 bytes .../portal/service/EPAppCommonServiceImpl.java | 343 +++++++++++---------- .../service/MicroserviceProxyServiceImpl.java | 145 +++++---- ecomp-portal-BE-os/README.md | 4 +- .../portalapp/portal/service/EPAppServiceImpl.java | 78 +++++ 5 files changed, 325 insertions(+), 245 deletions(-) diff --git a/deliveries/etc.zip b/deliveries/etc.zip index 7d590d5ac85bfbf6faf48b2393c9694f4026645e..dc530f515c446723c4ce50b1a6e59b45c2e45e6b 100644 GIT binary patch delta 1479 zcmZ8hdpOg39R7_Nn%hd)NMV?57+Z8yt_jU8LMt7XLoUfZLR(m;lalOLJWk|VPRGf? zVlkI++-D+k5KF4b>~T9%p>wu+&Uv2BAD_?re4qF8c|L!9-}fD$Jf_^lN#RCwjGe_D z6sc?GFs-G8?3!U;h!|K{DKjYvo`S}G!C@Ey3iS+!kUQNC`09&kI!920IR zEk=-|^avptyD~A<#DV~TmNWpM!89c`FjrZPF4+@`D zCLvC(XZ)`cXHD6;w)59*qr>IT`&%~4sn+FEywUwm#r1QodFB3lD_#$S#p5$P-a>e= z)=oyads2lAHT?v9w_ScNCTn~CJZb1^@EszxZ_m+M-w~33ecIqrE3ckT8G3$1i^D1x z`L-nB{@-h3uxv-pzf}RN!}F)R4-2!AxDEGukcbP$goZ7Pk*8ZGn+j zDDq8bQhu&A|1&y+>ofh+(#q?CmO}Rc*T6Ezv(?_FO)?d1OV*w7_&U7x?ckb=1vaji z!yC|sV~%ZG?;#_I7xFqW#dKF=Dre$gdlT2`!iG)xgT)~0{O-o>FB)wv>g`=35UbH$ zv!3NA{LXA5s+HFTgIv|cNSa?OD1vk~I)*&$)X4J?eVU{;x9~PrXsnN)R>Ro)e;Myt zz^K>FSCSXPN_z>zXg)sEG$V8=?|!Cn4Q+HnKUas5*>Bkx(B|dhCfrYYih8pbea`a=N3{IwHy!pfmA?ZTgI$WF`idPPua5%}$i8TZ*KI|sj+Dwkc= zc-h!k?4?trF6qvUTek7YbVQ(TsInN4} zK0gZ!1k*Z`y$<4fTCBz=_OajubFq4nNI2Iv%=}woo$?z%AnbRj;K6gs`^x4 z|8x$QmJLo1t#!(@UX&Zl;M5<8N^DKh&eJN~z1hIfH^b+{Us(s_miE59=;5RJ-DID$ z>bnFgrWCV1xP~uENRb^+;dllcXC5LSbn=9E0 z6=!3Zg?E-63|o(wBoAh|RNkH{x_ho*aq&m)HDqD~%!-5J*`zbli5z}o0KMd*Vq9n;%p&_pgS%^dVLoFqO{TABu-aih`(`KkX29% skCGPKLULmFx1In144@%SM*tA#Bv77a1IFVCQW~S+eY_4#!9YU%1Mf?sEC2ui delta 1531 zcmZXUYdq6?9LN8=ShR+8E=$OuVa9%z7{9do$=lksadDjF81K1S!GjEVhXFJ;tmXglo1eQ08*6IK?51bQi2e)=$HVk_mP0O1T+LgPRv)3cnE@co?B1# zn5)){{jw{?)(+uebxSj<0(nKNwm#iQZeI~|ac{)=K0*9-=xyWb1Fn4p4fpK@h2o@y z?5ct_*@U)Tk;@F1jS`sET)QQqR~x7av?m(U_?hD~m!~6O%DX zQYf)7qp`$`qHSB6_O-tzlk!9-{JTg7HFp>VojBu34REW0&Ec z_T65RhMH$O#FooftVO03U6+mDqsxxR?0wa|(zZ1+n^)3W{+zT!(3kH0{oEmh8!za2 zQTln5rsBYx#Hmt+1V(YFBLso*<_jB1*v;Rj3v!~zS7kdz8@10G>Rhv5*Upa4O}5D|o#Qsn%| z+s!}olkW9$-&=Flq%J=_eO|mzi_$pCIa%?nujm0sy|#CqkD=D_03)kO`^;`Rdb=G1W`{Kgl!wmL+{71P%k158P0w`7}2*Y^w!`-sYg3JJ7a@M6lvE( zcKhkWSc4Afeg#UHQ`p=%VV*d-JSJMpCEbOJlxtk*WVz!5ZC3qzZ1vS z>aO}cQ+VH>Lv}k7L6(8qor2-wobY=)MutES|7^kSotx?x>rq4SsjAM+f845hI`%EW z)$rSJy#0-2$$s>nDDdI^V7kIe7q!((OKh^#i_KG)wCC6^!nNl|Y8SZ~E@8IqBge5G zNM$1q<)_xIwvR$;3D~5Y9Ok)J^B&@t?v({U`e(8h85Z_A(BO`oNw~~7F@ALsnW6Q@h*rSG-Us?ukU#W2LE}i|RJ#}wNzi}F% za8=fAof97~<%hIth{SV!Q~a5po|6-^B6a}v*8&Q+=hOY+<<5H6t7mw16XM`Zt(i7@ z*{!n3-~v@=M@D0XPL|~1jwH;TFDm>chR*OGe)KoCLd^RSbn0n@|>F{c3mHBAHX)no%K3D{8fz-9rL;w+ztghGUWBY{v;{30K3 p1^EEv-Uh0a#kxPwL~~xH5Hv4Us5oUa2r)H>FVyu>`iAn4e*i!?sLucZ diff --git a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/EPAppCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/EPAppCommonServiceImpl.java index 4ef6e891..f38b921a 100644 --- a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/EPAppCommonServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/EPAppCommonServiceImpl.java @@ -96,7 +96,7 @@ public class EPAppCommonServiceImpl implements EPAppService { @Autowired private AdminRolesService adminRolesService; @Autowired - private SessionFactory sessionFactory; + protected SessionFactory sessionFactory; @Autowired private DataAccessService dataAccessService; @Autowired @@ -839,7 +839,7 @@ public class EPAppCommonServiceImpl implements EPAppService { // An app has been enabled/disabled. Must enable/disable all associated // functional menu items. - private void setFunctionalMenuItemsEnabled(Session localSession, Boolean enabled, Long appId) { + protected void setFunctionalMenuItemsEnabled(Session localSession, Boolean enabled, Long appId) { String active_yn = enabled ? "Y" : "N"; String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn " + "FROM fn_menu_functional m, fn_menu_functional_roles r " + "WHERE m.menu_id = r.menu_id " @@ -857,7 +857,7 @@ public class EPAppCommonServiceImpl implements EPAppService { // Attention! If (appId == null) we use this function to create application // otherwise we use it to modify existing application - private void updateApp(Long appId, OnboardingApp onboardingApp, FieldsValidator fieldsValidator, EPUser user) { + protected void updateApp(Long appId, OnboardingApp onboardingApp, FieldsValidator fieldsValidator, EPUser user) { logger.debug(EELFLoggerDelegate.debugLogger, "LR: entering updateApp"); // Separate out the code for a restricted app, since it doesn't need any // of the UEB code. @@ -898,190 +898,197 @@ public class EPAppCommonServiceImpl implements EPAppService { } } else { - synchronized (syncRests) { - boolean result = false; - Session localSession = null; - Transaction transaction = null; - try { - localSession = sessionFactory.openSession(); - transaction = localSession.beginTransaction(); - EPApp app; - if (appId == null) { - app = new EPApp(); - // ------------------------------------------------------------------------------------------- - // Register this App with the UEB communication server. - // Save - // the App's unique mailbox/topic - // name and keys to the FN_APP table. The App's mailbox - // and - // keys will be visible to the - // admin on the ECOMP portal. - // ------------------------------------------------------------------------------------------- - TopicManager topicManager = new TopicManager() { - - EPAppCommonServiceImpl service; - - public void init(EPAppCommonServiceImpl _service) { - service = _service; - } - - public void createTopic(String key, String secret, String topicName, - String topicDescription) throws HttpException, CambriaApiException, IOException { - - init(EPAppCommonServiceImpl.this); - final LinkedList urlList = Helper.uebUrlList(); - if (logger.isInfoEnabled()) { - logger.info("==> createTopic"); - logger.info("topicName: " + topicName); - logger.info("topicDescription: " + topicDescription); - } - CambriaTopicManager tm = null; - try { - tm = service.getTopicManager(urlList, key, secret); - } catch (Exception e) { - logger.error("pub.build Exception ", e); - throw new CambriaApiException(topicName); - } - tm.createTopic(topicName, topicDescription, 1, 1); - } - - public void addPublisher(String topicOwnerKey, String topicOwnerSecret, String publisherKey, - String topicName) throws HttpException, CambriaApiException, IOException { - logger.info("==> addPublisher to topic " + topicName); - final LinkedList urlList = Helper.uebUrlList(); - CambriaTopicManager tm = null; - try { - tm = service.getTopicManager(urlList, topicOwnerKey, topicOwnerSecret); - } catch (Exception e) { - logger.error("pub.build Exception ", e); - throw new CambriaApiException(topicName); - } - tm.allowProducer(topicName, publisherKey); - } + updateRestrictedApp(appId, onboardingApp, fieldsValidator, user); + + } + } - }; - final CambriaIdentityManager im = new CambriaClientBuilders.IdentityManagerBuilder() - .usingHosts(Helper.uebUrlList()).build(); - com.att.nsa.apiClient.credentials.ApiCredential credential = im.createApiKey(user.getEmail(), - "ECOMP Portal Owner"); - String appKey = credential.getApiKey(); - String appSecret = credential.getApiSecret(); - String appMailboxName = null; + protected void updateRestrictedApp(Long appId, OnboardingApp onboardingApp, FieldsValidator fieldsValidator, + EPUser user) { + synchronized (syncRests) { + boolean result = false; + Session localSession = null; + Transaction transaction = null; + try { + localSession = sessionFactory.openSession(); + transaction = localSession.beginTransaction(); + EPApp app; + if (appId == null) { + app = new EPApp(); + // ------------------------------------------------------------------------------------------- + // Register this App with the UEB communication server. + // Save + // the App's unique mailbox/topic + // name and keys to the FN_APP table. The App's mailbox + // and + // keys will be visible to the + // admin on the ECOMP portal. + // ------------------------------------------------------------------------------------------- + TopicManager topicManager = new TopicManager() { + + EPAppCommonServiceImpl service; + + public void init(EPAppCommonServiceImpl _service) { + service = _service; + } - int maxNumAttemptsToCreateATopic = 3; - boolean successfullyCreatedMailbox = false; - for (int i = 0; i < maxNumAttemptsToCreateATopic; i++) { - appMailboxName = "ECOMP-PORTAL-OUTBOX-" + (int) (Math.random() * 100000.0); + public void createTopic(String key, String secret, String topicName, + String topicDescription) throws HttpException, CambriaApiException, IOException { + init(EPAppCommonServiceImpl.this); + final LinkedList urlList = Helper.uebUrlList(); + if (logger.isInfoEnabled()) { + logger.info("==> createTopic"); + logger.info("topicName: " + topicName); + logger.info("topicDescription: " + topicDescription); + } + CambriaTopicManager tm = null; try { - topicManager.createTopic( - PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), - PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET), - appMailboxName, "ECOMP outbox for app" + onboardingApp.name); - successfullyCreatedMailbox = true; - logger.debug(EELFLoggerDelegate.debugLogger, - "Successfully created " + appMailboxName + " for App " + onboardingApp.name); - logger.debug(EELFLoggerDelegate.debugLogger, " Key = " + appKey + " Secret = " - + appSecret + " generated using = " + user.getEmail()); - break; - } catch (HttpException e) { - EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebConnectionError, e); - if (e.getStatusCode() == 409) { - logger.error(EELFLoggerDelegate.errorLogger, "Topic/mailbox " + appMailboxName - + " already exists. Will try using a different name", e); - } else { - logger.error(EELFLoggerDelegate.errorLogger, "HttpException when onboarding App: ", - e); - } + tm = service.getTopicManager(urlList, key, secret); + } catch (Exception e) { + logger.error("pub.build Exception ", e); + throw new CambriaApiException(topicName); } + tm.createTopic(topicName, topicDescription, 1, 1); } - if (successfullyCreatedMailbox) { - onboardingApp.setUebTopicName(appMailboxName); - onboardingApp.setUebKey(appKey); - onboardingApp.setUebSecret(appSecret); - + public void addPublisher(String topicOwnerKey, String topicOwnerSecret, String publisherKey, + String topicName) throws HttpException, CambriaApiException, IOException { + logger.info("==> addPublisher to topic " + topicName); + final LinkedList urlList = Helper.uebUrlList(); + CambriaTopicManager tm = null; try { - /* - * EP is a publisher to this App's new mailbox - */ - topicManager.addPublisher( - PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), - PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET), - PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), - appMailboxName); - - /* - * This App is a subscriber of its own mailbox - */ - topicManager.addSubscriber( - PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), - PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET), appKey, - appMailboxName); - - /* - * This App is a publisher to EP - */ - topicManager.addPublisher( - PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), - PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET), appKey, - PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME)); - } catch (HttpException | CambriaApiException | IOException e) { - EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebRegisterOnboardingAppError, e); - logger.error(EELFLoggerDelegate.errorLogger, - "Error when configuring Publisher/Subscriber for App's new mailbox", e); - transaction.commit(); - localSession.close(); - fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_CONFLICT); - return; + tm = service.getTopicManager(urlList, topicOwnerKey, topicOwnerSecret); + } catch (Exception e) { + logger.error("pub.build Exception ", e); + throw new CambriaApiException(topicName); + } + tm.allowProducer(topicName, publisherKey); + } + + }; + final CambriaIdentityManager im = new CambriaClientBuilders.IdentityManagerBuilder() + .usingHosts(Helper.uebUrlList()).build(); + com.att.nsa.apiClient.credentials.ApiCredential credential = im.createApiKey(user.getEmail(), + "ECOMP Portal Owner"); + String appKey = credential.getApiKey(); + String appSecret = credential.getApiSecret(); + String appMailboxName = null; + + int maxNumAttemptsToCreateATopic = 3; + boolean successfullyCreatedMailbox = false; + for (int i = 0; i < maxNumAttemptsToCreateATopic; i++) { + appMailboxName = "ECOMP-PORTAL-OUTBOX-" + (int) (Math.random() * 100000.0); + + try { + topicManager.createTopic( + PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), + PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET), + appMailboxName, "ECOMP outbox for app" + onboardingApp.name); + successfullyCreatedMailbox = true; + logger.debug(EELFLoggerDelegate.debugLogger, + "Successfully created " + appMailboxName + " for App " + onboardingApp.name); + logger.debug(EELFLoggerDelegate.debugLogger, " Key = " + appKey + " Secret = " + + appSecret + " generated using = " + user.getEmail()); + break; + } catch (HttpException e) { + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebConnectionError, e); + if (e.getStatusCode() == 409) { + logger.error(EELFLoggerDelegate.errorLogger, "Topic/mailbox " + appMailboxName + + " already exists. Will try using a different name", e); + } else { + logger.error(EELFLoggerDelegate.errorLogger, "HttpException when onboarding App: ", + e); } - } else { + } + } + + if (successfullyCreatedMailbox) { + onboardingApp.setUebTopicName(appMailboxName); + onboardingApp.setUebKey(appKey); + onboardingApp.setUebSecret(appSecret); + + try { + /* + * EP is a publisher to this App's new mailbox + */ + topicManager.addPublisher( + PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), + PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET), + PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), + appMailboxName); + + /* + * This App is a subscriber of its own mailbox + */ + topicManager.addSubscriber( + PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), + PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET), appKey, + appMailboxName); + + /* + * This App is a publisher to EP + */ + topicManager.addPublisher( + PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY), + PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET), appKey, + PortalApiProperties.getProperty(PortalApiConstants.ECOMP_PORTAL_INBOX_NAME)); + } catch (HttpException | CambriaApiException | IOException e) { + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebRegisterOnboardingAppError, e); + logger.error(EELFLoggerDelegate.errorLogger, + "Error when configuring Publisher/Subscriber for App's new mailbox", e); transaction.commit(); localSession.close(); fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_CONFLICT); return; } } else { - app = (EPApp) localSession.get(EPApp.class, appId); - if (app == null || app.getId() == null) { - // App is already deleted! - transaction.commit(); - localSession.close(); - fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_NOT_FOUND); - return; - } + transaction.commit(); + localSession.close(); + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_CONFLICT); + return; + } + } else { + app = (EPApp) localSession.get(EPApp.class, appId); + if (app == null || app.getId() == null) { + // App is already deleted! + transaction.commit(); + localSession.close(); + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_NOT_FOUND); + return; } - logger.debug(EELFLoggerDelegate.debugLogger, "LR: about to call createAppFromOnboarding"); - createAppFromOnboarding(app, onboardingApp, localSession); - logger.debug(EELFLoggerDelegate.debugLogger, - "LR: updateApp: finished calling createAppFromOnboarding"); - localSession.saveOrUpdate(app); - logger.debug(EELFLoggerDelegate.debugLogger, - "LR: updateApp: finished calling localSession.saveOrUpdate"); - // Enable or disable all menu items associated with this app - setFunctionalMenuItemsEnabled(localSession, onboardingApp.isEnabled, appId); - logger.debug(EELFLoggerDelegate.debugLogger, - "LR: updateApp: finished calling setFunctionalMenuItemsEnabled"); - transaction.commit(); - logger.debug(EELFLoggerDelegate.debugLogger, "LR: updateApp: finished calling transaction.commit"); - epUebHelper.addPublisher(app); - logger.debug(EELFLoggerDelegate.debugLogger, - "LR: updateApp: finished calling epUebHelper.addPublisher"); - result = true; - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, "updateApp failed", e); - EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebRegisterOnboardingAppError, e); - EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e); - EcompPortalUtils.rollbackTransaction(transaction, - "updateApp rollback, exception = " + EcompPortalUtils.getStackTrace(e)); - } finally { - EcompPortalUtils.closeLocalSession(localSession, "updateApp"); - } - if (!result) { - fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } + logger.debug(EELFLoggerDelegate.debugLogger, "LR: about to call createAppFromOnboarding"); + createAppFromOnboarding(app, onboardingApp, localSession); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: updateApp: finished calling createAppFromOnboarding"); + localSession.saveOrUpdate(app); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: updateApp: finished calling localSession.saveOrUpdate"); + // Enable or disable all menu items associated with this app + setFunctionalMenuItemsEnabled(localSession, onboardingApp.isEnabled, appId); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: updateApp: finished calling setFunctionalMenuItemsEnabled"); + transaction.commit(); + logger.debug(EELFLoggerDelegate.debugLogger, "LR: updateApp: finished calling transaction.commit"); + epUebHelper.addPublisher(app); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: updateApp: finished calling epUebHelper.addPublisher"); + result = true; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "updateApp failed", e); + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebRegisterOnboardingAppError, e); + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e); + EcompPortalUtils.rollbackTransaction(transaction, + "updateApp rollback, exception = " + EcompPortalUtils.getStackTrace(e)); + } finally { + EcompPortalUtils.closeLocalSession(localSession, "updateApp"); + } + if (!result) { + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } + } public CambriaTopicManager getTopicManager(LinkedList urlList, String key, String secret) diff --git a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/MicroserviceProxyServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/MicroserviceProxyServiceImpl.java index ff8ee424..f5a542bf 100644 --- a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/MicroserviceProxyServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/MicroserviceProxyServiceImpl.java @@ -22,7 +22,6 @@ package org.openecomp.portalapp.portal.service; import java.util.List; import javax.servlet.http.HttpServletRequest; - import org.apache.commons.codec.binary.Base64; import org.openecomp.portalapp.portal.domain.EPUser; import org.openecomp.portalapp.portal.domain.MicroserviceData; @@ -73,65 +72,18 @@ public class MicroserviceProxyServiceImpl implements MicroserviceProxyService { @Override public String proxyToDestination(long serviceId, EPUser user, HttpServletRequest request) throws Exception { - String response = null; - - // get the microservice object by the id + //get the microservice object by the id MicroserviceData data = microserviceService.getMicroserviceDataById(serviceId); // No such microservice available if (data == null) { - return response; - } - List params = data.getParameterList(); - MicroserviceParameter userId_param = new MicroserviceParameter(); - userId_param.setPara_key("userId"); - userId_param.setPara_value(user.getOrgUserId()); - params.add(userId_param); - - if (data.getSecurityType().equals(NO_AUTH)) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity(headers); - - String url = microserviceUrlConverter(data, params); - logger.debug(EELFLoggerDelegate.debugLogger, "Before making no authentication call: {}", url); - response = template.exchange(url, HttpMethod.GET, entity, String.class).getBody(); - logger.debug(EELFLoggerDelegate.debugLogger, "No authentication call response: {}", response); - - } else if (data.getSecurityType().equals(BASIC_AUTH)) { - // encoding the username and password - String plainCreds = data.getUsername() + ":" + decryptedPassword(data.getPassword()); - byte[] plainCredsBytes = plainCreds.getBytes(); - byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); - String base64Creds = new String(base64CredsBytes); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Basic " + base64Creds); - headers.setContentType(MediaType.APPLICATION_JSON); - String rawCookie = request.getHeader("Cookie"); - headers.add("Cookie", rawCookie); - HttpEntity entity = new HttpEntity(headers); - - String url = microserviceUrlConverter(data, params); - logger.debug(EELFLoggerDelegate.debugLogger, "Before making basic authentication call: {}", url); - response = template.exchange(url, HttpMethod.GET, entity, String.class).getBody(); - logger.debug(EELFLoggerDelegate.debugLogger, "Basic authentication call response: {}", response); - - } else if (data.getSecurityType().equals(COOKIE_AUTH)) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - String rawCookie = request.getHeader("Cookie"); - headers.add("Cookie", rawCookie); - HttpEntity entity = new HttpEntity(headers); - - String url = microserviceUrlConverter(data, params); - logger.debug(EELFLoggerDelegate.debugLogger, "Before making cookie-based authentication call: {}", url); - response = template.exchange(url, HttpMethod.GET, entity, String.class).getBody(); - logger.debug(EELFLoggerDelegate.debugLogger, "Cookie-based authentication call response: {}", response); + //can we return a better response than null? + return null; } - return response; + + return authenticateAndRespond(data, request, composeParams(data, user)); } - + @Override public String proxyToDestinationByWidgetId(long widgetId, EPUser user, HttpServletRequest request) throws Exception { @@ -155,55 +107,58 @@ public class MicroserviceProxyServiceImpl implements MicroserviceProxyService { return response; } - List params = data.getParameterList(); - MicroserviceParameter userId_param = new MicroserviceParameter(); - userId_param.setPara_key("userId"); - userId_param.setPara_value(user.getOrgUserId()); - params.add(userId_param); - + List params = composeParams(data, user); for (MicroserviceParameter p : params) { WidgetCatalogParameter userValue = widgetParameterService.getUserParamById(widgetId, user.getId(), p.getId()); if (userValue != null) p.setPara_value(userValue.getUser_value()); } + + return authenticateAndRespond(data, request, params); + + } + private String authenticateAndRespond(MicroserviceData data, HttpServletRequest request, List params){ + + String response = null; + if (data.getSecurityType().equals(NO_AUTH)) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity(headers); + HttpEntity entity = new HttpEntity(headersForNoAuth()); String url = microserviceUrlConverter(data, params); try { + logger.debug(EELFLoggerDelegate.debugLogger, "Before making no authentication call: {}", url); response = template.exchange(url, HttpMethod.GET, entity, String.class).getBody(); + logger.debug(EELFLoggerDelegate.debugLogger, "No authentication call response: {}", response); + } catch (HttpClientErrorException e) { throw e; } } else if (data.getSecurityType().equals(BASIC_AUTH)) { // encoding the username and password - String plainCreds = data.getUsername() + ":" + decryptedPassword(data.getPassword()); + String plainCreds = null; + try{ + plainCreds = data.getUsername() + ":" + decryptedPassword(data.getPassword()); + } + catch(Exception e){ + logger.error("problem decrypting password ... check if decryption key is correct in system.properties: ", e); + } byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Basic " + base64Creds); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity(headers); + HttpEntity entity = new HttpEntity(headersForBasicAuth(request, base64Creds)); String url = microserviceUrlConverter(data, params); try { response = template.exchange(url, HttpMethod.GET, entity, String.class).getBody(); } catch (HttpClientErrorException e) { + logger.error("Problem while talking to {1} - message: {2} ", url, e.getMessage()); throw e; } } else if (data.getSecurityType().equals(COOKIE_AUTH)) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - String rawCookie = request.getHeader("Cookie"); - headers.add("Cookie", rawCookie); - HttpEntity entity = new HttpEntity(headers); - + HttpEntity entity = new HttpEntity(headersForCookieAuth(request)); String url = microserviceUrlConverter(data, params); try { response = template.exchange(url, HttpMethod.GET, entity, String.class).getBody(); @@ -211,9 +166,10 @@ public class MicroserviceProxyServiceImpl implements MicroserviceProxyService { throw e; } } + return response; } - + private String decryptedPassword(String encryptedPwd) throws Exception { String result = ""; if (encryptedPwd != null & encryptedPwd.length() > 0) { @@ -225,6 +181,7 @@ public class MicroserviceProxyServiceImpl implements MicroserviceProxyService { throw e; } } + return result; } @@ -239,7 +196,43 @@ public class MicroserviceProxyServiceImpl implements MicroserviceProxyService { url += ADD_MARK; } } + return url; } + + private HttpHeaders headersForNoAuth(){ + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); -} + return headers; + } + + private HttpHeaders headersForBasicAuth(HttpServletRequest request, String base64Creds){ + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic " + base64Creds); + headers.setContentType(MediaType.APPLICATION_JSON); + String rawCookie = request.getHeader("Cookie"); + headers.add("Cookie", rawCookie); + + return headers; + } + + private HttpHeaders headersForCookieAuth(HttpServletRequest request){ + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + String rawCookie = request.getHeader("Cookie"); + headers.add("Cookie", rawCookie); + + return headers; + } + + private List composeParams(MicroserviceData data, EPUser user){ + List params = data.getParameterList(); + MicroserviceParameter userId_param = new MicroserviceParameter(); + userId_param.setPara_key("userId"); + userId_param.setPara_value(user.getOrgUserId()); + params.add(userId_param); + + return params; + } +} \ No newline at end of file diff --git a/ecomp-portal-BE-os/README.md b/ecomp-portal-BE-os/README.md index be584cba..89621049 100644 --- a/ecomp-portal-BE-os/README.md +++ b/ecomp-portal-BE-os/README.md @@ -19,7 +19,9 @@ Version 1.1.?, July 2017 - [Portal-35] Replaced the portal logo with onap logo on the login screen. - [Portal-40] Fix to add user roles - [Portal-47] Fix to eliminate duplicate roles on Users page -- [Portal-45] Fix to save on an application Onboarding +- [Portal-45] Fix to update an existing app on Application Onboarding +- [Portal-48] Fix to save a new app on Application onboarding + Version 1.1.0, July 2017 - [Portal-7] Improvements added as part of the rebasing process diff --git a/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/EPAppServiceImpl.java b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/EPAppServiceImpl.java index 1f829380..41e51be6 100644 --- a/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/EPAppServiceImpl.java +++ b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/EPAppServiceImpl.java @@ -25,9 +25,20 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.TreeSet; +import java.util.UUID; +import javax.servlet.http.HttpServletResponse; + +import org.hibernate.Session; +import org.hibernate.Transaction; import org.openecomp.portalapp.portal.domain.EPApp; +import org.openecomp.portalapp.portal.domain.EPUser; import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog; +import org.openecomp.portalapp.portal.logging.format.EPAppMessagesEnum; +import org.openecomp.portalapp.portal.logging.logic.EPLogUtil; +import org.openecomp.portalapp.portal.transport.FieldsValidator; +import org.openecomp.portalapp.portal.transport.OnboardingApp; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.openecomp.portalsdk.core.service.DataAccessService; import org.springframework.beans.factory.annotation.Autowired; @@ -47,6 +58,8 @@ public class EPAppServiceImpl extends EPAppCommonServiceImpl implements EPAppSer private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAppServiceImpl.class); + private static Object syncRests = new Object(); + @Autowired private DataAccessService dataAccessService; @@ -74,6 +87,71 @@ public class EPAppServiceImpl extends EPAppCommonServiceImpl implements EPAppSer } + protected void updateRestrictedApp(Long appId, OnboardingApp onboardingApp, FieldsValidator fieldsValidator, + EPUser user) { + synchronized (syncRests) { + boolean result = false; + Session localSession = null; + Transaction transaction = null; + try { + localSession = sessionFactory.openSession(); + transaction = localSession.beginTransaction(); + EPApp app; + if (appId == null) { + app = new EPApp(); + + // In the parent class, the UEB code is responsible for generating the keys/secret/mailbox but UEB Messaging + // is not actually being used currently; may be used in future at which point we can just remove this method and + // depend on parent class's method + // So, using UUID generator to generate the unique key instead. + String uuidStr = UUID.randomUUID().toString(); + String appKey = uuidStr; + String appSecret = uuidStr; + String appMailboxName = "ECOMP-PORTAL-OUTBOX"; + onboardingApp.setUebTopicName(appMailboxName); + onboardingApp.setUebKey(appKey); + onboardingApp.setUebSecret(appSecret); + + }else { + app = (EPApp) localSession.get(EPApp.class, appId); + if (app == null || app.getId() == null) { + // App is already deleted! + transaction.commit(); + localSession.close(); + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_NOT_FOUND); + return; + } + } + logger.debug(EELFLoggerDelegate.debugLogger, "LR: about to call createAppFromOnboarding"); + createAppFromOnboarding(app, onboardingApp, localSession); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: updateApp: finished calling createAppFromOnboarding"); + localSession.saveOrUpdate(app); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: updateApp: finished calling localSession.saveOrUpdate"); + // Enable or disable all menu items associated with this app + setFunctionalMenuItemsEnabled(localSession, onboardingApp.isEnabled, appId); + logger.debug(EELFLoggerDelegate.debugLogger, + "LR: updateApp: finished calling setFunctionalMenuItemsEnabled"); + transaction.commit(); + logger.debug(EELFLoggerDelegate.debugLogger, "LR: updateApp: finished calling transaction.commit"); + result = true; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "updateApp failed", e); + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebRegisterOnboardingAppError, e); + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e); + EcompPortalUtils.rollbackTransaction(transaction, + "updateApp rollback, exception = " + EcompPortalUtils.getStackTrace(e)); + } finally { + EcompPortalUtils.closeLocalSession(localSession, "updateApp"); + } + if (!result) { + fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } + + } + public CambriaTopicManager getTopicManager(LinkedList urlList, String key, String secret) throws GeneralSecurityException, Exception{ return CambriaClientFactory.createTopicManager( null, urlList, key, secret); } -- 2.16.6