-
Notifications
You must be signed in to change notification settings - Fork 0
Add JavaDoc for IpFilter #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,23 @@ | |
| import java.nio.charset.StandardCharsets; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Global IP-based request filter. | ||
| * | ||
| * <p>The filter runs early in the request pipeline and determines whether a request | ||
| * should be allowed to continue based on the client's IP address.</p> | ||
| * | ||
| * <p>Decision rules:</p> | ||
| * <ul> | ||
| * <li>If an IP is present in the whitelist, it is allowed.</li> | ||
| * <li>If an IP is present in the blacklist, it is denied.</li> | ||
| * <li>If an IP is present in both lists, {@code allowByDefault} is used.</li> | ||
| * <li>If an IP is present in neither list, {@code allowByDefault} is used.</li> | ||
| * </ul> | ||
| * | ||
| * <p>The default constructor loads configuration from {@link IpFilterConfig}.</p> | ||
| */ | ||
| @Global(order = 2) | ||
| public class IpFilter implements Filter { | ||
|
|
||
|
|
@@ -17,6 +34,14 @@ public class IpFilter implements Filter { | |
|
|
||
| private final boolean allowByDefault; | ||
|
|
||
| /** | ||
| * Creates an {@code IpFilter} with explicit configuration. | ||
| * | ||
| * @param whitelist IP addresses that should be allowed (may be {@code null}) | ||
| * @param blacklist IP addresses that should be denied (may be {@code null}) | ||
| * @param allowByDefault fallback decision when an IP is not listed, or listed in both sets | ||
| */ | ||
|
|
||
| public IpFilter(Set<String> whitelist, Set<String> blacklist, boolean allowByDefault) { | ||
|
Comment on lines
+37
to
45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank lines between Javadoc blocks and their declarations detach the docs from generated output. Lines 44, 58, and 83 each introduce a blank line between the closing 📝 Proposed fix (shown for parameterized constructor; apply the same to the no-arg constructor and `isAllowed`) * `@param` allowByDefault fallback decision when an IP is not listed, or listed in both sets
*/
-
public IpFilter(Set<String> whitelist, Set<String> blacklist, boolean allowByDefault) {Also applies to: 55-59, 77-84 🤖 Prompt for AI Agents |
||
| if (whitelist != null) { | ||
| this.whitelist.addAll(whitelist); | ||
|
|
@@ -27,6 +52,10 @@ public IpFilter(Set<String> whitelist, Set<String> blacklist, boolean allowByDe | |
| this.allowByDefault = allowByDefault; | ||
| } | ||
|
|
||
| /** | ||
| * Creates an {@code IpFilter} using configuration loaded from {@link IpFilterConfig} | ||
| */ | ||
|
|
||
| public IpFilter() { | ||
| IpFilterConfig config = new IpFilterConfig(); | ||
| this.whitelist.addAll(config.whitelist()); | ||
|
|
@@ -45,8 +74,16 @@ public void doFilter(HttpRequest req, HttpResponse res, FilterChain chain) throw | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Evaluates whether the given IP address should be allowed. | ||
| * | ||
| * @param ip client IP address | ||
| * @return {@code true} if the request is allowed, {@code false} otherwise | ||
| */ | ||
|
|
||
| public boolean isAllowed(String ip) { | ||
|
|
||
| // If an IP exists in both lists, fall back to allowByDefault | ||
| if (whitelist.contains(ip) && blacklist.contains(ip)) return allowByDefault; | ||
|
|
||
| if (whitelist.contains(ip)) return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaDoc rule ordering does not match actual precedence in
isAllowed.The list implies whitelist unconditionally takes priority (rule 1), but
isAllowedchecks "in both" before the pure-whitelist check (line 87 vs. line 89). A developer reading only the Javadoc would expect that a whitelisted IP is always allowed, which is incorrect when the IP also appears in the blacklist. The "both lists" case should be listed first to reflect actual code precedence.📝 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents