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,22 +19,29 @@ 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) {
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
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]);
rs.put(Constants.Session_UserDName, userNameWithIdAttached.split(":")[2]);
List<String> roles = new ArrayList<>();
userDetails.getAuthorities().forEach(auth -> roles.add(auth.getAuthority()));
rs.put(Constants.Session_Roles, roles);
HttpSession session = request.getSession();
Object lang = session.getAttribute(Constants.Session_Lang);
rs.put(Constants.Session_Lang, lang != null ? lang.toString() : "cn");
return rs;
try {
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
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]);
rs.put(Constants.Session_UserDName, userNameWithIdAttached.split(":")[2]);
List<String> roles = new ArrayList<>();
userDetails.getAuthorities().forEach(auth -> roles.add(auth.getAuthority()));
rs.put(Constants.Session_Roles, roles);
HttpSession session = request.getSession();
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