diff options
author | 2017-08-01 14:04:04 -0400 | |
---|---|---|
committer | 2017-08-01 15:25:38 -0400 | |
commit | 39a2ffd9ccd28539ec00e7fc16c7c9c051b1809a (patch) | |
tree | e21eef7629012a51c8a82443a39ae1a9f85e9847 /ecomp-portal-BE-common/src/main/java/org/openecomp | |
parent | 47e5623c1392c5b7e6471aec782509079e968d96 (diff) |
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) <clott@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common/src/main/java/org/openecomp')
2 files changed, 244 insertions, 244 deletions
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<String> 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<String> 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<String> 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<String> 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<String> 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<MicroserviceParameter> 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<String> entity = new HttpEntity<String>(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<String> entity = new HttpEntity<String>(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<String> entity = new HttpEntity<String>(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<MicroserviceParameter> params = data.getParameterList(); - MicroserviceParameter userId_param = new MicroserviceParameter(); - userId_param.setPara_key("userId"); - userId_param.setPara_value(user.getOrgUserId()); - params.add(userId_param); - + List<MicroserviceParameter> 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<MicroserviceParameter> params){ + + String response = null; + if (data.getSecurityType().equals(NO_AUTH)) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity<String> entity = new HttpEntity<String>(headers); + HttpEntity<String> entity = new HttpEntity<String>(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<String> entity = new HttpEntity<String>(headers); + HttpEntity<String> entity = new HttpEntity<String>(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<String> entity = new HttpEntity<String>(headers); - + HttpEntity<String> entity = new HttpEntity<String>(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<MicroserviceParameter> composeParams(MicroserviceData data, EPUser user){ + List<MicroserviceParameter> 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 |