mirror of https://github.com/elunez/eladmin
日志加入浏览器字段
parent
0c738b1ef3
commit
e245296c7e
|
@ -11,5 +11,4 @@
|
||||||
|
|
||||||
<artifactId>eladmin-common</artifactId>
|
<artifactId>eladmin-common</artifactId>
|
||||||
<name>公共模块</name>
|
<name>公共模块</name>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,6 +1,8 @@
|
||||||
package me.zhengjie.utils;
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.ClassPathResource;
|
import cn.hutool.core.io.resource.ClassPathResource;
|
||||||
|
import eu.bitwalker.useragentutils.Browser;
|
||||||
|
import eu.bitwalker.useragentutils.UserAgent;
|
||||||
import org.lionsoul.ip2region.DataBlock;
|
import org.lionsoul.ip2region.DataBlock;
|
||||||
import org.lionsoul.ip2region.DbConfig;
|
import org.lionsoul.ip2region.DbConfig;
|
||||||
import org.lionsoul.ip2region.DbSearcher;
|
import org.lionsoul.ip2region.DbSearcher;
|
||||||
|
@ -157,6 +159,12 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getBrowser(HttpServletRequest request){
|
||||||
|
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
|
||||||
|
Browser browser = userAgent.getBrowser();
|
||||||
|
return browser.getName();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得当天是周几
|
* 获得当天是周几
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,6 +15,8 @@ import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2018-11-24
|
* @date 2018-11-24
|
||||||
|
@ -51,7 +53,8 @@ public class LogAspect {
|
||||||
currentTime = System.currentTimeMillis();
|
currentTime = System.currentTimeMillis();
|
||||||
result = joinPoint.proceed();
|
result = joinPoint.proceed();
|
||||||
Log log = new Log("INFO",System.currentTimeMillis() - currentTime);
|
Log log = new Log("INFO",System.currentTimeMillis() - currentTime);
|
||||||
logService.save(getUsername(), StringUtils.getIp(RequestHolder.getHttpServletRequest()),joinPoint, log);
|
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||||
|
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +68,8 @@ public class LogAspect {
|
||||||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||||
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime);
|
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime);
|
||||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
|
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
|
||||||
logService.save(getUsername(), StringUtils.getIp(RequestHolder.getHttpServletRequest()), (ProceedingJoinPoint)joinPoint, log);
|
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||||
|
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
|
|
|
@ -45,6 +45,8 @@ public class Log implements Serializable {
|
||||||
@Column(name = "address")
|
@Column(name = "address")
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
private String browser;
|
||||||
|
|
||||||
// 请求耗时
|
// 请求耗时
|
||||||
private Long time;
|
private Long time;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ public interface LogService {
|
||||||
Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable);
|
Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable);
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log);
|
void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询异常详情
|
* 查询异常详情
|
||||||
|
|
|
@ -25,6 +25,8 @@ public class LogErrorDTO implements Serializable {
|
||||||
// 参数
|
// 参数
|
||||||
private String params;
|
private String params;
|
||||||
|
|
||||||
|
private String browser;
|
||||||
|
|
||||||
// 请求ip
|
// 请求ip
|
||||||
private String requestIp;
|
private String requestIp;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ public class LogSmallDTO implements Serializable {
|
||||||
|
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
private String browser;
|
||||||
|
|
||||||
// 创建日期
|
// 创建日期
|
||||||
private Timestamp createTime;
|
private Timestamp createTime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class LogServiceImpl implements LogService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log){
|
public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log){
|
||||||
|
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
Method method = signature.getMethod();
|
Method method = signature.getMethod();
|
||||||
|
@ -96,6 +96,7 @@ public class LogServiceImpl implements LogService {
|
||||||
log.setMethod(methodName);
|
log.setMethod(methodName);
|
||||||
log.setUsername(username);
|
log.setUsername(username);
|
||||||
log.setParams(params.toString() + " }");
|
log.setParams(params.toString() + " }");
|
||||||
|
log.setBrowser(browser);
|
||||||
logRepository.save(log);
|
logRepository.save(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package me.zhengjie.modules.monitor.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class OnlineUser {
|
||||||
|
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
private String browser;
|
||||||
|
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
private Date lastAccessTime;
|
||||||
|
}
|
|
@ -8,8 +8,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import me.zhengjie.aop.log.Log;
|
import me.zhengjie.aop.log.Log;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.modules.monitor.service.RedisService;
|
import me.zhengjie.modules.monitor.service.RedisService;
|
||||||
import me.zhengjie.modules.security.security.AuthenticationInfo;
|
import me.zhengjie.modules.security.security.AuthInfo;
|
||||||
import me.zhengjie.modules.security.security.AuthorizationUser;
|
import me.zhengjie.modules.security.security.AuthUser;
|
||||||
import me.zhengjie.modules.security.security.ImgResult;
|
import me.zhengjie.modules.security.security.ImgResult;
|
||||||
import me.zhengjie.modules.security.security.JwtUser;
|
import me.zhengjie.modules.security.security.JwtUser;
|
||||||
import me.zhengjie.utils.EncryptUtils;
|
import me.zhengjie.utils.EncryptUtils;
|
||||||
|
@ -53,7 +53,7 @@ public class AuthenticationController {
|
||||||
@Log("用户登录")
|
@Log("用户登录")
|
||||||
@ApiOperation("登录授权")
|
@ApiOperation("登录授权")
|
||||||
@PostMapping(value = "/login")
|
@PostMapping(value = "/login")
|
||||||
public ResponseEntity login(@Validated @RequestBody AuthorizationUser authorizationUser){
|
public ResponseEntity login(@Validated @RequestBody AuthUser authorizationUser){
|
||||||
|
|
||||||
// 查询验证码
|
// 查询验证码
|
||||||
String code = redisService.getCodeVal(authorizationUser.getUuid());
|
String code = redisService.getCodeVal(authorizationUser.getUuid());
|
||||||
|
@ -79,7 +79,7 @@ public class AuthenticationController {
|
||||||
final String token = jwtTokenUtil.generateToken(jwtUser);
|
final String token = jwtTokenUtil.generateToken(jwtUser);
|
||||||
|
|
||||||
// 返回 token
|
// 返回 token
|
||||||
return ResponseEntity.ok(new AuthenticationInfo(token,jwtUser));
|
return ResponseEntity.ok(new AuthInfo(token,jwtUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获取用户信息")
|
@ApiOperation("获取用户信息")
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
package me.zhengjie.modules.security.security;
|
package me.zhengjie.modules.security.security;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2018-11-23
|
* @date 2018-11-23
|
||||||
* 返回token
|
* 返回token
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class AuthenticationInfo implements Serializable {
|
public class AuthInfo implements Serializable {
|
||||||
|
|
||||||
private final String token;
|
private final String token;
|
||||||
|
|
||||||
private final JwtUser user;
|
private final JwtUser user;
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ import javax.validation.constraints.NotBlank;
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class AuthorizationUser {
|
public class AuthUser {
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String username;
|
private String username;
|
|
@ -7,7 +7,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
5
pom.xml
5
pom.xml
|
@ -200,6 +200,11 @@
|
||||||
<artifactId>easy-captcha</artifactId>
|
<artifactId>easy-captcha</artifactId>
|
||||||
<version>1.6.2</version>
|
<version>1.6.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.bitwalker</groupId>
|
||||||
|
<artifactId>UserAgentUtils</artifactId>
|
||||||
|
<version>1.20</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
Loading…
Reference in New Issue