Commit f2d7c69d by xieshaohua

sso用户登录日志改造

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