summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/sparky/security/portal/PortalRestAPIServiceImpl.java
diff options
context:
space:
mode:
authorArul.Nambi <arul.nambi@amdocs.com>2017-09-26 14:00:57 -0400
committerArul.Nambi <arul.nambi@amdocs.com>2017-09-26 14:01:41 -0400
commitc593dfe4c59d37d5d4ea14e3ac31da3318029562 (patch)
tree76cc5a494f02e14b809caad9c050fbfd6cd61a51 /src/main/java/org/openecomp/sparky/security/portal/PortalRestAPIServiceImpl.java
parent6777c6092050a0271c5d7de9c239cf1580d41fa8 (diff)
Renaming openecomp to onap
Issue-ID: AAI-208 Change-Id: I2bd02287bed376111156aca0100e2b7b74e368e3 Signed-off-by: Arul.Nambi <arul.nambi@amdocs.com>
Diffstat (limited to 'src/main/java/org/openecomp/sparky/security/portal/PortalRestAPIServiceImpl.java')
-rw-r--r--src/main/java/org/openecomp/sparky/security/portal/PortalRestAPIServiceImpl.java226
1 files changed, 0 insertions, 226 deletions
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<EcompUser> 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<EcompRole> 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<EcompRole> 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<EcompRole> roles) throws PortalAPIException {
- LOG.debug("Push user role [loginId:" + loginId + "]");
- try {
- EcompUser user = getUser(loginId);
- if (roles != null) {
- user.setRoles(new LinkedHashSet<EcompRole>(roles));
- } else {
- user.setRoles(new LinkedHashSet<EcompRole>());
- }
- 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