Added rate limiting through application.properties file to the /owners/find endpoint

This commit is contained in:
AndreiDombrovschi 2025-06-18 11:12:15 +03:00
parent f9399b7a9f
commit 1291e38731
3 changed files with 15 additions and 2 deletions

View file

@ -35,6 +35,7 @@ import org.springframework.web.servlet.ModelAndView;
import jakarta.validation.Valid;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.samples.petclinic.system.RateLimitInterceptor.*;
/**
* @author Juergen Hoeller

View file

@ -24,8 +24,14 @@ import java.util.Locale;
@SuppressWarnings("unused")
public class WebConfiguration implements WebMvcConfigurer {
private final RateLimitInterceptor rateLimitInterceptor;
public WebConfiguration(RateLimitInterceptor rateLimitInterceptor) {
this.rateLimitInterceptor = rateLimitInterceptor;
}
/**
* Uses session storage to remember the users language setting across requests.
* Uses session storage to remember the user's language setting across requests.
* Defaults to English if nothing is specified.
* @return session-based {@link LocaleResolver}
*/
@ -49,12 +55,13 @@ public class WebConfiguration implements WebMvcConfigurer {
}
/**
* Registers the locale change interceptor so it can run on each request.
* Registers interceptors including locale change and rate limiting.
* @param registry where interceptors are added
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
registry.addInterceptor(rateLimitInterceptor);
}
}

View file

@ -16,6 +16,11 @@ spring.messages.basename=messages/messages
# Actuator
management.endpoints.web.exposure.include=*
# Rate Limiting
rate-limit.max-requests=5
rate-limit.window-size-minutes=1
rate-limit.enabled=true
# Logging
logging.level.org.springframework=INFO
# logging.level.org.springframework.web=DEBUG