Merge "Sonar: Reduce cyclomatic complexity"
[portal.git] / ecomp-portal-BE-os / src / main / java / org / onap / portalapp / controller / LoginController.java
index b301976..56064b9 100644 (file)
  *
  * ============LICENSE_END============================================
  *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * 
  */
 package org.onap.portalapp.controller;
 
 import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
 
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLDecoder;
@@ -55,7 +56,6 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.commons.lang.StringUtils;
 import org.json.JSONObject;
 import org.onap.portalapp.command.EPLoginBean;
-import org.onap.portalapp.controller.EPUnRestrictedBaseController;
 import org.onap.portalapp.portal.domain.SharedContext;
 import org.onap.portalapp.portal.service.EPLoginService;
 import org.onap.portalapp.portal.service.EPRoleFunctionService;
@@ -66,12 +66,13 @@ import org.onap.portalapp.util.EPUserUtils;
 import org.onap.portalapp.util.SessionCookieUtil;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.onap.portalsdk.core.menu.MenuProperties;
-import org.onap.portalsdk.core.onboarding.util.CipherUtil;
 import org.onap.portalsdk.core.util.SystemProperties;
 import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Controller;
 import org.springframework.util.StopWatch;
+import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -130,7 +131,7 @@ public class LoginController extends EPUnRestrictedBaseController implements Log
                String loginId = root.get("loginId").textValue();
                String password = root.get("password").textValue();
                commandBean.setLoginId(loginId);
-               commandBean.setLoginPwd(CipherUtil.encryptPKC(password));
+               commandBean.setLoginPwd(password);
                
                HashMap additionalParamsMap = new HashMap();
                StringBuilder sbAdditionalInfo = new StringBuilder();
@@ -200,7 +201,7 @@ public class LoginController extends EPUnRestrictedBaseController implements Log
                Map<Object, Object> model = new HashMap<Object, Object>();
                HashMap<Object, Object> additionalParamsMap = new HashMap<Object, Object>();
                EPLoginBean commandBean = new EPLoginBean();
-               MDC.put(MDC_KEY_REQUEST_ID, getRequestId(request));
+               MDC.put(MDC_KEY_REQUEST_ID, (getRequestId(request)==null || getRequestId(request).isEmpty()) ? UUID.randomUUID().toString():getRequestId(request));
                // get userId from cookie
                String orgUserId = SessionCookieUtil.getUserIdFromCookie(request, response);
                logger.info(EELFLoggerDelegate.debugLogger, "processSingleSignOn: begins with orgUserId {}", orgUserId);
@@ -230,11 +231,11 @@ public class LoginController extends EPUnRestrictedBaseController implements Log
                                                additionalParamsMap);
 
                                stopWatch.stop();
-                               MDC.put(EPSystemProperties.MDC_TIMER, stopWatch.getTotalTimeMillis() + "ms");
+                               MDC.put(EPSystemProperties.MDC_TIMER, String.valueOf(stopWatch.getTotalTimeMillis()));
                                logger.info(EELFLoggerDelegate.debugLogger, "Operation findUser is completed.");
                        } catch (Exception e) {
                                stopWatch.stop();
-                               MDC.put(EPSystemProperties.MDC_TIMER, stopWatch.getTotalTimeMillis() + "ms");
+                               MDC.put(EPSystemProperties.MDC_TIMER, String.valueOf(stopWatch.getTotalTimeMillis()));
                                logger.info(EELFLoggerDelegate.errorLogger, "processSingleSignOn failed on user " + orgUserId, e);
                        } finally {
                                MDC.remove(EPSystemProperties.MDC_TIMER);
@@ -411,4 +412,9 @@ public class LoginController extends EPUnRestrictedBaseController implements Log
                this.sharedContextService = sharedContextService;
        }
 
+       @ExceptionHandler(Exception.class)
+       protected void handleBadRequests(Exception e, HttpServletResponse response) throws IOException {
+               logger.warn(EELFLoggerDelegate.errorLogger, "Handling bad request", e);
+               response.sendError(HttpStatus.BAD_REQUEST.value());
+       }
 }