diff options
author | Christopher Lott (cl778h) <clott@research.att.com> | 2017-10-04 08:22:43 -0400 |
---|---|---|
committer | Christopher Lott (cl778h) <clott@research.att.com> | 2017-10-04 08:24:16 -0400 |
commit | 4031c6ae9074f898e768cbf5ccb5158a59a7072a (patch) | |
tree | 1aa2ff6ce771d6f605f8d4e89db18240623545f2 /ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service | |
parent | 3a2b5c60384feb490e878020bdb9c01f514d7856 (diff) |
Repair redirect; correct javadoc site path
[PORTAL-53] Correct path for deployment of javadoc web site
[PORTAL-78] Prevent SDJ from redirecting multiples times during single signon
[St164634] Tone down the logging when communicating with the Partnering Applications
Add missing license headers; drop FusionLicenseImpl.
Issue: PORTAL-53 PORTAL-78
Change-Id: I3f8200d8e41754ade05e3f7b38d0db6bdd5e59e8
Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service')
-rw-r--r-- | ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java | 77 |
1 files changed, 69 insertions, 8 deletions
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 9c77441d..3efe46fd 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 @@ -55,10 +55,14 @@ import org.onap.portalsdk.core.onboarding.client.AppContextManager; import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestAPIService; import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; import org.onap.portalsdk.core.restful.domain.EcompRole; import org.onap.portalsdk.core.restful.domain.EcompUser; +import org.onap.portalsdk.core.service.RestApiRequestBuilder; import org.onap.portalsdk.core.service.RoleService; import org.onap.portalsdk.core.service.UserProfileService; +import org.onap.portalsdk.core.service.UserService; import org.onap.portalsdk.core.service.WebServiceCallService; import org.onap.portalsdk.core.util.JSONUtil; import org.onap.portalsdk.core.util.SystemProperties; @@ -66,6 +70,9 @@ import org.onap.portalsdk.core.web.support.UserUtils; import org.slf4j.MDC; import org.springframework.context.ApplicationContext; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; + /** * Implements the REST API interface to answer requests made by Portal app about * users and active sessions. @@ -84,7 +91,14 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService { private IAdminAuthExtension adminAuthExtensionServiceImpl; private LoginStrategy loginStrategy; - + private UserService userService; + private RestApiRequestBuilder restApiRequestBuilder; + + private static final String isAccessCentralized = PortalApiProperties + .getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED); + + private static final String isCentralized = "remote"; + public OnBoardingApiServiceImpl() { // Defend against null-pointer exception during server startup // that was caused by a spurious Spring annotation on this class. @@ -96,6 +110,10 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService { loginStrategy = appContext.getBean(LoginStrategy.class); // initialize the base class definition for Admin Auth Extension adminAuthExtensionServiceImpl = appContext.getBean(IAdminAuthExtension.class); + userService = appContext.getBean(UserService.class); + if(isCentralized.equals(isAccessCentralized)){ + restApiRequestBuilder = appContext.getBean(RestApiRequestBuilder.class); + } } private void setCurrentAttributes(User user, EcompUser userJson) { @@ -200,7 +218,15 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService { try { if (logger.isDebugEnabled()) logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## loginId: {}", loginId); - User user = userProfileService.getUserByLoginId(loginId); + + User user = null; + if(isCentralized.equals(isAccessCentralized)){ + String responseString = restApiRequestBuilder.getViaREST("/user/" + loginId, true, loginId); + user = userService.userMapper(responseString); + } + else{ + user = userProfileService.getUserByLoginId(loginId); + } if (user == null) { logger.info(EELFLoggerDelegate.debugLogger, "User + " + loginId + " doesn't exist"); return null; @@ -224,16 +250,36 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService { @Override public List<EcompUser> getUsers() throws PortalAPIException { + String users_List = ""; try { - List<User> users = userProfileService.findAllActive(); - List<EcompUser> ecompUsers = new ArrayList<EcompUser>(); - for (User user : users) - ecompUsers.add(UserUtils.convertToEcompUser(user)); - return ecompUsers; + if (isCentralized.equals(isAccessCentralized)) { + List<EcompUser> UsersList = new ArrayList<>(); + List<EcompUser> finalUsersList = new ArrayList<>(); + users_List = restApiRequestBuilder.getViaREST("/users", true, null); + ObjectMapper mapper = new ObjectMapper(); + UsersList = mapper.readValue(users_List, + TypeFactory.defaultInstance().constructCollectionType(List.class, EcompUser.class)); + for (EcompUser userString : UsersList) { + EcompUser ecompUser = mapper.convertValue(userString, EcompUser.class); + finalUsersList.add(ecompUser); + } + return UsersList; + } + else { + List<User> users = userProfileService.findAllActive(); + List<EcompUser> ecompUsers = new ArrayList<EcompUser>(); + for (User user : users) + ecompUsers.add(UserUtils.convertToEcompUser(user)); + return ecompUsers; + } } catch (Exception e) { String response = "OnboardingApiService.getUsers failed"; logger.error(EELFLoggerDelegate.errorLogger, response, e); - throw new PortalAPIException(response, e); + if (users_List.equals("")) { + throw new PortalAPIException("Application is Inactive"); + } else { + throw new PortalAPIException(response, e); + } } } @@ -301,6 +347,20 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService { logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## loginId: {}", loginId); List<EcompRole> ecompRoles = new ArrayList<EcompRole>(); try { + + if(isCentralized.equals(isAccessCentralized)){ + User user = null; + String responseString = restApiRequestBuilder.getViaREST("/user/" + loginId, true, loginId); + user = userService.userMapper(responseString); + SortedSet<Role> currentRoles = null; + if (user != null) { + currentRoles = user.getRoles(); + if (currentRoles != null) + for (Role role : currentRoles) + ecompRoles.add(UserUtils.convertToEcompRole(role)); + } + } + else{ User user = userProfileService.getUserByLoginId(loginId); SortedSet<Role> currentRoles = null; if (user != null) { @@ -309,6 +369,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService { for (Role role : currentRoles) ecompRoles.add(UserUtils.convertToEcompRole(role)); } + } return ecompRoles; } catch (Exception e) { String response = "OnboardingApiService.getUserRoles failed"; |