diff options
author | Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com> | 2018-09-25 13:59:56 -0400 |
---|---|---|
committer | Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com> | 2018-09-26 16:52:00 -0400 |
commit | a59bc3e85eaf33c0a38063e5c30fe890588a0eb1 (patch) | |
tree | b19ba17d5dbd6cecc0b34c0ef6b158c088746384 /ecomp-portal-BE-os | |
parent | 4be6886a011ddbc4543e8c27b759a27ff3415c18 (diff) |
login and Certman AAF Integration changes
Issue-ID: PORTAL-386, PORTAL-389
failed to create user with special char in login_id
Change-Id: I415adf615a7af97319d8d11a740e75d3dfa11583
Signed-off-by: Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-os')
6 files changed, 27 insertions, 209 deletions
diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java index ee53eba0..e9c48251 100644 --- a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java @@ -161,9 +161,10 @@ public class ExternalAppConfig extends AppConfig implements Configurable { MDC.put(MDC_SERVICE_INSTANCE_ID, ""); MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.INFORMATIONAL.severity()); MDC.put(MDC_INSTANCE_UUID, SystemProperties.getProperty(SystemProperties.INSTANCE_UUID)); - if("true".equalsIgnoreCase(remotecentralizedsystemaccess)){ - importFromExternalAuth(); - } + + // if("true".equalsIgnoreCase(remotecentralizedsystemaccess)){ + // importFromExternalAuth(); + // } } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "init failed", e); } @@ -174,7 +175,10 @@ public class ExternalAppConfig extends AppConfig implements Configurable { * for all the centralized applications between AAF and ONAP, updates * fn_user and fn_user_role with user information from AAF. * + * This is being handled in AAF directly, so it has been deprecated + * */ + @Deprecated private void importFromExternalAuth() throws Exception { JSONArray aafAppRoles = new JSONArray(); JSONArray aafUserList = new JSONArray(); diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/AppsCacheService.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/AppsCacheService.java deleted file mode 100644 index a3255480..00000000 --- a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/AppsCacheService.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright (C) 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============================================ - * - * - */ - -package org.onap.portalapp.portal.service; - -import org.onap.portalapp.portal.domain.EPApp; - -public interface AppsCacheService { - - /** - * returns an app by id from the cache - * @param appId - * @return corresponding App - */ - EPApp getApp(Long appId); - - /** - * returns the corresponding application endpoint - * @param appId - * @return if appId exists in cache, then return corresponding application endpoint, null otherwise. - */ - String getAppEndpoint(Long appId); -} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java deleted file mode 100644 index e6306c9c..00000000 --- a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright (C) 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============================================ - * - * - */ -package org.onap.portalapp.portal.service; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.PostConstruct; - -import org.onap.portalapp.portal.domain.EPApp; -import org.onap.portalapp.portal.logging.aop.EPMetricsLog; -import org.onap.portalapp.portal.service.AppsCacheService; -import org.onap.portalapp.portal.service.EPAppService; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.stereotype.Service; - -@Service("appsCacheService") -@org.springframework.context.annotation.Configuration -@EnableAspectJAutoProxy -@EPMetricsLog -public class AppsCacheServiceImple implements AppsCacheService { - @Autowired - EPAppService appsService; - - EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppsCacheServiceImple.class); - - private static long updateTime = 0; - private static final int cacheUpdateIntervalInSeconds = 10; - - private static volatile Map<Long, EPApp> appsMap; - - @PostConstruct - public void init() { - this.refreshAppsMap(); - } - - private Map<Long, EPApp> refreshAppsMap() { - long now = System.currentTimeMillis(); - - if(noNeedToUpdate(now)) - return null; - - synchronized (this) { - if(noNeedToUpdate(now)) - return null; - List<EPApp> allApps = appsService.getAppsFullList(); - Map<Long, EPApp> newAppsMap = new HashMap<Long, EPApp>(); - for (EPApp app : allApps) { - newAppsMap.put(app.getId(), app); - } - // Switch cache with the new one. - appsMap = newAppsMap; - updateTime = now; - } - - return appsMap; - } - - private boolean noNeedToUpdate(long now) { - long secondsPassed = (now - updateTime)/1000; - if(secondsPassed < cacheUpdateIntervalInSeconds){ - logger.debug(EELFLoggerDelegate.debugLogger, "no need to refresh yet, seconds since last refresh: " + secondsPassed + ", refresh interval (sec) = " + cacheUpdateIntervalInSeconds); - return true; // no need to update cache - } - return false; // its time to update - } - - @Override - public String getAppEndpoint(Long appId) { - refreshAppsMap(); - EPApp app = appsMap.get(appId); - if(app != null) - return app.getAppRestEndpoint(); - return null; - } - - @Override - public EPApp getApp(Long appId) { - refreshAppsMap(); - EPApp app = appsMap.get(appId); - if(app != null) - return app; - return null; - } - -} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/SearchServiceImpl.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/SearchServiceImpl.java index 48f6d298..e0934713 100644 --- a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/SearchServiceImpl.java +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/SearchServiceImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -79,18 +79,13 @@ public class SearchServiceImpl implements SearchService { public String searchUsersInFnTable(String searchString) { String orgUserId = null; List<String> tokens = EcompPortalUtils.parsingByRegularExpression(searchString, " "); - for (int i = 0; i < tokens.size(); i++) { // find userid if possible and remove it from tokens - if (tokens.get(i).matches(".*\\d+.*")) { - orgUserId = tokens.get(i); - tokens.remove(i); - } - } while (tokens.size() > 2) { // we use no more then first 2 tokens (userId is removed, see above) tokens.remove(tokens.size() - 1); } EPUser attrUser = new EPUser(); attrUser.setOrgUserId(orgUserId); - List<UserWithNameSurnameTitle> resultOfSearch = new ArrayList<UserWithNameSurnameTitle>(), resultOfAdditionalSearch = null; + List<UserWithNameSurnameTitle> resultOfSearch = new ArrayList<UserWithNameSurnameTitle>(), resultOfAdditionalSearch = null, + resultOfSearchUserId = new ArrayList<UserWithNameSurnameTitle>(); if (tokens.size() == 2) { attrUser.setFirstName(tokens.get(0)); attrUser.setLastName(tokens.get(1)); @@ -107,6 +102,7 @@ public class SearchServiceImpl implements SearchService { } else if (tokens.size() == 1) { attrUser.setFirstName(tokens.get(0)); resultOfSearch = this.searchUsersByName(attrUser); + resultOfSearchUserId = this.searchUsersByUserId(attrUser); resultOfSearch = this.removeWrongFirstNames(resultOfSearch, tokens.get(0)); if (resultOfSearch.size() < maxSizeOfSearchResult) { attrUser.setFirstName(null); @@ -114,12 +110,11 @@ public class SearchServiceImpl implements SearchService { resultOfAdditionalSearch = this.searchUsersByName(attrUser); resultOfAdditionalSearch = this.removeWrongLastNames(resultOfAdditionalSearch, tokens.get(0)); } - } else if (orgUserId != null) { - resultOfSearch = this.searchUsersByUserId(attrUser); } if (resultOfAdditionalSearch != null) { resultOfSearch.addAll(resultOfAdditionalSearch); } + resultOfSearch.addAll(resultOfSearchUserId); resultOfSearch = this.cutSearchResultToMaximumSize(resultOfSearch); ObjectMapper mapper = new ObjectMapper(); String result = "[]"; diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/UserServiceImpl.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/UserServiceImpl.java index b5ccfc02..fccd4ff8 100644 --- a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/UserServiceImpl.java +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/UserServiceImpl.java @@ -159,9 +159,12 @@ public class UserServiceImpl implements UserService { List list = null; StringBuffer criteria = new StringBuffer(); - if (firstName != null) + if (firstName != null && lastName != null) + criteria.append(" where first_name = '").append(firstName).append("' and last_name = '") + .append(lastName).append("'"); + else if (firstName != null) criteria.append(" where first_name = '").append(firstName).append("'"); - if (lastName != null) + else if (lastName != null) criteria.append(" where last_name = '").append(lastName).append("'"); list = getDataAccessService().getList(EPUser.class, criteria.toString(), null, null); return (list == null || list.size() == 0) ? null : list; diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/SearchServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/SearchServiceImplTest.java index 6b24e96d..04234059 100644 --- a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/SearchServiceImplTest.java +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/SearchServiceImplTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -37,7 +37,8 @@ */ package org.onap.portalapp.portal.service; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import java.util.ArrayList; import java.util.List; @@ -55,8 +56,6 @@ import org.mockito.MockitoAnnotations; import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.framework.MockEPUser; import org.onap.portalapp.portal.framework.MockitoTestSuite; -import org.onap.portalapp.portal.service.SearchServiceImpl; -import org.onap.portalapp.portal.service.UserService; import org.onap.portalapp.portal.transport.UserWithNameSurnameTitle; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.powermock.api.mockito.PowerMockito; @@ -105,19 +104,18 @@ public class SearchServiceImplTest { PowerMockito.mockStatic(EcompPortalUtils.class); List<String> list = new ArrayList<>(); String str = "Test"; - String str2 = "Test new"; - String str1 = "Test new1"; + String str1 = "Testnew"; list.add(str); list.add(str1); - list.add(str2); - Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list); + Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test Testnew", " ")).thenReturn(list); + @SuppressWarnings({ "unchecked", "rawtypes" }) List<EPUser> userList = new ArrayList(); EPUser user = mockUser.mockEPUser(); - user.setLastName("Test new"); + user.setLastName("Testnew"); userList.add(user); - Mockito.when( this.userService.getUserByFirstLastName("Test","Test new")).thenReturn(userList); - String result = searchServiceImpl.searchUsersInPhoneBook("Test"); - assertEquals("[{\"orgUserId\":\"guestT\",\"firstName\":\"test\",\"lastName\":\"Test new\",\"jobTitle\":null}]" , result); + Mockito.when( this.userService.getUserByFirstLastName("Test","Testnew")).thenReturn(userList); + String result = searchServiceImpl.searchUsersInPhoneBook("Test Testnew"); + assertEquals("[{\"orgUserId\":\"guestT\",\"firstName\":\"test\",\"lastName\":\"Testnew\",\"jobTitle\":null}]" , result); } |