Skip to content

Commit

Permalink
Rename DenyList to DenyRequest (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosbarbero authored Oct 26, 2020
1 parent aeb4e85 commit feee66b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
12 changes: 6 additions & 6 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -299,15 +299,15 @@ 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
|preFilterOrder |int |FilterConstants.FORM_BODY_WRAPPER_FILTER_ORDER

|===

Deny List properties
Deny Request properties

|===
|Property name| Values |Default Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Policy> getPolicies(String key) {
return policyList.getOrDefault(key, defaultPolicyList);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -110,9 +110,9 @@ protected List<Policy> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit feee66b

Please sign in to comment.