<commit_before>/*
 * Copyright (c) 2008-2016 Haulmont.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.haulmont.cuba.security.global;

import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class IpMatcher {

    private static Set<String> whiteListedIPs = ImmutableSet.of("127.0.0.1", "0:0:0:0:0:0:0:1");
    private List<String[]> masks = new ArrayList<>();

    private Logger log = LoggerFactory.getLogger(IpMatcher.class);

    public IpMatcher(String source) {
        String[] parts = source.split("[,;]");
        for (String part : parts) {
            String m = part.trim();
            String[] mask = ipv4(m);
            if (mask == null) {
                mask = ipv6(m);
                if (mask == null) {
                    log.warn("Invalid IP mask: '" + m + "'");
                    continue;
                }
            }
            masks.add(mask);
        }
    }

    public boolean match(String ip) {
        if (StringUtils.isBlank(ip) || whiteListedIPs.contains(ip)) {
            return true;
        }
        if (masks.isEmpty()) {
            return true;
        }

        String[] ipv = ipv4(ip);
        if (ipv == null) {
            ipv = ipv6(ip);
            if (ipv == null) {
                log.warn("IP format not supported: '" + ip + "'");
                return true;
            }
        }
<commit_msg>PL-9723 IpMatcher should use slf4j log syntax<commit_after>/*
 * Copyright (c) 2008-2016 Haulmont.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.haulmont.cuba.security.global;

import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class IpMatcher {

    private static final Set<String> whiteListedIPs = ImmutableSet.of("127.0.0.1", "0:0:0:0:0:0:0:1");
    private List<String[]> masks = new ArrayList<>();

    private final Logger log = LoggerFactory.getLogger(IpMatcher.class);

    public IpMatcher(String source) {
        String[] parts = source.split("[,;]");
        for (String part : parts) {
            String m = part.trim();
            String[] mask = ipv4(m);
            if (mask == null) {
                mask = ipv6(m);
                if (mask == null) {
                    log.warn("Invalid IP mask: '{}'", m);
                    continue;
                }
            }
            masks.add(mask);
        }
    }

    public boolean match(String ip) {
        if (StringUtils.isBlank(ip) || whiteListedIPs.contains(ip)) {
            return true;
        }
        if (masks.isEmpty()) {
            return true;
        }

        String[] ipv = ipv4(ip);
        if (ipv == null) {
            ipv = ipv6(ip);
            if (ipv == null) {
                log.warn("IP format not supported: '{}'", ip);
                return true;
            }
        }

{'fraction_non_alphanumeric': 0.11777456647398844, 'fraction_numerical': 0.016618497109826588, 'mean_word_length': 2.1509863429438543, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6615086', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1194, 'n_words': 364}