Null UserId while login into sdk 53/68253/5 casablanca release-2.4.0 3.0.2-ONAP
authorKotta, Shireesha (sk434m) <sk434m@att.com>
Thu, 20 Sep 2018 19:29:26 +0000 (15:29 -0400)
committerKotta, Shireesha (sk434m) <sk434m@att.com>
Fri, 21 Sep 2018 16:21:52 +0000 (12:21 -0400)
Issue-ID: PORTAL-390, PORTAL-393

Added changes to get uid from session

Change-Id: I1ac4da2679bc243408d1ae5f8ef1a3d9ad93274e
Signed-off-by: Kotta, Shireesha (sk434m) <sk434m@att.com>
ecomp-sdk/epsdk-app-os/README.md
ecomp-sdk/epsdk-app-os/src/main/java/org/onap/portalapp/controller/OnapLoginController.java [new file with mode: 0644]
ecomp-sdk/epsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java
ecomp-sdk/epsdk-app-os/src/main/webapp/WEB-INF/jsp/login.jsp
ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/InMemoryRestServer.java

index c61ebe6..1c12763 100644 (file)
@@ -14,6 +14,8 @@ https://www.eclipse.org/m2e-wtp/
 ## Release Notes
 Version 2.3.0
 - PORTAL 254 ECOMP AAF jar
+- portal 390 Null UserId while login into sdk in centralized mode
+- portal 393 InMemoryRestServer.java - Apache-2.0 (incomplete license statement)
 
 Version 2.2.0
 - PORTAL 136 Junits for SDK
diff --git a/ecomp-sdk/epsdk-app-os/src/main/java/org/onap/portalapp/controller/OnapLoginController.java b/ecomp-sdk/epsdk-app-os/src/main/java/org/onap/portalapp/controller/OnapLoginController.java
new file mode 100644 (file)
index 0000000..9e0ab54
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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============================================
+ *
+ * 
+ */
+package org.onap.portalapp.controller;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.onap.portalsdk.core.auth.LoginStrategy;
+import org.onap.portalsdk.core.controller.UnRestrictedBaseController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.servlet.ModelAndView;
+
+@Controller
+@RequestMapping("/")
+public class OnapLoginController extends UnRestrictedBaseController {
+       
+       @Autowired
+       private LoginStrategy loginStrategy;
+       
+       private String viewName;
+       
+       public String getViewName() {
+               return viewName;
+       }
+
+       public void setViewName(String viewName) {
+               this.viewName = viewName;
+       }
+
+       @RequestMapping(value = { "/do_login_external" }, method = RequestMethod.POST)
+       public ModelAndView doexternalLogin(HttpServletRequest request, HttpServletResponse response) throws Exception {
+               return loginStrategy.doLogin(request, response);
+       }
+
+}
index 074311d..c06e282 100644 (file)
 
 package org.onap.portalapp.login;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.onap.portalsdk.core.auth.LoginStrategy;
+import org.onap.portalsdk.core.command.LoginBean;
+import org.onap.portalsdk.core.domain.RoleFunction;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.menu.MenuProperties;
 import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.service.LoginService;
+import org.onap.portalsdk.core.service.RoleService;
 import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.servlet.ModelAndView;
 
 /**
@@ -58,13 +69,45 @@ public class LoginStrategyImpl extends LoginStrategy {
 
        private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LoginStrategyImpl.class);
 
+       @Autowired
+       private RoleService roleService;
+       
+       @Autowired
+       private LoginService loginService;
+       
        /**
         * login for open source is same as external login in the non-open-source
         * version.
         */
        @Override
        public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception {
-               return doExternalLogin(request, response);
+               invalidateExistingSession(request);
+
+               LoginBean commandBean = new LoginBean();
+               String loginId = request.getParameter("loginId");
+               String password = request.getParameter("password");
+               commandBean.setLoginId(loginId);
+               commandBean.setLoginPwd(password);
+               commandBean.setUserid(loginId);
+               commandBean = loginService.findUser(commandBean,
+                               (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), new HashMap());
+               List<RoleFunction> roleFunctionList = roleService.getRoleFunctions(loginId);
+
+               if (commandBean.getUser() == null) {
+                       String loginErrorMessage = (commandBean.getLoginErrorMessage() != null) ? commandBean.getLoginErrorMessage()
+                                       : "login.error.external.invalid";
+                       Map<String, String> model = new HashMap<>();
+                       model.put("error", loginErrorMessage);
+                       return new ModelAndView("login_external", "model", model);
+               } else {
+                       // store the currently logged in user's information in the session
+                       UserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(),
+                                       commandBean.getBusinessDirectMenu(),
+                                       SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_BACKDOOR), roleFunctionList);
+                       initateSessionMgtHandler(request);
+                       // user has been authenticated, now take them to the welcome page
+                       return new ModelAndView("redirect:welcome.htm");
+               }
        }
 
        @Override
index a91a3a9..6c30088 100644 (file)
                                <%=appDisplayName%>
                        </h2>
                        <br />
-                       <form action="login_external" method="POST"> 
+                       <form action="do_login_external" method="POST"> 
                                <label for="loginId">Login ID:</label>
                                <input id="loginId" name="loginId" type="text" style="width: 140px;height:25px;border-radius:7px;font-size:18px;padding-left:5px;" maxlength="30">
                                <br/>
index 2c37e21..beddc7e 100644 (file)
@@ -1,20 +1,39 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
  * You may obtain a copy of the License at
- *  
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * https://github.com/mp911de/rest-api-test
- * 
- * Embedded InMemory REST server for RESTEasy. Usage:
- * <ul>
- * <li>InMemoryRestServer srv = InMemoryRestServer.create(...) passing your resources and provider classes</li>
- * <li>srv.baseUri() for BaseUrl</li>
- * <li>srv.newRequest("/relative/resource/path") to issue requests</li>
- * <li>srv.close() to stop</li>
- * </ul>
  *
+ *             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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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============================================
+ *
+ * 
  */
 package org.onap.portalsdk.fw.test;