Skip to content

Commit

Permalink
#590 Remove Rate-Limit Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
svenkubiak committed Aug 23, 2021
1 parent f902d9b commit 1d434f1
Show file tree
Hide file tree
Showing 15 changed files with 13 additions and 511 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ public Response routes() {
json.put("limit", route.getLimit());
json.put("basicAuthentication", route.hasBasicAuthentication());
json.put("authentication", route.hasAuthentication());
json.put("authorization", route.hasAuthorization());
json.put("blocking", route.isBlocking());
routes.add(json);
});
Expand Down
6 changes: 0 additions & 6 deletions mangooio-core/src/main/java/io/mangoo/core/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,6 @@ private static void prepareRoutes() {
LOG.error("Could not find controller method '{}' in controller class '{}'", requestRoute.getControllerMethod(), requestRoute.getControllerClass());
failsafe();
}

if (requestRoute.hasAuthorization() && (!MangooUtils.resourceExists(Default.MODEL_CONF.toString()) || !MangooUtils.resourceExists(Default.POLICY_CSV.toString()))) {
LOG.error("Route on method '{}' in controller class '{}' requires authorization, but either model.conf or policy.csv is missing", requestRoute.getControllerMethod(), requestRoute.getControllerClass());
failsafe();
}
});
}

Expand Down Expand Up @@ -496,7 +491,6 @@ private static RoutingHandler getRoutingHandler() {
.withMaxEntitySize(requestRoute.getMaxEntitySize())
.withBasicAuthentication(requestRoute.getUsername(), requestRoute.getPassword())
.withAuthentication(requestRoute.hasAuthentication())
.withAuthorization(requestRoute.hasAuthorization())
.withLimit(requestRoute.getLimit());

routingHandler.add(requestRoute.getMethod().toString(), requestRoute.getUrl(), dispatcherHandler);
Expand Down
16 changes: 0 additions & 16 deletions mangooio-core/src/main/java/io/mangoo/routing/Attachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import java.util.Map;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

import io.mangoo.enums.Required;
import io.mangoo.i18n.Messages;
import io.mangoo.routing.bindings.Authentication;
Expand Down Expand Up @@ -52,7 +50,6 @@ public class Attachment {
private int methodParametersCount;
private boolean requestFilter;
private boolean requiresAuthentication;
private boolean requiresAuthorization;

public static Attachment build() {
return new Attachment();
Expand Down Expand Up @@ -161,10 +158,6 @@ public String getUsername() {
public boolean hasAuthentication() {
return this.requiresAuthentication;
}

public boolean hasBasicAuthentication() {
return StringUtils.isNotBlank(this.username) && StringUtils.isNotBlank(this.password);
}

public boolean hasLimit() {
return this.limit > 0;
Expand Down Expand Up @@ -288,13 +281,4 @@ public Attachment withAuthentication(boolean authentication) {
this.requiresAuthentication = authentication;
return this;
}

public Attachment withAuthorization(boolean authorization) {
this.requiresAuthorization = authorization;
return this;
}

public boolean hasAuthorization() {
return this.requiresAuthorization;
}
}
245 changes: 0 additions & 245 deletions mangooio-core/src/main/java/io/mangoo/routing/bindings/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,45 +76,6 @@ public void expectValue(String name, String message) {
}
}

/**
* Validates a given field to have a minimum length
*
* @deprecated
* Use {@link #expectMinValue(String, double)} or {@link #expectMinLength(String, double)} instead
*
* @param name The field to check
* @param minLength The minimum length
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void expectMin(String name, double minLength) {
expectMin(name, minLength, null);
}

/**
* Validates a given field to have a minimum length
*
* @deprecated
* Use {@link #expectMinValue(String, double, String)} or {@link #expectMinLength(String, double, String)} instead
*
* @param name The field to check
* @param minLength The minimum length
* @param message A custom error message instead of the default one
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void expectMin(String name, double minLength, String message) {
String value = Optional.ofNullable(get(name)).orElse("");

if (StringUtils.isNumeric(value)) {
if (Double.parseDouble(value) < minLength) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.MIN_KEY.toString(), name, minLength)));
}
} else {
if (value.length() < minLength) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.MIN_KEY.toString(), name, minLength)));
}
}
}

/**
* Validates a given field to have a minimum value
*
Expand Down Expand Up @@ -168,20 +129,6 @@ public void expectMinLength(String name, double minLength, String message) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.MIN_LENGTH_KEY.toString(), name, minLength)));
}
}

/**
* Validates a given field to have a maximum length
*
* @deprecated
* Use {@link #expectMaxLength(String, double)} or {@link #expectMaxValue(String, double)} instead
*
* @param maxLength The maximum length
* @param name The field to check
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void expectMax(String name, double maxLength) {
expectMax(name, maxLength, null);
}

/**
* Validates a given field to have a maximum value
Expand Down Expand Up @@ -227,31 +174,6 @@ public void expectNumeric(String name, String message) {
}
}

/**
* Validates a given field to have a maximum length
*
* @deprecated
* Use {@link #expectMaxLength(String, double, String)} or {@link #expectMaxValue(String, double, String)} instead
*
* @param name The field to check
* @param maxLength The maximum length
* @param message A custom error message instead of the default one
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void expectMax(String name, double maxLength, String message) {
String value = Optional.ofNullable(get(name)).orElse("");

if (StringUtils.isNumeric(value)) {
if (Double.parseDouble(value) > maxLength) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.MAX_KEY.toString(), name, maxLength)));
}
} else {
if (value.length() > maxLength) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.MAX_KEY.toString(), name, maxLength)));
}
}
}

/**
* Validates a given field to have a maximum length
*
Expand Down Expand Up @@ -454,21 +376,6 @@ public void expectIpv6(String name, String message) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.IPV6_KEY.toString(), name)));
}
}

/**
* Validates a field to be in a certain range
*
* @deprecated
* Use {@link #expectRangeLength(String, int, int)} or {@link #expectRangeValue(String, int, int)} instead
*
* @param name The field to check
* @param minLength The minimum length
* @param maxLength The maximum length
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void expectRange(String name, int minLength, int maxLength) {
expectRange(name, minLength, maxLength, null);
}

/**
* Validates a field to be in a certain range length
Expand Down Expand Up @@ -528,33 +435,6 @@ public void expectRangeLength(String name, int minLength, int maxLength, String
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.RANGE_LENGTH_KEY.toString(), name, minLength, maxLength)));
}
}

/**
* Validates a field to be in a certain range
*
* @deprecated
* Use {@link #expectRangeLength(String, int, int, String)} or {@link #expectRangeValue(String, int, int, String)} instead
*
* @param name The field to check
* @param minLength The minimum length
* @param maxLength The maximum length
* @param message A custom error message instead of the default one
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void expectRange(String name, int minLength, int maxLength, String message) {
String value = Optional.ofNullable(get(name)).orElse("");

if (StringUtils.isNumeric(value)) {
double doubleValue = Double.parseDouble(value);
if (doubleValue < minLength || doubleValue > maxLength) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.RANGE_KEY.toString(), name, minLength, maxLength)));
}
} else {
if (value.length() < minLength || value.length() > maxLength) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.RANGE_KEY.toString(), name, minLength, maxLength)));
}
}
}

/**
* Validates a field by a given regular expression pattern
Expand Down Expand Up @@ -609,131 +489,6 @@ public void expectUrl(String name, String message) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.URL_KEY.toString(), name)));
}
}

/**
* Validates a given value to be true
*
* @deprecated
* Use {@link #expectTrue(String, boolean, String)} instead
*
* @param value The value to check
* @param name The name of the field to display the error message
* @param message A custom error message instead of the default one
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void validateTrue(boolean value, String name, String message) {
if (!value) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.TRUE_KEY.toString(), name)));
}
}

/**
* Validates a given value to be true
*
* @deprecated
* Use {@link #expectTrue(String, boolean)} instead
*
* @param value The value to check
* @param name The name of the field to display the error message
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void validateTrue(boolean value, String name) {
validateTrue(value, name, null);
}

/**
* Validates a given value to be false
*
* @deprecated
* Use {@link #expectFalse(String, boolean, String)} instead
*
* @param value The value to check
* @param name The name of the field to display the error message
* @param message A custom error message instead of the default one
*/
@SuppressWarnings("all")
@Deprecated(since = "6.7.0", forRemoval = true)
public void validateFalse(boolean value, String name, String message) {
if (value) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.FALSE_KEY.toString(), name)));
}
}

