summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-common
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-app-common')
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java4
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/LogoutController.java57
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileSearchController.java18
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java4
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FavoritesControllerTest.java16
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/LogoutControllerTest.java45
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/service/OnBoardingApiServiceImplTest.java12
7 files changed, 50 insertions, 106 deletions
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java
index fbb9cc5d..09cbb0ac 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java
@@ -52,6 +52,8 @@ import org.onap.portalsdk.core.logging.aspect.AuditLog;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.onboarding.rest.FavoritesClient;
import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.onboarding.util.KeyConstants;
+import org.onap.portalsdk.core.onboarding.util.KeyProperties;
import org.onap.portalsdk.core.service.AppService;
import org.onap.portalsdk.core.util.SystemProperties;
import org.slf4j.MDC;
@@ -109,7 +111,7 @@ public class FavoritesController extends RestrictedBaseController {
appUserName = app.getUsername();
try {
decryptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
- SystemProperties.getProperty(SystemProperties.Decryption_Key));
+ KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY));
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,
"FavoritesController.getFavorites failed while decrypting password", e);
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/LogoutController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/LogoutController.java
index bbd08c45..d41bf239 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/LogoutController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/LogoutController.java
@@ -37,20 +37,16 @@
*/
package org.onap.portalapp.controller.core;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.servlet.http.HttpServletRequest;
import org.onap.portalsdk.core.controller.UnRestrictedBaseController;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.logging.aspect.MetricsLog;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
-import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
-import org.onap.portalsdk.core.web.support.UserUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;
@Controller
@@ -59,8 +55,6 @@ public class LogoutController extends UnRestrictedBaseController {
private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LogoutController.class);
- private User user;
-
/**
*
* invalidates the current application session, then redirects to portal logout
@@ -72,53 +66,12 @@ public class LogoutController extends UnRestrictedBaseController {
public ModelAndView globalLogout(HttpServletRequest request) {
ModelAndView modelView = null;
try {
- chatRoomLogout(request);
request.getSession().invalidate();
- String portalUrl = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL);
- String portalDomain = portalUrl.substring(0, portalUrl.lastIndexOf('/'));
- String redirectUrl = portalDomain + "/logout.htm";
- modelView = new ModelAndView("redirect:" + redirectUrl);
+ Map<String, Object> model = new HashMap<>();
+ return new ModelAndView("login", "model", model);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "Logout failed", e);
}
return modelView;
}
-
- /**
- *
- * invalidates the current session (application logout) and redirects user to
- * Portal.
- *
- * @param request
- * @return modelView
- */
- @RequestMapping(value = { "/app_logout.htm" }, method = RequestMethod.GET)
- public ModelAndView appLogout(HttpServletRequest request) {
- ModelAndView modelView = null;
- try {
- chatRoomLogout(request);
- modelView = new ModelAndView(
- "redirect:" + PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL));
- UserUtils.clearUserSession(request);
- request.getSession().invalidate();
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "Application Logout failed", e);
- }
- return modelView;
- }
-
- @MetricsLog
- public void chatRoomLogout(HttpServletRequest request) {
- request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
- setUser(UserUtils.getUserSession(request));
- }
-
- public User getUser() {
- return user;
- }
-
- public void setUser(User user) {
- this.user = user;
- }
-
}
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileSearchController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileSearchController.java
index ff80d413..24e44d4b 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileSearchController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileSearchController.java
@@ -139,6 +139,24 @@ public class ProfileSearchController extends RestrictedBaseController {
logger.error(EELFLoggerDelegate.applicationLogger, "getUserPagination failed", e);
}
}
+
+ @RequestMapping(value = { "/get_all_users" }, method = RequestMethod.GET)
+ public void getAllUsers(HttpServletRequest request, HttpServletResponse response) {
+ Map<String, Object> model = new HashMap<>();
+ ObjectMapper mapper = new ObjectMapper();
+ logger.info(EELFLoggerDelegate.applicationLogger, "Initiating get_all_users in ProfileSearchController");
+ List<User> profileList = null;
+ try {
+ profileList = service.listAllUsers();
+ model.put("profileList", mapper.writeValueAsString(profileList));
+ JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
+ JSONObject j = new JSONObject(msg);
+ response.setContentType(APPLICATION_JSON);
+ response.getWriter().write(j.toString());
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.applicationLogger, "getAllUsers failed", e);
+ }
+ }
@SuppressWarnings("unchecked")
private Map<String, Object> setDashboardData(HttpServletRequest request)
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
index 2b75aea1..8598ed15 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
@@ -62,6 +62,8 @@ import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler;
import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.onboarding.util.KeyConstants;
+import org.onap.portalsdk.core.onboarding.util.KeyProperties;
import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
import org.onap.portalsdk.core.restful.domain.EcompRole;
@@ -527,7 +529,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
appUserName = app.getUsername();
try {
decryptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
- SystemProperties.getProperty(SystemProperties.Decryption_Key));
+ KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY));
} catch (CipherUtilException e) {
logger.error(EELFLoggerDelegate.errorLogger, "getAppCredentials failed", e);
}
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FavoritesControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FavoritesControllerTest.java
index 5c54d40d..e980f2a1 100644
--- a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FavoritesControllerTest.java
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FavoritesControllerTest.java
@@ -53,6 +53,8 @@ import org.onap.portalsdk.core.domain.App;
import org.onap.portalsdk.core.domain.User;
import org.onap.portalsdk.core.onboarding.rest.FavoritesClient;
import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.onboarding.util.KeyConstants;
+import org.onap.portalsdk.core.onboarding.util.KeyProperties;
import org.onap.portalsdk.core.service.AppService;
import org.onap.portalsdk.core.util.SystemProperties;
import org.powermock.api.mockito.PowerMockito;
@@ -60,7 +62,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({SystemProperties.class, CipherUtil.class, FavoritesClient.class})
+@PrepareForTest({SystemProperties.class, CipherUtil.class, FavoritesClient.class, KeyProperties.class, KeyConstants.class})
public class FavoritesControllerTest {
@InjectMocks
@@ -89,6 +91,8 @@ public class FavoritesControllerTest {
HttpSession session = Mockito.mock(HttpSession.class);
Mockito.when(request.getSession()).thenReturn(session);
PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(KeyProperties.class);
+ PowerMockito.mockStatic(KeyConstants.class);
User user = new User();
user.setId(123L);
Mockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("user");
@@ -101,7 +105,7 @@ public class FavoritesControllerTest {
Mockito.when(appService.getDefaultApp()).thenReturn(app);
PowerMockito.mockStatic(CipherUtil.class);
- Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(app.getAppPassword());
+ Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(app.getAppPassword());
Mockito.when(CipherUtil.decryptPKC(app.getAppPassword(), app.getAppPassword())).thenReturn(app.getAppPassword());
PowerMockito.mockStatic(FavoritesClient.class);
@@ -120,6 +124,8 @@ public class FavoritesControllerTest {
HttpSession session = Mockito.mock(HttpSession.class);
Mockito.when(request.getSession()).thenReturn(session);
PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(KeyProperties.class);
+ PowerMockito.mockStatic(KeyConstants.class);
User user = new User();
user.setId(123L);
Mockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("user");
@@ -131,7 +137,7 @@ public class FavoritesControllerTest {
app.setAppPassword("Password");
Mockito.when(appService.getDefaultApp()).thenReturn(app);
- Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(app.getAppPassword());
+ Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(app.getAppPassword());
PowerMockito.mockStatic(FavoritesClient.class);
Mockito.when(FavoritesClient.getFavorites(Mockito.anyString(), Mockito.anyString(),
@@ -149,6 +155,8 @@ public class FavoritesControllerTest {
HttpSession session = Mockito.mock(HttpSession.class);
Mockito.when(request.getSession()).thenReturn(session);
PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(KeyProperties.class);
+ PowerMockito.mockStatic(KeyConstants.class);
User user = new User();
user.setId(123L);
Mockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("user");
@@ -161,7 +169,7 @@ public class FavoritesControllerTest {
Mockito.when(appService.getDefaultApp()).thenReturn(null);
PowerMockito.mockStatic(CipherUtil.class);
- Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(app.getAppPassword());
+ Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(app.getAppPassword());
Mockito.when(CipherUtil.decryptPKC(app.getAppPassword(), app.getAppPassword())).thenReturn(app.getAppPassword());
PowerMockito.mockStatic(FavoritesClient.class);
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/LogoutControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/LogoutControllerTest.java
index 8883cfa8..71d7277a 100644
--- a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/LogoutControllerTest.java
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/LogoutControllerTest.java
@@ -37,9 +37,6 @@
*/
package org.onap.portalapp.controller.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -111,46 +108,4 @@ public class LogoutControllerTest {
.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");
logoutController.globalLogout(mockedRequest);
}
-
- @Test
- public void globalLogoutExceptionTest(){
- PowerMockito.mockStatic(PortalApiProperties.class);
- PowerMockito.mockStatic(PortalApiConstants.class);
- Mockito.when(PortalApiProperties
- .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");
- assertNull(logoutController.globalLogout(mockedRequest));
- }
-
- @Test
- public void appLogoutTest(){
- ModelAndView actualModelView = new ModelAndView("redirect:http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");
- PowerMockito.mockStatic(PortalApiProperties.class);
- PowerMockito.mockStatic(PortalApiConstants.class);
- PowerMockito.mockStatic(RequestContextHolder.class);
- ServletRequestAttributes ServletRequestAttributes = new ServletRequestAttributes(mockedRequest);
- Mockito.when(RequestContextHolder.currentRequestAttributes()).thenReturn(ServletRequestAttributes);
- Mockito.when(PortalApiProperties
- .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");
- ModelAndView expectedModelView = logoutController.appLogout(mockedRequest);
- assertEquals(actualModelView.getViewName(), expectedModelView.getViewName());
- }
-
- @Test
- public void appLogoutExceptionTest(){
- PowerMockito.mockStatic(PortalApiProperties.class);
- PowerMockito.mockStatic(PortalApiConstants.class);
- Mockito.when(PortalApiProperties
- .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");
- assertNull(logoutController.appLogout(mockedRequest));
- }
-
- @Test
- public void getUserTest(){
- User expectedUser = new User();
- expectedUser.setActive(false);
- user.setActive(false);
- logoutController.setUser(user);
- User actualUser = logoutController.getUser();
- assertEquals(expectedUser.getActive(), actualUser.getActive());
- }
}
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/service/OnBoardingApiServiceImplTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/service/OnBoardingApiServiceImplTest.java
index 9d5e4fea..2c6827ed 100644
--- a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/service/OnBoardingApiServiceImplTest.java
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/service/OnBoardingApiServiceImplTest.java
@@ -65,6 +65,8 @@ import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler;
import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.onboarding.util.KeyConstants;
+import org.onap.portalsdk.core.onboarding.util.KeyProperties;
import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
import org.onap.portalsdk.core.restful.domain.EcompRole;
@@ -83,7 +85,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.context.ApplicationContext;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ AppContextManager.class, PortalApiProperties.class, JSONUtil.class, PortalTimeoutHandler.class, SystemProperties.class, CipherUtil.class })
+@PrepareForTest({ AppContextManager.class, PortalApiProperties.class, JSONUtil.class, PortalTimeoutHandler.class, SystemProperties.class, CipherUtil.class, KeyProperties.class, KeyConstants.class })
public class OnBoardingApiServiceImplTest {
@Mock
@@ -426,7 +428,9 @@ public class OnBoardingApiServiceImplTest {
PowerMockito.mockStatic(SystemProperties.class);
PowerMockito.mockStatic(CipherUtil.class);
- Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(key);
+ PowerMockito.mockStatic(KeyProperties.class);
+ PowerMockito.mockStatic(KeyConstants.class);
+ Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(key);
Mockito.when(CipherUtil.decryptPKC(app.getAppPassword(), key)).thenReturn(app.getAppPassword());
Mockito.when(appServiceImpl.getDefaultApp()).thenReturn(app);
OnBoardingApiServiceImpl onBoardingApiServiceImpl = new OnBoardingApiServiceImpl();
@@ -453,7 +457,9 @@ public class OnBoardingApiServiceImplTest {
PowerMockito.mockStatic(SystemProperties.class);
PowerMockito.mockStatic(CipherUtil.class);
- Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(key);
+ PowerMockito.mockStatic(KeyProperties.class);
+ PowerMockito.mockStatic(KeyConstants.class);
+ Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(key);
Mockito.when(CipherUtil.decryptPKC(app.getAppPassword(), key)).thenThrow(CipherUtilException.class);
Mockito.when(appServiceImpl.getDefaultApp()).thenReturn(app);
OnBoardingApiServiceImpl onBoardingApiServiceImpl = new OnBoardingApiServiceImpl();