aboutsummaryrefslogtreecommitdiffstats
path: root/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp
diff options
context:
space:
mode:
Diffstat (limited to 'dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp')
-rw-r--r--dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java171
-rw-r--r--dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/ExternalAppInitializer.java47
-rw-r--r--dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/HibernateMappingLocations.java60
-rw-r--r--dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/lm/FusionLicenseManagerImpl.java81
-rw-r--r--dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java111
5 files changed, 470 insertions, 0 deletions
diff --git a/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java
new file mode 100644
index 0000000..c827e84
--- /dev/null
+++ b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java
@@ -0,0 +1,171 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+package org.onap.portalapp.conf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onap.portalapp.lm.FusionLicenseManagerImpl;
+import org.onap.portalapp.login.LoginStrategyImpl;
+import org.openecomp.portalapp.scheduler.LogRegistry;
+import org.openecomp.portalsdk.core.auth.LoginStrategy;
+import org.openecomp.portalsdk.core.conf.AppConfig;
+import org.openecomp.portalsdk.core.conf.Configurable;
+import org.openecomp.portalsdk.core.lm.FusionLicenseManager;
+import org.openecomp.portalsdk.core.lm.FusionLicenseManagerUtils;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
+import org.openecomp.portalsdk.core.service.DataAccessService;
+import org.openecomp.portalsdk.core.util.CacheManager;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.Profile;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.web.servlet.ViewResolver;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+
+/**
+ * Configures Spring features in the DMaaP Bus Control web application.
+ * Subclasses the ECOMP Portal SDK core AppConfig class to reuse interceptors,
+ * view resolvers and other features defined there.
+ */
+@Configuration
+@EnableWebMvc
+@ComponentScan(basePackages = "org.openecomp, org.onap",
+ // Exclude unused annotated classes with heavy dependencies.
+ excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = {
+ // EPSDK-Analytics
+ org.openecomp.portalsdk.analytics.system.fusion.adapter.FusionAdapter.class,
+ org.openecomp.portalsdk.analytics.system.fusion.adapter.RaptorAdapter.class,
+ org.openecomp.portalsdk.analytics.system.fusion.web.RaptorController.class,
+ org.openecomp.portalsdk.analytics.system.fusion.web.RaptorControllerAsync.class,
+ org.openecomp.portalsdk.analytics.system.fusion.DbUtils.class,
+ // EPSDK-App-Common
+ org.openecomp.portalapp.controller.sample.ElasticSearchController.class,
+ LogRegistry.class,
+ org.openecomp.portalapp.controller.sample.PostDroolsController.class,
+ // EPSDK-Core
+ org.openecomp.portalsdk.core.scheduler.CoreRegister.class,
+ org.openecomp.portalsdk.core.scheduler.CronRegistry.class,
+ org.openecomp.portalsdk.core.service.PostDroolsService.class
+ }))
+@Profile("src")
+@EnableAsync
+@EnableScheduling
+public class ExternalAppConfig extends AppConfig implements Configurable {
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
+
+ @Configuration
+ @Import(SystemProperties.class)
+ static class InnerConfiguration {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.openecomp.portalsdk.core.conf.AppConfig#viewResolver()
+ */
+ public ViewResolver viewResolver() {
+ return super.viewResolver();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.openecomp.portalsdk.core.conf.AppConfig#addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry)
+ */
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ super.addResourceHandlers(registry);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.openecomp.portalsdk.core.conf.AppConfig#dataAccessService()
+ */
+ @Override
+ public DataAccessService dataAccessService() {
+ // Echo the JDBC URL to assist developers when starting the app.
+ systemProperties();
+ System.out.println("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
+ + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
+ return super.dataAccessService();
+ }
+
+ /**
+ * Creates a new list with a single entry that is the external app
+ * definitions.xml path.
+ *
+ * @return List of String, size 1
+ */
+ @Override
+ public List<String> addTileDefinitions() {
+ List<String> definitions = new ArrayList<String>();
+ // DBC does not need the sample page:
+ // definitions.add("/WEB-INF/defs/definitions.xml");
+ definitions.add("/WEB-INF/dbcapp/dbcapp-definitions.xml");
+ if (logger.isDebugEnabled())
+ logger.debug(EELFLoggerDelegate.debugLogger, "addTileDefinitions: list is " + definitions);
+ return definitions;
+ }
+
+ /**
+ * Adds request interceptors to the specified registry by calling
+ * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
+ * certain paths from the session timeout interceptor.
+ */
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
+ "/api*", "/single_signon.htm", "/single_signon");
+ super.addInterceptors(registry);
+ }
+
+ /**
+ * Creates and returns a new instance of a {@link CacheManager} class.
+ *
+ * @return New instance of {@link CacheManager}
+ */
+ @Bean
+ public AbstractCacheManager cacheManager() {
+ return new CacheManager();
+ }
+
+ @Bean
+ public FusionLicenseManager fusionLicenseManager() {
+ return new FusionLicenseManagerImpl();
+ }
+
+ @Bean
+ public FusionLicenseManagerUtils fusionLicenseManagerUtils() {
+ return new FusionLicenseManagerUtils();
+ }
+
+ @Bean
+ public LoginStrategy loginStrategy() {
+ return new LoginStrategyImpl();
+ }
+}
diff --git a/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/ExternalAppInitializer.java b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/ExternalAppInitializer.java
new file mode 100644
index 0000000..347bb51
--- /dev/null
+++ b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/ExternalAppInitializer.java
@@ -0,0 +1,47 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+package org.onap.portalapp.conf;
+
+import org.openecomp.portalsdk.core.conf.AppInitializer;
+
+public class ExternalAppInitializer extends AppInitializer {
+
+ @Override
+ protected Class<?>[] getRootConfigClasses() {
+ return super.getRootConfigClasses();
+ }
+
+ @Override
+ protected Class<?>[] getServletConfigClasses() {
+ Class<?> appConfigClass = ExternalAppConfig.class;
+ // Show something on stdout to indicate the app is starting.
+ System.out.println("ExternalAppInitializer: servlet configuration class is " + appConfigClass.getName());
+ return new Class[] { appConfigClass };
+ }
+
+ /*
+ * URL request will direct to the Spring dispatcher for processing
+ */
+ @Override
+ protected String[] getServletMappings() {
+ return super.getServletMappings();
+ }
+
+}
diff --git a/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/HibernateMappingLocations.java b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/HibernateMappingLocations.java
new file mode 100644
index 0000000..cbff8a9
--- /dev/null
+++ b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/conf/HibernateMappingLocations.java
@@ -0,0 +1,60 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+package org.onap.portalapp.conf;
+
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.stereotype.Component;
+
+import org.openecomp.portalsdk.core.conf.HibernateMappingLocatable;
+
+@Component
+@Profile("src")
+public class HibernateMappingLocations implements HibernateMappingLocatable {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.portalsdk.core.conf.HibernateMappingLocatable#
+ * getMappingLocations()
+ */
+ @Override
+ public Resource[] getMappingLocations() {
+ return new Resource[] {
+ // Path is relative to WEB-INF/conf;
+ // a leading slash gets stripped so don't bother.
+ new ClassPathResource("../fusion/orm/Fusion.hbm.xml"),
+ new ClassPathResource("../dbcapp/dbcapp.hbm.xml")
+ };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.portalsdk.core.conf.HibernateMappingLocatable#
+ * getPackagesToScan()
+ */
+ @Override
+ public String[] getPackagesToScan() {
+ return new String[] { "org.onap", "org.openecomp" };
+ }
+
+}
diff --git a/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/lm/FusionLicenseManagerImpl.java b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/lm/FusionLicenseManagerImpl.java
new file mode 100644
index 0000000..49a6070
--- /dev/null
+++ b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/lm/FusionLicenseManagerImpl.java
@@ -0,0 +1,81 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+
+package org.onap.portalapp.lm;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+
+import org.openecomp.portalsdk.core.lm.FusionLicenseManager;
+
+/**
+ * Empty implementation to satisfy an interface.
+ */
+public class FusionLicenseManagerImpl implements FusionLicenseManager {
+
+ public FusionLicenseManagerImpl() {
+ }
+
+ /**
+ * An implementation of the KeyStoreParam interface that returns the
+ * information required to work with the keystore containing the private key
+ */
+ public void initKeyStoreParam() {
+ }
+
+ public void initCipherParam() {
+ }
+
+ public void initLicenseParam() {
+ }
+
+ public void doInitWork() {
+ }
+
+ public int installLicense() {
+ return OPENSOURCE_LICENSE;
+ }
+
+ public synchronized int verifyLicense(ServletContext context) {
+ return OPENSOURCE_LICENSE;
+ }
+
+ public void generateLicense(Map<String, String> clientInfoMap, List<String> ipAddressList) throws Exception {
+ }
+
+ public static String nvls(String s) {
+ return null;
+ }
+
+ public String nvl(String s) {
+ return null;
+ }
+
+ public Date getExpiredDate() {
+ return null;
+ }
+
+ public void setExpiredDate(Date expiredDate) {
+ }
+
+}
diff --git a/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java
new file mode 100644
index 0000000..1dd7abc
--- /dev/null
+++ b/dcae_dmaapbc_webapp/dbca-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java
@@ -0,0 +1,111 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+
+package org.onap.portalapp.login;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.openecomp.portalsdk.core.auth.LoginStrategy;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException;
+import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.web.servlet.ModelAndView;
+
+/**
+ * Implements basic single-signon login strategy for open-source applications
+ * when users start at Portal. Extracts an encrypted user ID sent by Portal.
+ */
+public class LoginStrategyImpl extends LoginStrategy {
+
+ private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LoginStrategyImpl.class);
+
+ /**
+ * login for open source is same as external login in the non-open-source
+ * version.
+ */
+ @Override
+ public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception {
+ return doExternalLogin(request, response);
+ }
+
+ @Override
+ public String getUserId(HttpServletRequest request) throws PortalAPIException {
+ // Check ECOMP Portal cookie
+ Cookie ep = getCookie(request, EP_SERVICE);
+ if (ep == null) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "getUserId: no EP_SERVICE cookie, returning null");
+ return null;
+ }
+
+ String userid = null;
+ try {
+ userid = getUserIdFromCookie(request);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getUserId failed", e);
+ }
+ return userid;
+ }
+
+ /**
+ * Searches the request for the user-ID cookie and decrypts the value using a
+ * key configured in properties
+ *
+ * @param request
+ * HttpServletRequest
+ * @return User ID
+ * @throws Exception
+ * On any failure
+ */
+ private String getUserIdFromCookie(HttpServletRequest request) throws Exception {
+ String userId = "";
+ Cookie userIdCookie = getCookie(request, USER_ID);
+ if (userIdCookie != null) {
+ final String cookieValue = userIdCookie.getValue();
+ if (!SystemProperties.containsProperty(SystemProperties.Decryption_Key))
+ throw new Exception("Failed to find property " + SystemProperties.Decryption_Key);
+ final String decryptionKey = SystemProperties.getProperty(SystemProperties.Decryption_Key);
+ userId = CipherUtil.decrypt(cookieValue, decryptionKey);
+ logger.debug(EELFLoggerDelegate.debugLogger, "getUserIdFromCookie: decrypted as {}", userId);
+ }
+ return userId;
+ }
+
+ /**
+ * Searches the request for the named cookie.
+ *
+ * @param request
+ * HttpServletRequest
+ * @param cookieName
+ * Name of desired cookie
+ * @return Cookie if found; otherwise null.
+ */
+ private Cookie getCookie(HttpServletRequest request, String cookieName) {
+ Cookie[] cookies = request.getCookies();
+ if (cookies != null)
+ for (Cookie cookie : cookies)
+ if (cookie.getName().equals(cookieName))
+ return cookie;
+ return null;
+ }
+
+}