新增人员登录日志
This commit is contained in:
@@ -3,10 +3,12 @@ package com.adc.da.login.rest;
|
||||
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.Result;
|
||||
import com.adc.da.login.exception.TokenRuntimeException;
|
||||
import com.adc.da.login.util.IDMUtil;
|
||||
import com.adc.da.login.util.IpUtil;
|
||||
import com.adc.da.login.util.JwtUtils;
|
||||
import com.adc.da.sys.entity.LoginInfoEO;
|
||||
import com.adc.da.sys.entity.UserEO;
|
||||
import com.adc.da.sys.service.ILoginInfoEOService;
|
||||
import com.adc.da.sys.service.IUserEOService;
|
||||
import com.adc.da.util.Encodes;
|
||||
import com.adc.da.util.PasswordUtils;
|
||||
@@ -26,8 +28,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -44,6 +47,8 @@ public class LoginRestController {
|
||||
private IDMUtil idmUtil;
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
@Autowired
|
||||
private ILoginInfoEOService loginInfoEOService;
|
||||
|
||||
@ApiOperation(value = "登录")
|
||||
// @GetMapping(value = "/login")
|
||||
@@ -70,6 +75,11 @@ public class LoginRestController {
|
||||
String userStr = JSON.toJSONString(userEO);
|
||||
String userStr2 = URLEncoder.encode(userStr,"UTF-8");
|
||||
userStr = encoder.encode(userStr2.getBytes());
|
||||
|
||||
LoginInfoEO loginInfoEO=new LoginInfoEO();
|
||||
loginInfoEO.setUserId(userEO.getUsid());
|
||||
loginInfoEO.setLoginAddress(IpUtil.getIpAddr(request));
|
||||
loginInfoEOService.saveBean(loginInfoEO);
|
||||
return Result.success(userStr);
|
||||
} else {
|
||||
log.info("用户[{}]密码验证失败", username);
|
||||
@@ -81,7 +91,7 @@ public class LoginRestController {
|
||||
// @GetMapping(value = "/login")
|
||||
@GetMapping(value = "/checkPage")
|
||||
@ResponseBody
|
||||
public ResponseMessage<String> checkPage(@RequestParam @NotNull(message = "请输入用户名") String username) throws UnsupportedEncodingException {
|
||||
public ResponseMessage<String> checkPage(HttpServletRequest request,@RequestParam @NotNull(message = "请输入用户名") String username) throws UnsupportedEncodingException {
|
||||
username =new String(Encodes.decodeBase64(username), StandardCharsets.UTF_8);
|
||||
UserEO userEO = userService.getUserByLoginNameNotDeleted(username);
|
||||
if (null == userEO) {
|
||||
@@ -100,6 +110,11 @@ public class LoginRestController {
|
||||
String userStr = JSON.toJSONString(userEO);
|
||||
String userStr2 = URLEncoder.encode(userStr,"UTF-8");
|
||||
userStr = encoder.encode(userStr2.getBytes());
|
||||
|
||||
LoginInfoEO loginInfoEO=new LoginInfoEO();
|
||||
loginInfoEO.setUserId(userEO.getUsid());
|
||||
loginInfoEO.setLoginAddress(IpUtil.getIpAddr(request));
|
||||
loginInfoEOService.saveBean(loginInfoEO);
|
||||
return Result.success(userStr);
|
||||
|
||||
}
|
||||
@@ -108,7 +123,7 @@ public class LoginRestController {
|
||||
// @GetMapping(value = "/login")
|
||||
@GetMapping(value = "/checkPageNoEncryption")
|
||||
@ResponseBody
|
||||
public ResponseMessage<String> checkPageNoEncryption(@RequestParam @NotNull(message = "请输入用户名") String username) throws UnsupportedEncodingException {
|
||||
public ResponseMessage<String> checkPageNoEncryption(HttpServletRequest request,@RequestParam @NotNull(message = "请输入用户名") String username) throws UnsupportedEncodingException {
|
||||
UserEO userEO = userService.getUserByLoginNameNotDeleted(username);
|
||||
if (null == userEO) {
|
||||
log.info("用户[{}]身份验证失败", username);
|
||||
@@ -126,6 +141,11 @@ public class LoginRestController {
|
||||
String userStr = JSON.toJSONString(userEO);
|
||||
String userStr2 = URLEncoder.encode(userStr,"UTF-8");
|
||||
userStr = encoder.encode(userStr2.getBytes());
|
||||
|
||||
LoginInfoEO loginInfoEO=new LoginInfoEO();
|
||||
loginInfoEO.setUserId(userEO.getUsid());
|
||||
loginInfoEO.setLoginAddress(IpUtil.getIpAddr(request));
|
||||
loginInfoEOService.saveBean(loginInfoEO);
|
||||
return Result.success(userStr);
|
||||
|
||||
}
|
||||
@@ -134,7 +154,7 @@ public class LoginRestController {
|
||||
@ApiOperation(value = "登录")
|
||||
@PostMapping(value = "/loginIdm")
|
||||
@ResponseBody
|
||||
public ResponseMessage<String> loginRest(String code) throws UnsupportedEncodingException {
|
||||
public ResponseMessage<String> loginRest(HttpServletRequest request,String code) throws UnsupportedEncodingException {
|
||||
String account = idmUtil.idmLogin(code);
|
||||
if(StringUtils.isBlank(account)){
|
||||
return Result.error("r0011", "用户不存在");
|
||||
@@ -160,6 +180,10 @@ public class LoginRestController {
|
||||
String userStr = JSON.toJSONString(userEO);
|
||||
String userStr2 = URLEncoder.encode(userStr,"UTF-8");
|
||||
userStr = encoder.encode(userStr2.getBytes());
|
||||
LoginInfoEO loginInfoEO=new LoginInfoEO();
|
||||
loginInfoEO.setUserId(userEO.getUsid());
|
||||
loginInfoEO.setLoginAddress(IpUtil.getIpAddr(request));
|
||||
loginInfoEOService.saveBean(loginInfoEO);
|
||||
return Result.success(userStr);
|
||||
}
|
||||
|
||||
@@ -180,5 +204,30 @@ public class LoginRestController {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getIpAddress() {
|
||||
try {
|
||||
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
InetAddress ip = null;
|
||||
while (allNetInterfaces.hasMoreElements()) {
|
||||
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
|
||||
if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
|
||||
continue;
|
||||
} else {
|
||||
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
|
||||
while (addresses.hasMoreElements()) {
|
||||
ip = addresses.nextElement();
|
||||
if (ip != null && ip instanceof Inet4Address) {
|
||||
return ip.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("IP地址获取失败" + e.toString());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.adc.da.login.util;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* @program: LAWSSystem
|
||||
* @description: 获取ip的工具类
|
||||
* @author: duyunbao
|
||||
* @create: 2019-04-15 16:32
|
||||
*/
|
||||
public class IpUtil {
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
String ipAddress = null;
|
||||
try {
|
||||
ipAddress = request.getHeader("x-forwarded-for");
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getRemoteAddr();
|
||||
if (ipAddress.equals("127.0.0.1")) {
|
||||
// 根据网卡取本机配置的IP
|
||||
InetAddress inet = null;
|
||||
try {
|
||||
inet = InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ipAddress = inet.getHostAddress();
|
||||
}
|
||||
}
|
||||
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
|
||||
if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length()
|
||||
// = 15
|
||||
if (ipAddress.indexOf(",") > 0) {
|
||||
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ipAddress="";
|
||||
}
|
||||
// ipAddress = this.getRequest().getRemoteAddr();
|
||||
|
||||
return ipAddress;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.adc.da.sys.entity;
|
||||
|
||||
import com.adc.da.base.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -10,6 +11,7 @@ import java.util.Date;
|
||||
* <b>日期:</b> 2018-09-03 <br>
|
||||
* <b>版权所有:<b>版权归北京卡达克数据技术中心所有。<br>
|
||||
*/
|
||||
@TableName(value = "TS_LOGIN_INFO")
|
||||
public class LoginInfoEO extends BaseEntity {
|
||||
|
||||
@org.springframework.format.annotation.DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@@ -21,7 +23,7 @@ public class LoginInfoEO extends BaseEntity {
|
||||
private Date loginTime;
|
||||
private String userId;
|
||||
private String id;
|
||||
private int countNum;
|
||||
// private int countNum;
|
||||
private String maxCountDate;
|
||||
|
||||
/**
|
||||
@@ -130,13 +132,13 @@ public class LoginInfoEO extends BaseEntity {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getCountNum() {
|
||||
return countNum;
|
||||
}
|
||||
// public int getCountNum() {
|
||||
// return countNum;
|
||||
// }
|
||||
|
||||
public void setCountNum(int countNum) {
|
||||
this.countNum = countNum;
|
||||
}
|
||||
// public void setCountNum(int countNum) {
|
||||
// this.countNum = countNum;
|
||||
// }
|
||||
|
||||
public String getMaxCountDate() {
|
||||
return maxCountDate;
|
||||
|
||||
Reference in New Issue
Block a user