Java Code Examples for eu.bitwalker.useragentutils.UserAgent#parseUserAgentString()
The following examples show how to use
eu.bitwalker.useragentutils.UserAgent#parseUserAgentString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OnlineSessionFactory.java From supplierShop with MIT License | 6 votes |
@Override public Session createSession(SessionContext initData) { OnlineSession session = new OnlineSession(); if (initData != null && initData instanceof WebSessionContext) { WebSessionContext sessionContext = (WebSessionContext) initData; HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest(); if (request != null) { UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); // 获取客户端操作系统 String os = userAgent.getOperatingSystem().getName(); // 获取客户端浏览器 String browser = userAgent.getBrowser().getName(); session.setHost(IpUtils.getIpAddr(request)); session.setBrowser(browser); session.setOs(os); } } return session; }
Example 2
Source File: OnlineSessionFactory.java From RuoYi with Apache License 2.0 | 6 votes |
@Override public Session createSession(SessionContext initData) { OnlineSession session = new OnlineSession(); if (initData instanceof WebSessionContext) { WebSessionContext sessionContext = (WebSessionContext) initData; HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest(); if (request != null) { UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); // 获取客户端操作系统 String os = userAgent.getOperatingSystem().getName(); // 获取客户端浏览器 String browser = userAgent.getBrowser().getName(); session.setHost(IpUtils.getIpAddr(request)); session.setBrowser(browser); session.setOs(os); } } return session; }
Example 3
Source File: OnlineSessionFactory.java From LuckyFrameWeb with GNU Affero General Public License v3.0 | 6 votes |
@Override public Session createSession(SessionContext initData) { OnlineSession session = new OnlineSession(); if (initData instanceof WebSessionContext) { WebSessionContext sessionContext = (WebSessionContext) initData; HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest(); if (request != null) { UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); // 获取客户端操作系统 String os = userAgent.getOperatingSystem().getName(); // 获取客户端浏览器 String browser = userAgent.getBrowser().getName(); session.setHost(IpUtils.getIpAddr(request)); session.setBrowser(browser); session.setOs(os); } } return session; }
Example 4
Source File: WebLogAspect.java From SpringBoot-Home with Apache License 2.0 | 6 votes |
/** * 前置通知: * 1. 在执行目标方法之前执行,比如请求接口之前的登录验证; * 2. 在前置通知中设置请求日志信息,如开始时间,请求参数,注解内容等 * * @param joinPoint * @throws Throwable */ @Before("webLogPointcut()") public void doBefore(JoinPoint joinPoint) { // 接收到请求,记录请求内容 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); //获取请求头中的User-Agent UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); //打印请求的内容 startTime = System.currentTimeMillis(); log.info("请求开始时间:{}" , LocalDateTime.now()); log.info("请求Url : {}" , request.getRequestURL().toString()); log.info("请求方式 : {}" , request.getMethod()); log.info("请求ip : {}" , request.getRemoteAddr()); log.info("请求参数 : {}" , Arrays.toString(joinPoint.getArgs())); // 系统信息 log.info("浏览器:{}", userAgent.getBrowser().toString()); log.info("浏览器版本:{}", userAgent.getBrowserVersion()); log.info("操作系统: {}", userAgent.getOperatingSystem().toString()); }
Example 5
Source File: HttpContextUtils.java From plumemo with Apache License 2.0 | 5 votes |
/** * 获取发起请求的操作系统名称 */ public static String getOsName(HttpServletRequest request) { try{ String header = request.getHeader("User-Agent"); UserAgent userAgent = UserAgent.parseUserAgentString(header); OperatingSystem operatingSystem = userAgent.getOperatingSystem(); return operatingSystem.getName(); }catch (Exception e){ return "not found osName"; } }
Example 6
Source File: WebUtil.java From wenku with MIT License | 5 votes |
/** * 获取系统名称 * @param request 系统名称字符串 * @return */ public static String getOSName(HttpServletRequest request) { String userAgentStr = request.getHeader("User-Agent"); String result = "未知"; UserAgent userAgent = UserAgent.parseUserAgentString(userAgentStr); result = userAgent.getOperatingSystem().getName(); return result; }
Example 7
Source File: AsyncFactory.java From DimpleBlog with Apache License 2.0 | 5 votes |
/** * record visit log * * @param visitLog visitLog * @return timeTask */ public static TimerTask recordVisitLog(final VisitLog visitLog) { final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); final String spider = SpiderUtils.parseUserAgent(ServletUtils.getUserAgent()); return new TimerTask() { @Override public void run() { visitLog.setOs(userAgent.getOperatingSystem().getName()); visitLog.setSpider(spider); visitLog.setBrowser(userAgent.getBrowser().getName()); visitLog.setLocation(AddressUtils.getCityInfoByIp(visitLog.getIp())); SpringUtils.getBean(VisitLogService.class).insertVisitLog(visitLog); } }; }
Example 8
Source File: CommentServiceImpl.java From DimpleBlog with Apache License 2.0 | 5 votes |
@Override public int insertComment(Comment comment) { comment.setAdminReply(SecurityUtils.isAdmin()); final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); comment.setOs(userAgent.getOperatingSystem().getName()); comment.setBrowser(userAgent.getBrowser().getName()); comment.setIp(IpUtils.getIpAddr(ServletUtils.getRequest())); comment.setLocation(AddressUtils.getCityInfoByIp(comment.getIp())); return commentMapper.insertComment(comment); }
Example 9
Source File: RequestStatisticsFilter.java From microservices-platform with Apache License 2.0 | 5 votes |
@Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); Map<String, String> headers = request.getHeaders().toSingleValueMap(); UserAgent userAgent = UserAgent.parseUserAgentString(headers.get("User-Agent")); //埋点 PointUtil.debug("1", "request-statistics", "ip=" + ReactiveAddrUtil.getRemoteAddr(request) + "&browser=" + getBrowser(userAgent.getBrowser().name()) + "&operatingSystem=" + getOperatingSystem(userAgent.getOperatingSystem().name())); return chain.filter(exchange); }
Example 10
Source File: StringUtils.java From eladmin with Apache License 2.0 | 4 votes |
public static String getBrowser(HttpServletRequest request) { UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); Browser browser = userAgent.getBrowser(); return browser.getName(); }
Example 11
Source File: StringUtils.java From sk-admin with Apache License 2.0 | 4 votes |
public static String getBrowser(HttpServletRequest request) { UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); Browser browser = userAgent.getBrowser(); return browser.getName(); }
Example 12
Source File: RequestUtils.java From spring-boot-start-current with Apache License 2.0 | 4 votes |
/** * @return {@link eu.bitwalker.useragentutils.UserAgent} */ public static UserAgent getUserAgent () { return UserAgent.parseUserAgentString( getUserAgentHeader() ); }
Example 13
Source File: AsyncFactory.java From ruoyiplus with MIT License | 4 votes |
/** * 记录登陆信息 * * @param username 用户名 * @param status 状态 * @param message 消息 * @param args 列表 * @return 任务task */ public static TimerTask recordLogininfor(final String username, final String status, final String message, final Object... args) { final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); final String ip = ShiroUtils.getIp(); return new TimerTask() { @Override public void run() { StringBuilder s = new StringBuilder(); s.append(LogUtils.getBlock(ip)); s.append(AddressUtils.getRealAddressByIP(ip)); s.append(LogUtils.getBlock(username)); s.append(LogUtils.getBlock(status)); s.append(LogUtils.getBlock(message)); // 打印信息到日志 sys_user_logger.info(s.toString(), args); // 获取客户端操作系统 String os = userAgent.getOperatingSystem().getName(); // 获取客户端浏览器 String browser = userAgent.getBrowser().getName(); // 封装对象 SysLogininfor logininfor = new SysLogininfor(); logininfor.setLoginName(username); logininfor.setIpaddr(ip); logininfor.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); logininfor.setBrowser(browser); logininfor.setOs(os); logininfor.setMsg(message); // 日志状态 if (Constants.LOGIN_SUCCESS.equals(status) || Constants.LOGOUT.equals(status)) { logininfor.setStatus(Constants.SUCCESS); } else if (Constants.LOGIN_FAIL.equals(status)) { logininfor.setStatus(Constants.FAIL); } // 插入数据 SpringUtils.getBean(SysLogininforServiceImpl.class).insertLogininfor(logininfor); } }; }
Example 14
Source File: BrowserDetectionFilter.java From molgenis with GNU Lesser General Public License v3.0 | 4 votes |
protected boolean isSupported(String userAgentHeaderValue) { UserAgent userAgent = UserAgent.parseUserAgentString(userAgentHeaderValue); return !UNSUPPORTED_BROWSERS.contains(userAgent.getBrowser()); }
Example 15
Source File: LogAspect.java From paascloud-master with Apache License 2.0 | 4 votes |
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); } }
Example 16
Source File: LoginService.java From smart-admin with MIT License | 4 votes |
/** * 登陆 * * @param loginForm 登录名 密码 * @return 登录用户基本信息 */ public ResponseDTO<LoginDetailVO> login(@Valid EmployeeLoginFormDTO loginForm, HttpServletRequest request) { String redisVerificationCode = redisValueOperations.get(loginForm.getCodeUuid()); //增加删除已使用的验证码方式 频繁登录 redisValueOperations.getOperations().delete(loginForm.getCodeUuid()); if (StringUtils.isEmpty(redisVerificationCode)) { return ResponseDTO.wrap(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID); } if (!redisVerificationCode.equalsIgnoreCase(loginForm.getCode())) { return ResponseDTO.wrap(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID); } String loginPwd = SmartDigestUtil.encryptPassword(CommonConst.Password.SALT_FORMAT, loginForm.getLoginPwd()); EmployeeDTO employeeDTO = employeeDao.login(loginForm.getLoginName(), loginPwd); if (null == employeeDTO) { return ResponseDTO.wrap(EmployeeResponseCodeConst.LOGIN_FAILED); } if (EmployeeStatusEnum.DISABLED.equalsValue(employeeDTO.getIsDisabled())) { return ResponseDTO.wrap(EmployeeResponseCodeConst.IS_DISABLED); } //jwt token赋值 String compactJws = loginTokenService.generateToken(employeeDTO); LoginDetailVO loginDTO = SmartBeanUtil.copy(employeeDTO, LoginDetailVO.class); //获取前端功能权限 loginDTO.setPrivilegeList(initEmployeePrivilege(employeeDTO.getId())); loginDTO.setXAccessToken(compactJws); DepartmentEntity departmentEntity = departmentDao.selectById(employeeDTO.getDepartmentId()); loginDTO.setDepartmentName(departmentEntity.getName()); //判断是否为超管 Boolean isSuperman = privilegeEmployeeService.isSuperman(loginDTO.getId()); loginDTO.setIsSuperMan(isSuperman); //登陆操作日志 UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); UserLoginLogEntity logEntity = UserLoginLogEntity.builder() .userId(employeeDTO.getId()) .userName(employeeDTO.getActualName()) .remoteIp(SmartIPUtil.getRemoteIp(request)) .remotePort(request.getRemotePort()) .remoteBrowser(userAgent.getBrowser().getName()) .remoteOs(userAgent.getOperatingSystem().getName()) .loginStatus(JudgeEnum.YES.getValue()).build(); logService.addLog(logEntity); return ResponseDTO.succData(loginDTO); }
Example 17
Source File: UserAgentGetter.java From easyweb-shiro with MIT License | 4 votes |
public UserAgentGetter(HttpServletRequest request) { this.request = request; userAgentString = request.getHeader("User-Agent"); userAgent = UserAgent.parseUserAgentString(userAgentString); }
Example 18
Source File: UserController.java From Genesis with Apache License 2.0 | 4 votes |
/** * 用户登陆 * @param request * @param session * @return 0:用户名不存在 1:密码错误 2:登录成功 */ @RequestMapping("/api/loginCheck") @ResponseBody public Object signin(HttpServletRequest request,HttpSession session){ //处理参数 String password=ProduceMD5.getMD5(request.getParameter("password")); String username=request.getParameter("username"); //验证用户名密码 int loginVerify=userService.login(username,password); HashMap<String, String> res = new HashMap<String, String>(); //登录成功 if(loginVerify == 2){ User user =userService.getUserByUsername(username); Integer userId=user.getId(); //添加积分 boolean ifSuccAddCredit=userService.addCredit(1,userId); //用户信息写入session session.setAttribute("userId",userId); session.setAttribute("username",username); //获取登录信息 String ip=getRemortIP(request); UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); //获取用户的浏览器名 String userbrowser = userAgent.getBrowser().toString(); //写入登录日志 LoginLog log=new LoginLog(); log.setDevice(userbrowser); log.setIp(ip); log.setUserId(userId); log.setLoginTime(new Date()); boolean ifSuccAddLog=loginLogService.addLog(log); res.put("stateCode", "2"); } //密码错误 else if (loginVerify == 1){ res.put("stateCode", "1"); } //用户名不存在 else { res.put("stateCode", "0"); } return res; }
Example 19
Source File: RequestListener.java From Spring-Boot-Book with Apache License 2.0 | 4 votes |
@Override public void requestDestroyed(ServletRequestEvent arg0) { System.out.println("监听器初始化..."); Integer count = null;//请求数量 Object requestCount = arg0.getServletContext().getAttribute("requestCount"); if (requestCount == null) { count = 0; } else { count = Integer.valueOf(requestCount.toString()); } count++; System.out.println("当前请求数:" + count.toString()); arg0.getServletContext().setAttribute("requestCount", count); /*用户信息*/ /*用户信息*/ HttpServletRequest servletRequest = (HttpServletRequest) arg0.getServletRequest(); //requestURL String requestURL = servletRequest.getRequestURL().toString(); //queryString String queryString = servletRequest.getQueryString(); RequestLog requestLog = new RequestLog(); requestLog.setIpaddr(IpUtils.getIpAddr(servletRequest)); requestLog.setSessionId(servletRequest.getRequestedSessionId()); requestLog.setReferer(servletRequest.getHeader("Referer")); requestLog.setAccept(servletRequest.getHeader("accept")); requestLog.setMethod(servletRequest.getMethod()); requestLog.setUrl(requestURL); requestLog.setQuerystring(queryString); /*UserAgent 工具类*/ UserAgent userAgent = UserAgent.parseUserAgentString(servletRequest.getHeader("User-Agent")); Browser browser = userAgent.getBrowser(); Version version = browser.getVersion(servletRequest.getHeader("User-Agent")); String browserInfo = null; try { browserInfo = browser.getName() + "/" + version.getVersion(); } catch (Exception e) { e.printStackTrace(); } OperatingSystem os = userAgent.getOperatingSystem(); /*UserAgent 工具类*/ requestLog.setOs(os.getName()); requestLog.setBrowser(browserInfo); requestLog.setCreationTimes(System.currentTimeMillis()); /* SecurityContextImpl securityContextImpl = (SecurityContextImpl) servletRequest.getSession().getAttribute("SPRING_SECURITY_CONTEXT"); requestLog.setLoginName( securityContextImpl.getAuthentication().getName());*/ requestLogRepository.save(requestLog); }
Example 20
Source File: UserAgentUtils.java From MyShopPlus with Apache License 2.0 | 2 votes |
/** * 获取用户代理 * * @param request {@link HttpServletRequest} * @return {@link UserAgent} */ public static UserAgent getUserAgent(HttpServletRequest request) { return UserAgent.parseUserAgentString(request.getHeader("User-Agent")); }