2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
6 * Modifications Copyright (C) 2020 Nordix Foundation
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ========================LICENSE_END===================================
21 package org.oransc.portal.nonrtric.controlpanel.portalapi;
23 import java.io.IOException;
24 import java.lang.invoke.MethodHandles;
27 import javax.servlet.http.HttpServletRequest;
29 import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
30 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
31 import org.onap.portalsdk.core.restful.domain.EcompUser;
32 import org.oransc.portal.nonrtric.controlpanel.ControlPanelUserManager;
33 import org.oransc.portal.nonrtric.controlpanel.config.SpringContextCache;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.context.ApplicationContext;
40 * Implements the contract used by the Portal to transmit user details to this
41 * on-boarded application. The requests are intercepted first by a servlet in
42 * the EPSDK-FW library, which proxies the calls to these methods.
44 * An instance of this class is created upon first request to the API. But this
45 * class is found and instantiated via Class.forName(), so cannot use Spring
48 public class PortalRestCentralServiceImpl implements IPortalRestCentralService {
50 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
53 private SpringContextCache springContextCache;
54 private final PortalAuthManager authManager;
55 private final ControlPanelUserManager userManager;
57 public PortalRestCentralServiceImpl() throws IOException, PortalAPIException {
58 final ApplicationContext context = springContextCache.getApplicationContext();
59 authManager = context.getBean(PortalAuthManager.class);
60 userManager = context.getBean(ControlPanelUserManager.class);
64 * Answers the Portal API credentials.
67 public Map<String, String> getAppCredentials() throws PortalAPIException {
68 logger.debug("getAppCredentials");
69 return authManager.getAppCredentials();
73 * Extracts the user ID from a cookie in the header
76 public String getUserId(HttpServletRequest request) throws PortalAPIException {
77 logger.debug("getuserId");
78 return authManager.validateEcompSso(request);
82 public void pushUser(EcompUser user) throws PortalAPIException {
83 logger.debug("pushUser: {}", user);
84 userManager.createUser(user);
88 public void editUser(String loginId, EcompUser user) throws PortalAPIException {
89 logger.debug("editUser: {}", user);
90 userManager.updateUser(loginId, user);