2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property and Nokia
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
20 package org.oransc.ric.portal.dashboard.portalapi;
22 import java.io.IOException;
23 import java.lang.invoke.MethodHandles;
26 import javax.servlet.http.HttpServletRequest;
28 import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
29 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
30 import org.onap.portalsdk.core.restful.domain.EcompUser;
31 import org.oransc.ric.portal.dashboard.config.SpringContextCache;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.context.ApplicationContext;
37 * Implements the contract used by the Portal to transmit user details to this
38 * on-boarded application. The requests are intercepted first by a servlet in
39 * the EPSDK-FW library, which proxies the calls to these methods.
41 * An instance of this class is created upon first request to the API. But this
42 * class is found and instantiated via Class.forName(), so cannot use Spring
45 public class PortalRestCentralServiceImpl implements IPortalRestCentralService {
47 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
49 private final PortalAuthManager authManager;
50 private final DashboardUserManager userManager;
52 public PortalRestCentralServiceImpl() throws IOException, PortalAPIException {
53 final ApplicationContext context = SpringContextCache.getApplicationContext();
54 authManager = (PortalAuthManager) context.getBean(PortalAuthManager.class);
55 userManager = (DashboardUserManager) context.getBean(DashboardUserManager.class);
59 * Answers the Portal API credentials.
62 public Map<String, String> getAppCredentials() throws PortalAPIException {
63 logger.debug("getAppCredentials");
64 return authManager.getAppCredentials();
68 * Extracts the user ID from a cookie in the header
71 public String getUserId(HttpServletRequest request) throws PortalAPIException {
72 logger.debug("getuserId");
73 return authManager.valdiateEcompSso(request);
77 public void pushUser(EcompUser user) throws PortalAPIException {
78 logger.debug("pushUser: {}", user);
79 userManager.createUser(user);
83 public void editUser(String loginId, EcompUser user) throws PortalAPIException {
84 logger.debug("editUser: {}", user);
85 userManager.updateUser(loginId, user);