All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dspace.statistics.util.SpiderDetector Maven / Gradle / Ivy

The newest version!
/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */
package org.dspace.statistics.util;

import java.io.File;
import java.io.IOException;
import java.util.Set;

import jakarta.servlet.http.HttpServletRequest;
import org.dspace.statistics.factory.StatisticsServiceFactory;

/**
 * SpiderDetector delegates static methods to SpiderDetectorService,
 * which is used to find IPs, hosts, or agents that are spiders...
 *
 * @author kevinvandevelde at atmire.com
 * @author ben at atmire.com
 * @author Mark Diggory (mdiggory at atmire.com)
 * @author frederic at atmire.com
 */
public class SpiderDetector {
    //Service where all methods get delegated to.  This is instantiated by a
    // Spring bean defined in core-services.xml
    private static final SpiderDetectorService spiderDetectorService
            = StatisticsServiceFactory.getInstance().getSpiderDetectorService();

    /**
     * Default constructor
     */
    private SpiderDetector() { }

    /**
     * Utility method which reads lines from a file & returns them in a Set.
     *
     * @param patternFile the location of our spider file
     * @return a vector full of patterns
     * @throws IOException could not happen since we check the file be4 we use it
     */
    public static Set readPatterns(File patternFile)
        throws IOException {
        return spiderDetectorService.readPatterns(patternFile);
    }

    /**
     * Static Service Method for testing spiders against existing spider files.
     * 

* In future spiders HashSet may be optimized as byte offset array to * improve performance and memory footprint further. * * @param clientIP address of the client. * @param proxyIPs comma-list of X-Forwarded-For addresses, or null. * @param hostname domain name of host, or null. * @param agent User-Agent header value, or null. * @return true if the client matches any spider characteristics list. */ public static boolean isSpider(String clientIP, String proxyIPs, String hostname, String agent) { return spiderDetectorService.isSpider(clientIP, proxyIPs, hostname, agent); } /** * Static Service Method for testing spiders against existing spider files. * * @param request * @return true|false if the request was detected to be from a spider. */ public static boolean isSpider(HttpServletRequest request) { return spiderDetectorService.isSpider(request); } /** * Check individual IP is a spider. * * @param ip * @return if is spider IP */ public static boolean isSpider(String ip) { return spiderDetectorService.isSpider(ip); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy