Java Code Examples for eu.bitwalker.useragentutils.OperatingSystem

The following examples show how to use eu.bitwalker.useragentutils.OperatingSystem. These examples are extracted from open source projects. 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 Project: boubei-tss   Source File: URLUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static String parseBrowser(String useragent) {
 	useragent = (useragent + "").toLowerCase();
 	if(useragent.indexOf(browsers[0]) >= 0 && useragent.indexOf(browsers[1]) < 0) { // 微信客户端,注意区分QQ浏览器
 		return QQ_WX;
 	} 
 	
 	String origin = useragent;
 	try {
UserAgent userAgent = UserAgent.parseUserAgentString( useragent );
     	Browser browser = userAgent.getBrowser();
     	OperatingSystem opsys = userAgent.getOperatingSystem(); // 访问设备系统
     	Version browserVersion = userAgent.getBrowserVersion(); // 详细版本
         String version = browserVersion.getMajorVersion();      // 浏览器主版本
         
         origin = browser.getGroup().getName() + version + "-" + opsys;
         
     } catch(Exception e) { }
     	
 	for(String _b : browsers) {
 		if(useragent.indexOf(_b) >= 0) {
 			origin += "," + _b;
 			break;
 		}
 	}
     return origin.toLowerCase();
 }
 
Example 2
Source Project: uavstack   Source File: UEMServiceGFHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * getUA
 * 
 * @param fdata
 * @param request
 */
private void getUA(StringBuilder fdata, HttpServletRequest request) {

    UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));

    String bwrVersion = userAgent.getBrowserVersion().getMajorVersion();
    Browser bwr = userAgent.getBrowser();
    String bwrType = bwr.getBrowserType().getName();
    String bwrName = bwr.getName();
    String bwrEngine = bwr.getRenderingEngine().name();

    fdata.append(bwrName).append(";");
    fdata.append(bwrType).append(";");
    fdata.append(bwrEngine).append(";");
    fdata.append(bwrVersion).append(";");

    OperatingSystem os = userAgent.getOperatingSystem();

    String osName = os.getName();
    String deType = os.getDeviceType().getName();
    fdata.append(osName).append(";");
    fdata.append(deType).append(";");
}
 
Example 3
Source Project: kk-anti-reptile   Source File: UaRule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean doExecute(HttpServletRequest request, HttpServletResponse response) {
    AntiReptileProperties.UaRule uaRule = properties.getUaRule();
    UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
    OperatingSystem os = userAgent.getOperatingSystem();
    OperatingSystem osGroup = userAgent.getOperatingSystem().getGroup();
    DeviceType deviceType = userAgent.getOperatingSystem().getDeviceType();
    if (DeviceType.UNKNOWN.equals(deviceType)) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Unknown device, User-Agent: " + userAgent.toString());
        return true;
    } else if (OperatingSystem.UNKNOWN.equals(os)
            || OperatingSystem.UNKNOWN_MOBILE.equals(os)
            || OperatingSystem.UNKNOWN_TABLET.equals(os)) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Unknown OperatingSystem, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedLinux() && (OperatingSystem.LINUX.equals(osGroup) || OperatingSystem.LINUX.equals(os))) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Linux request, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedMobile() && (DeviceType.MOBILE.equals(deviceType) || DeviceType.TABLET.equals(deviceType))) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Mobile Device request, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedPc() && DeviceType.COMPUTER.equals(deviceType)) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed PC request, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedIot() && (DeviceType.DMR.equals(deviceType) || DeviceType.GAME_CONSOLE.equals(deviceType) || DeviceType.WEARABLE.equals(deviceType))) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Iot Device request, User-Agent: " + userAgent.toString());
        return true;
    }
    if (!uaRule.isAllowedProxy() && OperatingSystem.PROXY.equals(os)) {
        System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Proxy request, User-Agent: " + userAgent.toString());
        return true;
    }
    return false;
}
 
Example 4
Source Project: app-version   Source File: UserAgentUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static String getOS(String ua) {

        if (null == ua) return noDevice;
        UserAgent userAgent = UserAgent.parseUserAgentString(ua);
        OperatingSystem os = userAgent.getOperatingSystem();
        return os.toString();
    }
 
Example 5
Source Project: momo-cloud-permission   Source File: UserAgentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取os:Windows/ios/Android
 *
 * @param request
 * @return
 */
public static String getOs(String userAgent) {
    OperatingSystem operatingSystem = getOperatingSystem(userAgent);
    String os = operatingSystem.getGroup().getName();
    logger.info("os is:{}", os);
    return os;
}
 
Example 6
Source Project: momo-cloud-permission   Source File: UserAgentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取deviceType
 *
 * @param request
 * @return
 */
