Commit f2d7c69d by xieshaohua

sso用户登录日志改造

parent 3e493ed7
...@@ -5,11 +5,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; ...@@ -5,11 +5,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients @EnableFeignClients
@EnableAsync @EnableAsync
@EnableScheduling
public class LoginApplication { public class LoginApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON; ...@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.keymobile.auth.common.security.CustomizedUserDetailService; import com.keymobile.auth.common.security.CustomizedUserDetailService;
import com.keymobile.login.logging.LogManager; import com.keymobile.login.logging.LogManager;
import com.keymobile.login.persistence.SsoUserRepository;
import com.keymobile.login.persistence.model.SsoUserAbstract;
import com.keymobile.login.service.AuthService; import com.keymobile.login.service.AuthService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
...@@ -62,6 +64,9 @@ public class LoginManagement { ...@@ -62,6 +64,9 @@ public class LoginManagement {
@Autowired @Autowired
private CustomizedUserDetailService customizedUserDetailService; private CustomizedUserDetailService customizedUserDetailService;
@Autowired
private SsoUserRepository ssoUserRepository;
private static final Logger log = LoggerFactory.getLogger(LoginManagement.class); private static final Logger log = LoggerFactory.getLogger(LoginManagement.class);
...@@ -133,7 +138,8 @@ public class LoginManagement { ...@@ -133,7 +138,8 @@ public class LoginManagement {
HttpSession session = request.getSession(true); HttpSession session = request.getSession(true);
session.setAttribute("SPRING_SECURITY_CONTEXT", SecurityContextHolder.getContext()); session.setAttribute("SPRING_SECURITY_CONTEXT", SecurityContextHolder.getContext());
log.info("单点登录用户:" + userName); log.info("单点登录用户:" + userName);
MDC.put("user", userName + "(" + userDName + ")");
MDC.put("user", getLogUserInfo(userName, userDName));
MDC.put("session", session.getId()); MDC.put("session", session.getId());
LogManager.logInfo(Constants.SSO_API, "登录"); LogManager.logInfo(Constants.SSO_API, "登录");
response.sendRedirect(ssoRedirectUrl); response.sendRedirect(ssoRedirectUrl);
...@@ -313,6 +319,18 @@ public class LoginManagement { ...@@ -313,6 +319,18 @@ public class LoginManagement {
return null; return null;
} }
private String getLogUserInfo(String userName, String userDName) {
SsoUserAbstract user = ssoUserRepository.findById(userName).orElse(null);
if (user != null) {
return userName + "(" + userDName + "/" + user.getOrganizationname() + ")";
} else {
return userName + "(" + userDName + ")";
}
}
private Boolean needUpate(JSONObject ssoUser, Map<String, Object> user) { private Boolean needUpate(JSONObject ssoUser, Map<String, Object> user) {
if (ssoUser == null || user == null) { if (ssoUser == null || user == null) {
return false; return false;
......
package com.keymobile.login.persistence; package com.keymobile.login.persistence;
import com.keymobile.login.persistence.model.SsoUserAbstract; import com.keymobile.login.persistence.model.SsoUserAbstract;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import javax.transaction.Transactional; import javax.transaction.Transactional;
...@@ -13,4 +15,7 @@ public interface SsoUserRepository extends CrudRepository<SsoUserAbstract, Strin ...@@ -13,4 +15,7 @@ public interface SsoUserRepository extends CrudRepository<SsoUserAbstract, Strin
List<SsoUserAbstract> getByOrganizationnameLike(String organName); List<SsoUserAbstract> getByOrganizationnameLike(String organName);
List<SsoUserAbstract> findAll(Specification<SsoUserAbstract> spec, Sort sort);
} }
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