Example usage for org.springframework.security.web.util.matcher IpAddressMatcher IpAddressMatcher

List of usage examples for org.springframework.security.web.util.matcher IpAddressMatcher IpAddressMatcher

Introduction

In this page you can find the example usage for org.springframework.security.web.util.matcher IpAddressMatcher IpAddressMatcher.

Prototype

public IpAddressMatcher(String ipAddress) 

Source Link

Document

Takes a specific IP address or a range specified using the IP/Netmask (e.g.

Usage

From source file:org.web4thejob.security.SecurityUtil.java

public static boolean hasIpAddress(String ipAddress, String remoteAddress) {
    return (new IpAddressMatcher(ipAddress).matches(remoteAddress));
}

From source file:org.duracloud.account.annotation.CIDRRangeValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    //may contain multiple values, semicolon separated.
    if (!StringUtils.isBlank(value)) {
        String[] values = value.split(";");
        for (String val : values) {
            try {
                new IpAddressMatcher(val);
            } catch (IllegalArgumentException ex) {
                return false;
            }/*from   w ww .j av a 2s  .c  om*/
        }
        return true;
    } else {
        return true;
    }
}

From source file:org.web4thejob.security.CustomELRequestMatcherContext.java

public boolean hasIpAddress(String ipAddress) {
    return (new IpAddressMatcher(ipAddress).matches(request));
}

From source file:org.duracloud.account.security.auth.AuthProvider.java

/**
 * Determines if a given IP address is in the given IP range.
 *
 * @param ipAddress single IP address// www  .  jav a  2  s . co  m
 * @param range IP address range using CIDR notation
 * @return true if the address is in the range, false otherwise
 */
protected boolean ipInRange(String ipAddress, String range) {
    IpAddressMatcher addressMatcher = new IpAddressMatcher(range);
    return addressMatcher.matches(ipAddress);
}

From source file:grails.plugin.springsecurity.web.filter.IpAddressFilter.java

protected boolean isAllowed(final HttpServletRequest request) {
    String ip = request.getRemoteAddr();
    if (allowLocalhost && (IPV4_LOOPBACK.equals(ip) || IPV6_LOOPBACK.equals(ip))) {
        return true;
    }/*from ww  w . j  av  a 2  s .  co  m*/

    String uri = (String) request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE);
    if (!StringUtils.hasLength(uri)) {
        uri = request.getRequestURI();
        if (!request.getContextPath().equals("/") && uri.startsWith(request.getContextPath())) {
            uri = uri.substring(request.getContextPath().length());
        }
    }

    List<InterceptedUrl> matching = findMatchingRules(uri);
    if (matching.isEmpty()) {
        return true;
    }

    for (InterceptedUrl iu : matching) {
        for (ConfigAttribute ipPattern : iu.getConfigAttributes()) {
            if (new IpAddressMatcher(ipPattern.getAttribute()).matches(request)) {
                return true;
            }
        }
    }

    log.warn("disallowed request {} from {}", new Object[] { uri, ip });
    return false;
}

From source file:org.geoserver.security.config.BruteForcePreventionConfig.java

public List<IpAddressMatcher> getWhitelistAddressMatchers() {
    try {/*w w w  . j av a 2s  . c  om*/
        if (this.getWhitelistedMasks() != null && this.whitelistedAddressMatchers == null) {
            this.whitelistedAddressMatchers = whitelistedMasks.stream().map(mask -> new IpAddressMatcher(mask))
                    .collect(Collectors.toList());
        }
    } catch (Exception e) {
        // an error here and no request can be made, best be cautious (yes, it actually
        // happened to me)
        LOGGER.log(Level.SEVERE, "Invalid netmask configuration, will skip it", e);
    }
    return this.whitelistedAddressMatchers;
}

From source file:org.wikimedia.analytics.refinery.core.IpUtil.java

/**
 * Constructs a IpUtil object with the default list of trusted proxies
 * <p>/*from ww  w .ja v a  2s .  co  m*/
 * The default list of trusted proxies is sourced from:
 * https://git.wikimedia.org/blob/operations%2Fpuppet.git/9f97e3c2c5bc012ba5c3751f13fd838a06d6528d/manifests%2Fnetwork.pp#L14
 */
public IpUtil() {
    trustedProxiesCache = new HashSet<IpAddressMatcher>();
    labsSubnetsCache = new HashSet<IpAddressMatcher>();

    for (String trustedProxy : trustedProxies) {
        IpAddressMatcher matcher = new IpAddressMatcher(trustedProxy);
        trustedProxiesCache.add(matcher);
    }

    for (String labsSubnet : labsSubnets) {
        IpAddressMatcher matcher = new IpAddressMatcher(labsSubnet);
        labsSubnetsCache.add(matcher);
    }
}