public static String getDevicetype(String userAgent) {
    OperatingSystem operatingSystem = getOperatingSystem(userAgent);
    String deviceType = operatingSystem.getDeviceType().toString();
    logger.info("deviceType is:{}", deviceType);
    return deviceType;
}
 
Example 7
Source Project: momo-cloud-permission   Source File: UserAgentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取操作系统的名字
 *
 * @param request
 * @return
 */
public static String getOsName(String userAgent) {
    OperatingSystem operatingSystem = getOperatingSystem(userAgent);
    String osName = operatingSystem.getName();
    logger.info("osName is:{}", osName);
    return osName;
}
 
Example 8
Source Project: momo-cloud-permission   Source File: UserAgentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取device的生产厂家
 *
 * @param request
 */
public static String getDeviceManufacturer(String userAgent) {
    OperatingSystem operatingSystem = getOperatingSystem(userAgent);
    String deviceManufacturer = operatingSystem.getManufacturer().toString();
    logger.info("deviceManufacturer is:{}", deviceManufacturer);
    return deviceManufacturer;
}
 
Example 9
Source Project: plumemo   Source File: HttpContextUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取发起请求的操作系统名称
 */
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 10
/**
 * 保存当前评论时的设备信息
 *
 * @param comment
 */
private void setCurrentDeviceInfo(Comment comment) {
    String ua = RequestUtil.getUa();
    UserAgent agent = UserAgent.parseUserAgentString(ua);
    Browser browser = agent.getBrowser();
    String browserInfo = browser.getName();
    Version version = agent.getBrowserVersion();
    if (version != null) {
        browserInfo += " " + version.getVersion();
    }
    comment.setBrowser(browserInfo);
    OperatingSystem os = agent.getOperatingSystem();
    comment.setOs(os.getName());
    comment.setIp(RequestUtil.getIp());
}
 
Example 11
Source Project: proctor   Source File: UserAgent.java    License: Apache License 2.0 5 votes vote down vote up
public boolean isSmartPhone() {
    OperatingSystem operatingSystemGroup = getOperatingSystem().getGroup();
    return isMobileDevice() &&
            (OperatingSystem.IOS.equals(operatingSystemGroup)
            || OperatingSystem.ANDROID.equals(operatingSystemGroup)
            || OperatingSystem.WINDOWS_MOBILE7.equals(getOperatingSystem()));
}
 
Example 12
Source Project: proctor   Source File: VersionedOS.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static VersionedOS fromUserAgent(@Nonnull final UserAgent agent) {
    final OperatingSystem os = agent.getOperatingSystem();
    final Version version = getVersion(agent);
    final int majorVersion = parseVersionNumberFrom(version.getMajorVersion());
    final int minorVersion = parseVersionNumberFrom(version.getMinorVersion());

    @Nonnull final String fullVersion = Strings.nullToEmpty(version.getVersion());
    return new VersionedOS(os, fullVersion, majorVersion, minorVersion);
}
 
Example 13
Source Project: Spring-Boot-Book   Source File: RequestListener.java    License: Apache License 2.0 4 votes vote down vote up
@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 14
Source Project: proctor   Source File: UserAgent.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public OperatingSystem getOperatingSystem() {
    return MoreObjects.firstNonNull(userAgent.getOperatingSystem(), OperatingSystem.UNKNOWN);
}
 
Example 15
Source Project: proctor   Source File: UserAgent.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isIOS() {
    final OperatingSystem operatingSystemGroup = getOperatingSystem().getGroup();

    return isMobileDevice() &&
            OperatingSystem.IOS.equals(operatingSystemGroup);
}
 
Example 16
Source Project: proctor   Source File: UserAgent.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isAndroid() {
    final OperatingSystem operatingSystemGroup = getOperatingSystem().getGroup();

    return OperatingSystem.ANDROID.equals(operatingSystemGroup);
}
 
Example 17
Source Project: proctor   Source File: UserAgent.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isWindowsPhone() {
    return OperatingSystem.WINDOWS_MOBILE7.equals(getOperatingSystem());
}
 
Example 18
Source Project: proctor   Source File: VersionedOS.java    License: Apache License 2.0 4 votes vote down vote up
private VersionedOS(@Nonnull final OperatingSystem os, @Nonnull final String version, int majorVersion, int minorVersion) {
    this.majorVersion = majorVersion;
    this.minorVersion = minorVersion;
    this.os = null == os.getGroup() ? os : os.getGroup();
    this.version = version;
}
 
Example 19
Source Project: momo-cloud-permission   Source File: UserAgentUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 获取操作系统对象
 *
 * @param request
 * @return
 */
private static OperatingSystem getOperatingSystem(String userAgent) {
    UserAgent agent = UserAgent.parseUserAgentString(userAgent);
    OperatingSystem operatingSystem = agent.getOperatingSystem();
    return operatingSystem;
}