mirror of https://github.com/elunez/eladmin
日志加入浏览器字段
parent
0c738b1ef3
commit
e245296c7e
|
@ -11,5 +11,4 @@
|
|||
|
||||
<artifactId>eladmin-common</artifactId>
|
||||
<name>公共模块</name>
|
||||
|
||||
</project>
|
|
@ -1,6 +1,8 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
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.DbConfig;
|
||||
import org.lionsoul.ip2region.DbSearcher;
|
||||
|
@ -157,6 +159,12 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
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.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
|
@ -51,7 +53,8 @@ public class LogAspect {
|
|||
currentTime = System.currentTimeMillis();
|
||||
result = joinPoint.proceed();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -65,7 +68,8 @@ public class LogAspect {
|
|||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime);
|
||||
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() {
|
||||
|
|
|
@ -45,6 +45,8 @@ public class Log implements Serializable {
|
|||
@Column(name = "address")
|
||||
private String address;
|
||||
|
||||
private String browser;
|
||||
|
||||
// 请求耗时
|
||||
private Long time;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public interface LogService {
|
|||
Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
@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 browser;
|
||||
|
||||
// 请求ip
|
||||
private String requestIp;
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ public class LogSmallDTO implements Serializable {
|
|||
|
||||
private String address;
|
||||
|
||||
private String browser;
|
||||
|
||||
// 创建日期
|
||||
private Timestamp createTime;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class LogServiceImpl implements LogService {
|
|||
|
||||
@Override
|
||||
@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();
|
||||
Method method = signature.getMethod();
|
||||
|
@ -96,6 +96,7 @@ public class LogServiceImpl implements LogService {
|
|||
log.setMethod(methodName);
|
||||
log.setUsername(username);
|
||||
log.setParams(params.toString() + " }");
|
||||
log.setBrowser(browser);
|
||||
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.exception.BadRequestException;
|
||||
import me.zhengjie.modules.monitor.service.RedisService;
|
||||
import me.zhengjie.modules.security.security.AuthenticationInfo;
|
||||
import me.zhengjie.modules.security.security.AuthorizationUser;
|
||||
import me.zhengjie.modules.security.security.AuthInfo;
|
||||
import me.zhengjie.modules.security.security.AuthUser;
|
||||
import me.zhengjie.modules.security.security.ImgResult;
|
||||
import me.zhengjie.modules.security.security.JwtUser;
|
||||
import me.zhengjie.utils.EncryptUtils;
|
||||
|
@ -53,7 +53,7 @@ public class AuthenticationController {
|
|||
@Log("用户登录")
|
||||
@ApiOperation("登录授权")
|
||||
@PostMapping(value = "/login")
|
||||
public ResponseEntity login(@Validated @RequestBody AuthorizationUser authorizationUser){
|
||||
public ResponseEntity login(@Validated @RequestBody AuthUser authorizationUser){
|
||||
|
||||
// 查询验证码
|
||||
String code = redisService.getCodeVal(authorizationUser.getUuid());
|
||||
|
@ -79,7 +79,7 @@ public class AuthenticationController {
|
|||
final String token = jwtTokenUtil.generateToken(jwtUser);
|
||||
|
||||
// 返回 token
|
||||
return ResponseEntity.ok(new AuthenticationInfo(token,jwtUser));
|
||||
return ResponseEntity.ok(new AuthInfo(token,jwtUser));
|
||||
}
|
||||
|
||||
@ApiOperation("获取用户信息")
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.io.Serializable;
|
|||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class AuthenticationInfo implements Serializable {
|
||||
public class AuthInfo implements Serializable {
|
||||
|
||||
private final String token;
|
||||
|
|
@ -11,7 +11,7 @@ import javax.validation.constraints.NotBlank;
|
|||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class AuthorizationUser {
|
||||
public class AuthUser {
|
||||
|
||||
@NotBlank
|
||||
private String username;
|
|
@ -7,7 +7,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
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.web.authentication.WebAuthenticationDetailsSource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
Loading…
Reference in New Issue