summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Lott (cl778h) <clott@research.att.com>2017-08-01 14:04:04 -0400
committerChristopher Lott (cl778h) <clott@research.att.com>2017-08-01 15:25:38 -0400
commit39a2ffd9ccd28539ec00e7fc16c7c9c051b1809a (patch)
treee21eef7629012a51c8a82443a39ae1a9f85e9847
parent47e5623c1392c5b7e6471aec782509079e968d96 (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>
-rw-r--r--deliveries/etc.zipbin11469 -> 11448 bytes
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/EPAppCommonServiceImpl.java343
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/MicroserviceProxyServiceImpl.java145
-rw-r--r--ecomp-portal-BE-os/README.md4
-rw-r--r--ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/EPAppServiceImpl.java78
5 files changed, 325 insertions, 245 deletions
diff --git a/deliveries/etc.zip b/deliveries/etc.zip
index 7d590d5a..dc530f51 100644
--- a/deliveries/etc.zip
+++ b/deliveries/etc.zip
Binary files differ
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
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<String> urlList, String key, String secret) throws GeneralSecurityException, Exception{
return CambriaClientFactory.createTopicManager( null, urlList, key, secret);
}