/**
* Validates a given value to be false
*
* @deprecated
* Use {@link #expectFalse(String, boolean)} instead
*
* @param value The value to check
* @param name The name of the field to display the error message
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void validateFalse(boolean value, String name) {
validateFalse(value, name, null);
}

/**
* Validates a given object to be not null
*
* @deprecated
* Use {@link #expectNotNull(String, Object, String)} instead
*
* @param object The object to check
* @param name The name of the field to display the error message
* @param message A custom error message instead of the default one
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void validateNotNull(Object object, String name, String message) {
if (object == null) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.NOTNULL_KEY.toString(), name)));
}
}

/**
* Validates a given object to be not null
*
* @deprecated
* Use {@link #expectNotNull(String, Object)} instead
*
* @param object The object to check
* @param name The name of the field to display the error message
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void validateNotNull(Object object, String name) {
validateNotNull(object, name, null);
}

/**
* Validates a given object to be null
*
* @deprecated
* Use {@link #expectNull(String, Object, String)} instead
*
* @param object The object to check
* @param name The name of the field to display the error message
* @param message A custom error message instead of the default one
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void validateNull(Object object, String name, String message) {
if (object != null) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.NULL_KEY.toString(), name)));
}
}

/**
* Validates a given object to be null
*
* @deprecated
* Use {@link #expectNull(String, Object)} instead
*
* @param object The object to check
* @param name The name of the field to display the error message
*/
@Deprecated(since = "6.7.0", forRemoval = true)
public void validateNull(Object object, String name) {
validateNull(object, name, null);
}

/**
* Validates a given value to be true
Expand Down
Loading

0 comments on commit 1d434f1

Please sign in to comment.