1212
1313public class ParsedFirewallLists {
1414 private final List <IPEntry > blockedIps = new ArrayList <>();
15+ private final List <IPEntry > monitoredIps = new ArrayList <>();
1516 private final List <IPEntry > allowedIps = new ArrayList <>();
1617 private final List <UADetailsEntry > uaDetails = new ArrayList <>();
1718 private Pattern blockedUserAgents = null ;
@@ -25,12 +26,23 @@ public List<Match> matchBlockedIps(String ip) {
2526 List <Match > matches = new ArrayList <>();
2627 for (IPEntry entry : this .blockedIps ) {
2728 if (entry .ips ().matches (ip )) {
28- matches .add (new Match (entry .key (), ! entry . monitor (), entry .description ()));
29+ matches .add (new Match (entry .key (), entry .description ()));
2930 }
3031 }
3132 return matches ;
3233 }
3334
35+ public List <Match > matchMonitoredIps (String ip ) {
36+ List <Match > matches = new ArrayList <>();
37+ for (IPEntry entry : this .monitoredIps ) {
38+ if (entry .ips ().matches (ip )) {
39+ matches .add (new Match (entry .key (), entry .description ()));
40+ }
41+ }
42+ return matches ;
43+ }
44+
45+
3446 // returns true if one or more matches has been found with allowlist.
3547 public boolean matchesAllowedIps (String ip ) {
3648 if (this .allowedIps .isEmpty ()) {
@@ -67,31 +79,30 @@ public UABlockedResult matchBlockedUserAgents(String userAgent) {
6779 }
6880
6981 public void update (ReportingApi .APIListsResponse response ) {
70- blockedIps .clear ();
7182 updateBlockedIps (response .blockedIPAddresses ());
7283 updateMonitoredIps (response .monitoredIPAddresses ());
73-
7484 updateAllowedIps (response .allowedIPAddresses ());
75-
7685 updateBlockedAndMonitoredUAs (response .blockedUserAgents (), response .monitoredUserAgents ());
7786 updateUADetails (response .userAgentDetails ());
7887 }
7988
8089 public void updateBlockedIps (List <ReportingApi .ListsResponseEntry > blockedIpLists ) {
90+ this .blockedIps .clear ();
8191 if (blockedIpLists == null )
8292 return ;
8393 for (ReportingApi .ListsResponseEntry entry : blockedIpLists ) {
8494 IPList ipList = createIPList (entry .ips ());
85- blockedIps .add (new IPEntry (/* monitor */ false , entry .key (), entry .source (), entry .description (), ipList ));
95+ this . blockedIps .add (new IPEntry (entry .key (), entry .source (), entry .description (), ipList ));
8696 }
8797 }
8898
8999 public void updateMonitoredIps (List <ReportingApi .ListsResponseEntry > monitoredIpsList ) {
100+ this .monitoredIps .clear ();
90101 if (monitoredIpsList == null )
91102 return ;
92103 for (ReportingApi .ListsResponseEntry entry : monitoredIpsList ) {
93104 IPList ipList = createIPList (entry .ips ());
94- blockedIps . add (new IPEntry (/* monitor */ true , entry .key (), entry .source (), entry .description (), ipList ));
105+ this . monitoredIps . add (new IPEntry (entry .key (), entry .source (), entry .description (), ipList ));
95106 }
96107 }
97108
@@ -101,8 +112,7 @@ public void updateAllowedIps(List<ReportingApi.ListsResponseEntry> allowedIpList
101112 return ;
102113 for (ReportingApi .ListsResponseEntry entry : allowedIpLists ) {
103114 IPList ipList = createIPList (entry .ips ());
104- boolean shouldMonitor = false ; // we don't monitor allowed ips
105- allowedIps .add (new IPEntry (shouldMonitor , entry .key (), entry .source (), entry .description (), ipList ));
115+ allowedIps .add (new IPEntry (entry .key (), entry .source (), entry .description (), ipList ));
106116 }
107117 }
108118
@@ -124,13 +134,13 @@ public void updateBlockedAndMonitoredUAs(String blockedUAs, String monitoredUAs)
124134 }
125135
126136
127- public record Match (String key , boolean block , String description ) {
137+ public record Match (String key , String description ) {
128138 }
129139
130140 public record UABlockedResult (boolean block , List <String > matchedKeys ) {
131141 }
132142
133- private record IPEntry (boolean monitor , String key , String source , String description , IPList ips ) {
143+ private record IPEntry (String key , String source , String description , IPList ips ) {
134144 }
135145
136146 private record UADetailsEntry (String key , Pattern pattern ) {
0 commit comments