7e0aef2e9dc13e6192233ac2580d344686446b53
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / admin / PolicyUserInfoController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Bell Canada
7  * ================================================================================
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.policy.admin;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28
29 import org.json.JSONObject;
30 import org.onap.policy.common.logging.flexlogger.FlexLogger;
31 import org.onap.policy.common.logging.flexlogger.Logger;
32 import org.onap.portalsdk.core.controller.RestrictedBaseController;
33 import org.onap.portalsdk.core.web.support.JsonMessage;
34 import org.onap.portalsdk.core.web.support.UserUtils;
35 import org.springframework.stereotype.Controller;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.bind.annotation.RequestMethod;
38
39 import com.fasterxml.jackson.databind.ObjectMapper;
40
41 @Controller
42 @RequestMapping("/")
43 public class PolicyUserInfoController extends RestrictedBaseController {
44
45     private static final Logger LOGGER = FlexLogger.getLogger(PolicyUserInfoController.class);
46
47     @RequestMapping(value = "/get_PolicyUserInfo", method = RequestMethod.GET)
48     public void getPolicyUserInfo(HttpServletRequest request, HttpServletResponse response) {
49         JsonMessage msg;
50         try {
51             String userId = UserUtils.getUserSession(request).getOrgUserId();
52             Map<String, Object> model = new HashMap<>();
53             ObjectMapper mapper = new ObjectMapper();
54             model.put("userid", userId);
55             msg = new JsonMessage(mapper.writeValueAsString(model));
56             JSONObject j = new JSONObject(msg);
57             response.getWriter().write(j.toString());
58         } catch (Exception e) {
59             LOGGER.error("Exception Occurred" + e);
60         }
61     }
62 }