From c593dfe4c59d37d5d4ea14e3ac31da3318029562 Mon Sep 17 00:00:00 2001 From: "Arul.Nambi" Date: Tue, 26 Sep 2017 14:00:57 -0400 Subject: Renaming openecomp to onap Issue-ID: AAI-208 Change-Id: I2bd02287bed376111156aca0100e2b7b74e368e3 Signed-off-by: Arul.Nambi --- .../security/portal/PortalRestAPIServiceImpl.java | 226 --------------------- 1 file changed, 226 deletions(-) delete mode 100644 src/main/java/org/openecomp/sparky/security/portal/PortalRestAPIServiceImpl.java (limited to 'src/main/java/org/openecomp/sparky/security/portal/PortalRestAPIServiceImpl.java') diff --git a/src/main/java/org/openecomp/sparky/security/portal/PortalRestAPIServiceImpl.java b/src/main/java/org/openecomp/sparky/security/portal/PortalRestAPIServiceImpl.java deleted file mode 100644 index d9c7a0e..0000000 --- a/src/main/java/org/openecomp/sparky/security/portal/PortalRestAPIServiceImpl.java +++ /dev/null @@ -1,226 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.security.portal; - -import java.io.File; -import java.io.IOException; -import java.text.MessageFormat; -import java.util.LinkedHashSet; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.openecomp.portalsdk.core.onboarding.crossapi.IPortalRestAPIService; -import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException; -import org.openecomp.portalsdk.core.restful.domain.EcompRole; -import org.openecomp.portalsdk.core.restful.domain.EcompUser; -import org.openecomp.sparky.security.EcompSso; -import org.openecomp.sparky.security.portal.config.PortalAuthenticationConfig; -import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Responds to ECOMP Portal's REST queries for user and role information and management. - */ -public class PortalRestAPIServiceImpl implements IPortalRestAPIService { - - private static final Logger LOG = LoggerFactory.getLogger(PortalRestAPIServiceImpl.class); - private static final String ERROR_MESSAGE = "Failed to {0} user [loginId:{1}]"; - - private UserManager userManager; - - /** - * Initialise user manager. - */ - public PortalRestAPIServiceImpl() { - userManager = new UserManager(new File(TierSupportUiConstants.USERS_FILE_LOCATION)); - } - - ///////////////////////////////////////////////////////////////////////////// - // User interface - ///////////////////////////////////////////////////////////////////////////// - - /* - * (non-Javadoc) - * - * @see - * com.att.fusion.core.onboarding.crossapi.IPortalRestAPIService#pushUser(com.att.fusion.core. - * restful.domain.EcompUser) - */ - @Override - public void pushUser(EcompUser user) throws PortalAPIException { - LOG.debug("Push user [loginId:" + user.getLoginId() + "]"); - - if (userManager.getUser(user.getLoginId()).isPresent()) { - String message = getMessage(ERROR_MESSAGE, "push", user.getLoginId()) - + ", user is already stored"; - LOG.error(message); - throw new PortalAPIException(message); - } - - try { - userManager.pushUser(user); - } catch (IOException e) { - String message = getMessage(ERROR_MESSAGE, "push", user.getLoginId()); - LOG.error(message, e); - throw new PortalAPIException(message, e); - } - } - - /* - * (non-Javadoc) - * - * @see com.att.fusion.core.onboarding.crossapi.IPortalRestAPIService#editUser(java.lang.String, - * com.att.fusion.core.restful.domain.EcompUser) - */ - @Override - public void editUser(String loginId, EcompUser user) throws PortalAPIException { - LOG.debug("Edit user [loginId:" + loginId + "]"); - - userManager.getUser(loginId).orElseThrow(() -> { - String message = getMessage(ERROR_MESSAGE, "edit", loginId) + ", unknown user"; - LOG.error(message); - return new PortalAPIException(message); - }); - - try { - userManager.editUser(loginId, user); - } catch (IOException e) { - String message = getMessage(ERROR_MESSAGE, "edit", loginId); - LOG.error(message, e); - throw new PortalAPIException(message, e); - } - } - - /* - * (non-Javadoc) - * - * @see com.att.fusion.core.onboarding.crossapi.IPortalRestAPIService#getUser(java.lang.String) - */ - @Override - public EcompUser getUser(String loginId) throws PortalAPIException { - LOG.debug("Get user [loginId:" + loginId + "]"); - return userManager.getUser(loginId).orElseThrow(() -> { - String message = getMessage(ERROR_MESSAGE, "get", loginId) + ", unknown user"; - LOG.error(message); - return new PortalAPIException(message); - }); - } - - /* - * (non-Javadoc) - * - * @see com.att.fusion.core.onboarding.crossapi.IPortalRestAPIService#getUsers() - */ - @Override - public List getUsers() throws PortalAPIException { - LOG.debug("Get users"); - return userManager.getUsers(); - } - - @Override - public String getUserId(HttpServletRequest request) throws PortalAPIException { - return EcompSso.validateEcompSso(request); - } - - ///////////////////////////////////////////////////////////////////////////// - // Role interface - ///////////////////////////////////////////////////////////////////////////// - - /* - * (non-Javadoc) - * - * @see com.att.fusion.core.onboarding.crossapi.IPortalRestAPIService#getAvailableRoles() - */ - @Override - public List getAvailableRoles() throws PortalAPIException { - LOG.debug("Get available roles"); - return UserManager.getRoles(); - } - - /* - * (non-Javadoc) - * - * @see - * com.att.fusion.core.onboarding.crossapi.IPortalRestAPIService#getUserRoles(java.lang.String) - */ - @Override - public List getUserRoles(String loginId) throws PortalAPIException { - LOG.debug("Get user roles"); - return userManager.getUserRoles(loginId); - } - - /* - * (non-Javadoc) - * - * @see - * com.att.fusion.core.onboarding.crossapi.IPortalRestAPIService#pushUserRole(java.lang.String, - * java.util.List) - */ - @Override - public void pushUserRole(String loginId, List roles) throws PortalAPIException { - LOG.debug("Push user role [loginId:" + loginId + "]"); - try { - EcompUser user = getUser(loginId); - if (roles != null) { - user.setRoles(new LinkedHashSet(roles)); - } else { - user.setRoles(new LinkedHashSet()); - } - editUser(loginId, user); - } catch (PortalAPIException e) { - String message = getMessage(ERROR_MESSAGE, "push role", loginId); - LOG.error(message); - throw new PortalAPIException(message, e); - } - } - - ///////////////////////////////////////////////////////////////////////////// - // Security interface - ///////////////////////////////////////////////////////////////////////////// - - /* - * (non-Javadoc) - * - * @see - * com.att.fusion.core.onboarding.crossapi.IPortalRestAPIService#isAppAuthenticated(javax.servlet. - * http.HttpServletRequest) - */ - @Override - public boolean isAppAuthenticated(HttpServletRequest request) throws PortalAPIException { - LOG.debug("Authentication request"); - PortalAuthenticationConfig config = PortalAuthenticationConfig.getInstance(); - String restUsername = request.getHeader(PortalAuthenticationConfig.PROP_USERNAME); - String restPassword = request.getHeader(PortalAuthenticationConfig.PROP_PASSWORD); - return restUsername != null && restPassword != null && restUsername.equals(config.getUsername()) - && restPassword.equals(config.getPassword()); - } - - private String getMessage(String message, Object... args) { - MessageFormat formatter = new MessageFormat(""); - formatter.applyPattern(message); - return formatter.format(args); - } - -} \ No newline at end of file -- cgit 1.2.3-korg