Skip to content
Snippets Groups Projects
Commit c59a1bfd authored by Chad Leong's avatar Chad Leong :speech_balloon:
Browse files

Merge branch 'request-reject-handler' into 'master'

make request reject handler global

See merge request !468
parents 7f50dfdf e88b12c8
No related branches found
No related tags found
1 merge request!468make request reject handler global
Pipeline #218673 failed
package org.opengroup.osdu.partition.di;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.firewall.HttpStatusRequestRejectedHandler;
import org.springframework.security.web.firewall.RequestRejectedHandler;
@Configuration
public class BeanConfiguration {
@Bean
public RequestRejectedHandler requestRejectedHandler() {
return new HttpStatusRequestRejectedHandler();
}
}
......@@ -14,25 +14,24 @@
package org.opengroup.osdu.partition.middleware;
import java.util.ArrayList;
import java.util.List;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.gson.Gson;
import javassist.NotFoundException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.firewall.HttpStatusRequestRejectedHandler;
import org.springframework.security.web.firewall.RequestRejectedHandler;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
......@@ -40,11 +39,11 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import org.opengroup.osdu.core.common.model.http.AppException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;
import java.util.ArrayList;
import java.util.List;
@ControllerAdvice
@RestController
......
......@@ -7,13 +7,10 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.partition.middleware.GlobalExceptionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.web.firewall.HttpStatusRequestRejectedHandler;
import org.springframework.security.web.firewall.RequestRejectedHandler;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
......@@ -31,11 +28,6 @@ public class AzureExceptionMapper extends GlobalExceptionMapper {
@Autowired
private TelemetryClient telemetryClient;
@Bean
public RequestRejectedHandler requestRejectedHandler() {
return new HttpStatusRequestRejectedHandler();
}
@ExceptionHandler(HttpResponseException.class)
protected ResponseEntity<Object> handleHttpResponseException(HttpResponseException e) {
if (e.getResponse().getStatusCode() == HttpStatus.TOO_MANY_REQUESTS.value()) {
......
......@@ -99,7 +99,7 @@ public abstract class BaseTestTemplate extends TestBase {
@Test
public void should_return400_when_makingHttpRequestWithoutValidUrl() throws Exception {
CloseableHttpResponse response = descriptor.run("/", testUtils.getAccessToken());
CloseableHttpResponse response = descriptor.runWithInvalidPath(getId(), testUtils.getAccessToken());
assertEquals(error(EntityUtils.toString(response.getEntity())), 400, response.getCode());
}
}
......@@ -53,4 +53,9 @@ public abstract class RestDescriptor {
this.arg = arg;
return TestUtils.send(getPath(), getHttpMethod(), token, body, getQuery(), false);
}
public CloseableHttpResponse runWithInvalidPath(String arg, String token) throws Exception {
this.arg = arg;
return TestUtils.send(getPath() + "//", getHttpMethod(), token, getValidBody(), getQuery(), false);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment