use of cn.hutool.http.useragent.UserAgent in project RuoYi-Flowable-Plus by KonBAI-Q.
the class UserActionListener method doLogin.
/**
* 每次登录时触发
*/
@Override
public void doLogin(String loginType, Object loginId, SaLoginModel loginModel) {
UserType userType = UserType.getUserType(loginId.toString());
if (userType == UserType.SYS_USER) {
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
String ip = ServletUtils.getClientIP();
LoginUser user = LoginHelper.getLoginUser();
String tokenValue = StpUtil.getTokenValueByLoginId(loginId);
UserOnlineDTO dto = new UserOnlineDTO();
dto.setIpaddr(ip);
dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
dto.setBrowser(userAgent.getBrowser().getName());
dto.setOs(userAgent.getOs().getName());
dto.setLoginTime(System.currentTimeMillis());
dto.setTokenId(tokenValue);
dto.setUserName(user.getUsername());
dto.setDeptName(user.getDeptName());
RedisUtils.setCacheObject(Constants.ONLINE_TOKEN_KEY + tokenValue, dto, tokenConfig.getTimeout(), TimeUnit.SECONDS);
log.info("user doLogin, useId:{}, token:{}", loginId, tokenValue);
} else if (userType == UserType.APP_USER) {
// app端 自行根据业务编写
}
}
use of cn.hutool.http.useragent.UserAgent in project ballcat by ballcat-projects.
the class LoginLogHandler method prodLoginLog.
/**
* 根据token和请求信息产生一个登陆日志
* @param source AbstractAuthenticationToken 当前token
* @return LoginLog 登陆日志
*/
private LoginLog prodLoginLog(AbstractAuthenticationToken source) {
// 获取 Request
HttpServletRequest request = LogUtils.getHttpServletRequest();
LoginLog loginLog = new LoginLog().setLoginTime(LocalDateTime.now()).setIp(IpUtils.getIpAddr(request)).setStatus(LogStatusEnum.SUCCESS.getValue()).setTraceId(MDC.get(LogConstant.TRACE_ID)).setUsername(source.getName());
// 根据 ua 获取浏览器和操作系统
UserAgent ua = UserAgentUtil.parse(request.getHeader("user-agent"));
if (ua != null) {
loginLog.setBrowser(ua.getBrowser().getName()).setOs(ua.getOs().getName());
}
return loginLog;
}
use of cn.hutool.http.useragent.UserAgent in project RuoYi-Vue-Plus by JavaLionLi.
the class UserActionListener method doLogin.
/**
* 每次登录时触发
*/
@Override
public void doLogin(String loginType, Object loginId, SaLoginModel loginModel) {
UserType userType = UserType.getUserType(loginId.toString());
if (userType == UserType.SYS_USER) {
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
String ip = ServletUtils.getClientIP();
LoginUser user = LoginHelper.getLoginUser();
String tokenValue = StpUtil.getTokenValueByLoginId(loginId);
UserOnlineDTO dto = new UserOnlineDTO();
dto.setIpaddr(ip);
dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
dto.setBrowser(userAgent.getBrowser().getName());
dto.setOs(userAgent.getOs().getName());
dto.setLoginTime(System.currentTimeMillis());
dto.setTokenId(tokenValue);
dto.setUserName(user.getUsername());
dto.setDeptName(user.getDeptName());
RedisUtils.setCacheObject(Constants.ONLINE_TOKEN_KEY + tokenValue, dto, tokenConfig.getTimeout(), TimeUnit.SECONDS);
log.info("user doLogin, useId:{}, token:{}", loginId, tokenValue);
} else if (userType == UserType.APP_USER) {
// app端 自行根据业务编写
}
}
use of cn.hutool.http.useragent.UserAgent in project albedo by somowhere.
the class LoginUtil method getUserOnline.
public static UserOnlineDo getUserOnline(Authentication authentication) {
UserOnlineDo online = new UserOnlineDo();
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
HttpSession session = request.getSession(false);
UserDetail user = SecurityUtil.getUser(authentication);
online.setSessionId(String.valueOf(session.getId()));
online.setDeptId(user.getDeptId());
online.setDeptName(user.getDeptName());
online.setUserId(user.getId());
online.setUsername(user.getUsername());
online.setStartTimestamp(LocalDateTimeUtil.of(session.getCreationTime()));
online.setLastAccessTime(LocalDateTimeUtil.of(session.getLastAccessedTime()));
online.setExpireTime((long) session.getMaxInactiveInterval());
online.setIpAddress(WebUtil.getIp(request));
online.setIpLocation(AddressUtil.getRegion(online.getIpAddress()));
online.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT));
UserAgent userAgent = UserAgentUtil.parse(online.getUserAgent());
online.setBrowser(userAgent.getBrowser().getName());
online.setOs(userAgent.getOs().getName());
return online;
}
use of cn.hutool.http.useragent.UserAgent in project albedo by somowhere.
the class SysLogUtils method getSysLogLogin.
public LogLoginDo getSysLogLogin() {
HttpServletRequest request = RequestHolder.getHttpServletRequest();
String userAgentStr = request.getHeader(HttpHeaders.USER_AGENT);
UserAgent userAgent = UserAgentUtil.parse(userAgentStr);
String tempIp = WebUtil.getIp(request);
return LogLoginDo.builder().ipAddress(tempIp).ipLocation(AddressUtil.getRegion(tempIp)).username(getUsername()).createdBy(getUserId()).createdDate(LocalDateTime.now()).loginDate(LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATE_FORMATTER)).userAgent(userAgentStr).browser(userAgent.getBrowser().getName()).os(userAgent.getOs().getName()).requestUri(URLUtil.getPath(request.getRequestURI())).build();
}
Aggregations