From 4031c6ae9074f898e768cbf5ccb5158a59a7072a Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Wed, 4 Oct 2017 08:22:43 -0400 Subject: 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) --- .../controller/core/SingleSignOnController.java | 5 ++ .../portalapp/controller/core/package-info.java | 37 +++++++++++ .../portalapp/controller/sample/package-info.java | 37 +++++++++++ .../service/OnBoardingApiServiceImpl.java | 77 +++++++++++++++++++--- 4 files changed, 148 insertions(+), 8 deletions(-) (limited to 'ecomp-sdk/epsdk-app-common/src/main/java') diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/SingleSignOnController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/SingleSignOnController.java index 17630643..fb2e3b80 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/SingleSignOnController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/SingleSignOnController.java @@ -202,6 +202,11 @@ public class SingleSignOnController extends UnRestrictedBaseController { final String redirectUrl = portalUrl + "?uebAppKey=" + uebAppKey + "&redirectUrl=" + encodedReturnToAppUrl; logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: portal-bound redirect URL is {}", redirectUrl); + + // this line may not be necessary but jsessionid coockie is not getting created in all cases; + // so force the cookie creation + request.getSession(true); + return new ModelAndView("redirect:" + redirectUrl); } } diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/package-info.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/package-info.java index 3cbcb3ba..a9db4ea1 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/package-info.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/package-info.java @@ -1,3 +1,40 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ package org.onap.portalapp.controller.core; /** diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/package-info.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/package-info.java index 57b7d4a4..6b6effca 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/package-info.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/package-info.java @@ -1,3 +1,40 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ package org.onap.portalapp.controller.sample; /** 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 getUsers() throws PortalAPIException { + String users_List = ""; try { - List users = userProfileService.findAllActive(); - List ecompUsers = new ArrayList(); - for (User user : users) - ecompUsers.add(UserUtils.convertToEcompUser(user)); - return ecompUsers; + if (isCentralized.equals(isAccessCentralized)) { + List UsersList = new ArrayList<>(); + List 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 users = userProfileService.findAllActive(); + List ecompUsers = new ArrayList(); + 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 ecompRoles = new ArrayList(); try { + + if(isCentralized.equals(isAccessCentralized)){ + User user = null; + String responseString = restApiRequestBuilder.getViaREST("/user/" + loginId, true, loginId); + user = userService.userMapper(responseString); + SortedSet 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 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"; -- cgit 1.2.3-korg