1 package com.atlassian.security.auth.trustedapps;
2
3 import com.atlassian.ip.Subnet;
4
5 import java.util.Set;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public class AtlassianIPMatcher implements IPMatcher
23 {
24 private final com.atlassian.ip.IPMatcher ipMatcher;
25
26
27
28
29
30
31
32 public AtlassianIPMatcher(final Set<String> patterns) throws IPAddressFormatException
33 {
34 if (!patterns.isEmpty()) {
35 final com.atlassian.ip.IPMatcher.Builder builder = com.atlassian.ip.IPMatcher.builder();
36 for (final String patternStr : patterns)
37 {
38 builder.addPattern(patternStr);
39 }
40 ipMatcher = builder.build();
41 }
42 else
43 {
44 ipMatcher = null;
45 }
46 }
47
48 public boolean match(final String ipAddress)
49 {
50
51 return ipMatcher == null || ipMatcher.matches(ipAddress);
52 }
53
54 public static void parsePatternString(String pattern) throws IPAddressFormatException
55 {
56 if (!Subnet.isValidPattern(pattern))
57 {
58 throw new IPAddressFormatException(pattern);
59 }
60 }
61 }