eu.bitwalker.useragentutils.DeviceType Java Examples

The following examples show how to use eu.bitwalker.useragentutils.DeviceType. 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: UaRule.java    From kk-anti-reptile with 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 #2
Source File: UserAgent.java    From proctor with Apache License 2.0 4 votes vote down vote up
/**
 * Determines whether user agent is a tablet
 * @return true if tablet
 */
public boolean isTablet() {
    return DeviceType.TABLET.equals(getDeviceType()) ||
            userAgentString.contains(NEXUS_7_SIGNATURE) ||
            userAgentString.contains(KINDLE_FIRE_SIGNATURE);
}
 
Example #3
Source File: UserAgent.java    From proctor with Apache License 2.0 4 votes vote down vote up
@Nonnull
public DeviceType getDeviceType() {
    return MoreObjects.firstNonNull(getOperatingSystem().getDeviceType(), DeviceType.UNKNOWN);
}
 
Example #4
Source File: UserAgentUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static DeviceType getRequestDeviceType(HttpServletRequest request){
	UserAgent userAgent = getUserAgent(request);
	return userAgent.getOperatingSystem().getDeviceType();
}
 
Example #5
Source File: UserAgentUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static DeviceType getRequestDeviceType(){
	UserAgent userAgent = getUserAgent();
	return userAgent.getOperatingSystem().getDeviceType();
}
 
Example #6
Source File: UserAgentUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static boolean isMobileRequest(HttpServletRequest request){
	return DeviceType.MOBILE.equals(getRequestDeviceType(request));
}
 
Example #7
Source File: UserAgentUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static boolean isMobileRequest(){
	return DeviceType.MOBILE.equals(getRequestDeviceType());
}
 
Example #8
Source File: UserAgentUtils.java    From Shop-for-JavaWeb with MIT License 2 votes vote down vote up
/**
 * 是否是手机
 * @param request
 * @return
 */
public static boolean isMobile(HttpServletRequest request){
	return DeviceType.MOBILE.equals(getDeviceType(request));
}
 
Example #9
Source File: UserAgentUtils.java    From Shop-for-JavaWeb with MIT License 2 votes vote down vote up
/**
 * 是否是手机和平板
 * @param request
 * @return
 */
public static boolean isMobileOrTablet(HttpServletRequest request){
	DeviceType deviceType = getDeviceType(request);
	return DeviceType.MOBILE.equals(deviceType) || DeviceType.TABLET.equals(deviceType);
}
 
Example #10
Source File: UserAgentUtils.java    From Shop-for-JavaWeb with MIT License 2 votes vote down vote up
/**
 * 是否是平板
 * @param request
 * @return
 */
public static boolean isTablet(HttpServletRequest request){
	return DeviceType.TABLET.equals(getDeviceType(request));
}
 
Example #11
Source File: UserAgentUtils.java    From Shop-for-JavaWeb with MIT License 2 votes vote down vote up
/**
 * 是否是PC
 * @param request
 * @return
 */
public static boolean isComputer(HttpServletRequest request){
	return DeviceType.COMPUTER.equals(getDeviceType(request));
}
 
Example #12
Source File: UserAgentUtils.java    From Shop-for-JavaWeb with MIT License 2 votes vote down vote up
/**
 * 获取设备类型
 * @param request
 * @return
 */
public static DeviceType getDeviceType(HttpServletRequest request){
	return getUserAgent(request).getOperatingSystem().getDeviceType();
}
 
Example #13
Source File: UserAgentUtils.java    From frpMgr with MIT License 2 votes vote down vote up
/**
 * 是否是手机和平板
 * @param request
 * @return
 */
public static boolean isMobileOrTablet(HttpServletRequest request){
	DeviceType deviceType = getDeviceType(request);
	return DeviceType.MOBILE.equals(deviceType) || DeviceType.TABLET.equals(deviceType);
}
 
Example #14
Source File: UserAgentUtils.java    From frpMgr with MIT License 2 votes vote down vote up
/**
 * 是否是平板
 * @param request
 * @return
 */
public static boolean isTablet(HttpServletRequest request){
	return DeviceType.TABLET.equals(getDeviceType(request));
}
 
Example #15
Source File: UserAgentUtils.java    From frpMgr with MIT License 2 votes vote down vote up
/**
 * 是否是手机
 * @param request
 * @return
 */
public static boolean isMobile(HttpServletRequest request){
	return DeviceType.MOBILE.equals(getDeviceType(request));
}
 
Example #16
Source File: UserAgentUtils.java    From frpMgr with MIT License 2 votes vote down vote up
/**
 * 是否是PC
 * @param request
 * @return
 */
public static boolean isComputer(HttpServletRequest request){
	return DeviceType.COMPUTER.equals(getDeviceType(request));
}
 
Example #17
Source File: UserAgentUtils.java    From frpMgr with MIT License 2 votes vote down vote up
/**
 * 获取设备类型
 * @param request
 * @return
 */
public static DeviceType getDeviceType(HttpServletRequest request){
	return getUserAgent(request).getOperatingSystem().getDeviceType();
}