use of eu.bitwalker.useragentutils.UserAgent in project paascloud-master by paascloud.
the class LogAspect method handleLog.
private void handleLog(final JoinPoint joinPoint, final Object result) {
final Date startTime = this.threadLocal.get();
final Date endTime = new Date(System.currentTimeMillis());
HttpServletRequest request = RequestUtil.getRequest();
final UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
String requestURI = request.getRequestURI();
try {
LogAnnotation relog = giveController(joinPoint);
LoginAuthDto loginUser = RequestUtil.getLoginUser();
if (relog == null) {
return;
}
// 获取客户端操作系统
final String os = userAgent.getOperatingSystem().getName();
// 获取客户端浏览器
final String browser = userAgent.getBrowser().getName();
final String ipAddress = RequestUtil.getRemoteAddr(request);
OperationLogDto operationLogDto = new OperationLogDto();
operationLogDto.setClassName(joinPoint.getTarget().getClass().getName());
operationLogDto.setMethodName(joinPoint.getSignature().getName());
operationLogDto.setExcuteTime(endTime.getTime() - startTime.getTime());
operationLogDto.setStartTime(startTime);
operationLogDto.setEndTime(endTime);
operationLogDto.setIp(ipAddress);
operationLogDto.setOs(os);
operationLogDto.setBrowser(browser);
operationLogDto.setRequestUrl(requestURI);
operationLogDto.setGroupId(loginUser.getGroupId());
operationLogDto.setGroupName(loginUser.getGroupName());
operationLogDto.setCreatedTime(new Date());
operationLogDto.setCreator(loginUser.getUserName());
operationLogDto.setCreatorId(loginUser.getUserId());
operationLogDto.setLastOperator(loginUser.getUserName());
operationLogDto.setLastOperatorId(loginUser.getUserId());
operationLogDto.setLogType(relog.logType().getType());
operationLogDto.setLogName(relog.logType().getName());
getControllerMethodDescription(relog, operationLogDto, result, joinPoint);
threadLocal.remove();
taskExecutor.execute(() -> this.restTemplate.postForObject("http://paascloud-provider-uac/auth/saveLog", operationLogDto, Integer.class));
} catch (Exception ex) {
log.error("获取注解类出现异常={}", ex.getMessage(), ex);
}
}
use of eu.bitwalker.useragentutils.UserAgent in project paascloud-master by paascloud.
the class UacUserTokenServiceImpl method saveUserToken.
@Override
public void saveUserToken(String accessToken, String refreshToken, LoginAuthDto loginAuthDto, HttpServletRequest request) {
// 获取登录时间
Long userId = loginAuthDto.getUserId();
UacUser uacUser = uacUserService.selectByKey(userId);
final UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
// 获取客户端操作系统
final String os = userAgent.getOperatingSystem().getName();
// 获取客户端浏览器
final String browser = userAgent.getBrowser().getName();
final String remoteAddr = RequestUtil.getRemoteAddr(request);
// 根据IP获取位置信息
final String remoteLocation = opcRpcService.getLocationById(remoteAddr);
// 存入mysql数据库
UacUserToken uacUserToken = new UacUserToken();
OAuth2ClientProperties[] clients = securityProperties.getOauth2().getClients();
int accessTokenValidateSeconds = clients[0].getAccessTokenValidateSeconds();
int refreshTokenValiditySeconds = clients[0].getRefreshTokenValiditySeconds();
uacUserToken.setOs(os);
uacUserToken.setBrowser(browser);
uacUserToken.setAccessToken(accessToken);
uacUserToken.setAccessTokenValidity(accessTokenValidateSeconds);
uacUserToken.setLoginIp(remoteAddr);
uacUserToken.setLoginLocation(remoteLocation);
uacUserToken.setLoginTime(uacUser.getLastLoginTime());
uacUserToken.setLoginName(loginAuthDto.getLoginName());
uacUserToken.setRefreshToken(refreshToken);
uacUserToken.setRefreshTokenValidity(refreshTokenValiditySeconds);
uacUserToken.setStatus(UacUserTokenStatusEnum.ON_LINE.getStatus());
uacUserToken.setUserId(userId);
uacUserToken.setUserName(loginAuthDto.getUserName());
uacUserToken.setUpdateInfo(loginAuthDto);
uacUserToken.setGroupId(loginAuthDto.getGroupId());
uacUserToken.setGroupName(loginAuthDto.getGroupName());
uacUserToken.setId(generateId());
uacUserTokenMapper.insertSelective(uacUserToken);
UserTokenDto userTokenDto = new ModelMapper().map(uacUserToken, UserTokenDto.class);
// 存入redis数据库
updateRedisUserToken(accessToken, accessTokenValidateSeconds, userTokenDto);
}
use of eu.bitwalker.useragentutils.UserAgent in project paascloud-master by paascloud.
the class UacUserServiceImpl method handlerLoginData.
@Override
public void handlerLoginData(OAuth2AccessToken token, final SecurityUser principal, HttpServletRequest request) {
final UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
// 获取客户端操作系统
final String os = userAgent.getOperatingSystem().getName();
// 获取客户端浏览器
final String browser = userAgent.getBrowser().getName();
final String remoteAddr = RequestUtil.getRemoteAddr(request);
// 根据IP获取位置信息
final String remoteLocation = opcRpcService.getLocationById(remoteAddr);
final String requestURI = request.getRequestURI();
UacUser uacUser = new UacUser();
Long userId = principal.getUserId();
uacUser.setLastLoginIp(remoteAddr);
uacUser.setId(userId);
uacUser.setLastLoginTime(new Date());
uacUser.setLastLoginLocation(remoteLocation);
LoginAuthDto loginAuthDto = new LoginAuthDto(userId, principal.getLoginName(), principal.getNickName(), principal.getGroupId(), principal.getGroupName());
// 记录token日志
String accessToken = token.getValue();
String refreshToken = token.getRefreshToken().getValue();
uacUserTokenService.saveUserToken(accessToken, refreshToken, loginAuthDto, request);
// 记录最后登录信息
taskExecutor.execute(() -> this.updateUser(uacUser));
// 记录操作日志
UacLog log = new UacLog();
log.setGroupId(principal.getGroupId());
log.setGroupName(principal.getGroupName());
log.setIp(remoteAddr);
log.setLocation(remoteLocation);
log.setOs(os);
log.setBrowser(browser);
log.setRequestUrl(requestURI);
log.setLogType(LogTypeEnum.LOGIN_LOG.getType());
log.setLogName(LogTypeEnum.LOGIN_LOG.getName());
taskExecutor.execute(() -> uacLogService.saveLog(log, loginAuthDto));
}
Aggregations