From feee66b44d8726a1e1bfadb08b212c44efe7c578 Mon Sep 17 00:00:00 2001 From: Marcos Barbero Date: Mon, 26 Oct 2020 10:36:24 +0100 Subject: [PATCH] Rename DenyList to DenyRequest (#393) --- README.adoc | 12 ++++++------ .../config/properties/RateLimitProperties.java | 12 ++++++------ .../ratelimit/filters/AbstractRateLimitFilter.java | 10 +++++----- .../tests/it/SpringDataApplicationTestIT.java | 6 +++++- .../tests/it/SpringDataDenyOriginTestIT.java | 4 ++-- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.adoc b/README.adoc index 46002ec7..0ebd81e0 100644 --- a/README.adoc +++ b/README.adoc @@ -174,7 +174,7 @@ zuul: repository: REDIS behind-proxy: true add-response-headers: true - default-deny-list: + deny-request: response-status-code: 404 #default value is 403 (FORBIDDEN) origins: - 200.187.10.25 @@ -217,9 +217,9 @@ zuul.ratelimit.repository=REDIS zuul.ratelimit.behind-proxy=true zuul.ratelimit.add-response-headers=true -zuul.ratelimit.default-deny-list.response-status-code=404 -zuul.ratelimit.default-deny-list.origins[0]=200.187.10.25 -zuul.ratelimit.default-deny-list.origins[1]=somedomain.com +zuul.ratelimit.deny-request.response-status-code=404 +zuul.ratelimit.deny-request.origins[0]=200.187.10.25 +zuul.ratelimit.deny-request.origins[1]=somedomain.com zuul.ratelimit.default-policy-list[0].limit=10 zuul.ratelimit.default-policy-list[0].quota=1000 @@ -299,7 +299,7 @@ Property namespace: __zuul.ratelimit__ |response-headers |NONE, STANDARD, VERBOSE |VERBOSE |key-prefix |String |${spring.application.name:rate-limit-application} |repository |CONSUL, REDIS, JPA, BUCKET4J_JCACHE, BUCKET4J_HAZELCAST, BUCKET4J_INFINISPAN, BUCKET4J_IGNITE| - -|default-deny-list |List of link:./spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitProperties.java#L296[DenyList]| - +|deny-request |link:./spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitProperties.java#L296[DenyRequest]| - |default-policy-list |List of link:./spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitProperties.java#L190[Policy]| - |policy-list |Map of Lists of link:./spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitProperties.java#L82[Policy]| - |postFilterOrder |int |FilterConstants.SEND_RESPONSE_FILTER_ORDER - 10 @@ -307,7 +307,7 @@ Property namespace: __zuul.ratelimit__ |=== -Deny List properties +Deny Request properties |=== |Property name| Values |Default Value diff --git a/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitProperties.java b/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitProperties.java index ea7041c6..a04622a0 100644 --- a/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitProperties.java +++ b/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitProperties.java @@ -86,7 +86,7 @@ public class RateLimitProperties { private int preFilterOrder = FORM_BODY_WRAPPER_FILTER_ORDER; @NestedConfigurationProperty - private DenyList defaultDenyList = new DenyList(); + private DenyRequest denyRequest = new DenyRequest(); public List getPolicies(String key) { return policyList.getOrDefault(key, defaultPolicyList); @@ -179,12 +179,12 @@ public void setPreFilterOrder(int preFilterOrder) { this.preFilterOrder = preFilterOrder; } - public DenyList getDefaultDenyList() { - return defaultDenyList; + public DenyRequest getDenyRequest() { + return denyRequest; } - public void setDefaultDenyList(DenyList defaultDenyList) { - this.defaultDenyList = defaultDenyList; + public void setDenyRequest(DenyRequest denyRequest) { + this.denyRequest = denyRequest; } public static class Policy { @@ -293,7 +293,7 @@ public void setMatcher(String matcher) { } } - public static class DenyList { + public static class DenyRequest { /** * List of origins that will have the request denied. diff --git a/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/filters/AbstractRateLimitFilter.java b/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/filters/AbstractRateLimitFilter.java index 1782685d..8a819f62 100644 --- a/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/filters/AbstractRateLimitFilter.java +++ b/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/filters/AbstractRateLimitFilter.java @@ -65,8 +65,8 @@ public boolean shouldFilter() { return false; } - if (originIsOnDefaultDenyList(request)) { - int responseStatusCode = properties.getDefaultDenyList().getResponseStatusCode(); + if (originIsOnDenyRequest(request)) { + int responseStatusCode = properties.getDenyRequest().getResponseStatusCode(); ctx.setResponseStatusCode(responseStatusCode); ctx.setSendZuulResponse(false); @@ -110,9 +110,9 @@ protected List policy(Route route, HttpServletRequest request) { return policies; } - private boolean originIsOnDefaultDenyList(HttpServletRequest request) { - RateLimitProperties.DenyList denyList = properties.getDefaultDenyList(); - return denyList.getOrigins().stream() + private boolean originIsOnDenyRequest(HttpServletRequest request) { + RateLimitProperties.DenyRequest denyRequest = properties.getDenyRequest(); + return denyRequest.getOrigins().stream() .anyMatch(origin -> RateLimitType.ORIGIN.apply(request, null, rateLimitUtils, origin)); } diff --git a/spring-cloud-zuul-ratelimit-tests/springdata/src/test/java/com/marcosbarbero/tests/it/SpringDataApplicationTestIT.java b/spring-cloud-zuul-ratelimit-tests/springdata/src/test/java/com/marcosbarbero/tests/it/SpringDataApplicationTestIT.java index 66b2bf71..823b4ec4 100644 --- a/spring-cloud-zuul-ratelimit-tests/springdata/src/test/java/com/marcosbarbero/tests/it/SpringDataApplicationTestIT.java +++ b/spring-cloud-zuul-ratelimit-tests/springdata/src/test/java/com/marcosbarbero/tests/it/SpringDataApplicationTestIT.java @@ -24,7 +24,11 @@ * @author Marcos Barbero * @since 2017-06-27 */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { + // just making sure the test on SpringDataDenyOriginTestIT does not mess with the tests on this class + "zuul.ratelimit.deny-request.origins[0]=10.0.0.1" + }) public class SpringDataApplicationTestIT { @Autowired diff --git a/spring-cloud-zuul-ratelimit-tests/springdata/src/test/java/com/marcosbarbero/tests/it/SpringDataDenyOriginTestIT.java b/spring-cloud-zuul-ratelimit-tests/springdata/src/test/java/com/marcosbarbero/tests/it/SpringDataDenyOriginTestIT.java index 2797466b..c6ac5037 100644 --- a/spring-cloud-zuul-ratelimit-tests/springdata/src/test/java/com/marcosbarbero/tests/it/SpringDataDenyOriginTestIT.java +++ b/spring-cloud-zuul-ratelimit-tests/springdata/src/test/java/com/marcosbarbero/tests/it/SpringDataDenyOriginTestIT.java @@ -11,8 +11,8 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { - "zuul.ratelimit.default-deny-list.origins[0]=127.0.0.1", - "zuul.ratelimit.default-deny-list.response-status-code=404" + "zuul.ratelimit.deny-request.origins[0]=127.0.0.1", + "zuul.ratelimit.deny-request.response-status-code=404" } ) public class SpringDataDenyOriginTestIT {