Commit 2cd22759 by linxu

处理sessionInfo异常

parent 2de960ef
package com.keymobile.proxy.api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;
......@@ -17,10 +19,13 @@ import java.util.Map;
@RequestMapping(value = "/")
public class LoginManagement {
private Logger logger = LoggerFactory.getLogger(LoginManagement.class);
@RequestMapping(value = "/sessionInfo", method = RequestMethod.POST)
public @ResponseBody Map<String,Object> verifyLogin(HttpServletRequest request, HttpServletResponse response) {
try {
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Map<String,Object> rs = new HashMap<>();
Map<String, Object> rs = new HashMap<>();
String userNameWithIdAttached = userDetails.getUsername();
rs.put(Constants.Session_UserName, userNameWithIdAttached.split(":")[0]);
rs.put(Constants.Session_UserId, userNameWithIdAttached.split(":")[1]);
......@@ -33,6 +38,10 @@ public class LoginManagement {
Object lang = session.getAttribute(Constants.Session_Lang);
rs.put(Constants.Session_Lang, lang != null ? lang.toString() : "cn");
return rs;
} catch (Exception e) {
logger.error("Errors occur when getting session." ,e);
return null;
}
}
@RequestMapping(value = "/lang", method = RequestMethod.POST)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment