mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 13:05:49 +00:00
Added rate limiting through application.properties file to the /owners/find endpoint
This commit is contained in:
parent
f9399b7a9f
commit
1291e38731
3 changed files with 15 additions and 2 deletions
|
@ -35,6 +35,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
import org.springframework.samples.petclinic.system.RateLimitInterceptor.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
|
@ -24,8 +24,14 @@ import java.util.Locale;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class WebConfiguration implements WebMvcConfigurer {
|
public class WebConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
private final RateLimitInterceptor rateLimitInterceptor;
|
||||||
|
|
||||||
|
public WebConfiguration(RateLimitInterceptor rateLimitInterceptor) {
|
||||||
|
this.rateLimitInterceptor = rateLimitInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses session storage to remember the user’s language setting across requests.
|
* Uses session storage to remember the user's language setting across requests.
|
||||||
* Defaults to English if nothing is specified.
|
* Defaults to English if nothing is specified.
|
||||||
* @return session-based {@link LocaleResolver}
|
* @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
|
* @param registry where interceptors are added
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(localeChangeInterceptor());
|
registry.addInterceptor(localeChangeInterceptor());
|
||||||
|
registry.addInterceptor(rateLimitInterceptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,11 @@ spring.messages.basename=messages/messages
|
||||||
# Actuator
|
# Actuator
|
||||||
management.endpoints.web.exposure.include=*
|
management.endpoints.web.exposure.include=*
|
||||||
|
|
||||||
|
# Rate Limiting
|
||||||
|
rate-limit.max-requests=5
|
||||||
|
rate-limit.window-size-minutes=1
|
||||||
|
rate-limit.enabled=true
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
logging.level.org.springframework=INFO
|
logging.level.org.springframework=INFO
|
||||||
# logging.level.org.springframework.web=DEBUG
|
# logging.level.org.springframework.web=DEBUG
|
||||||
|
|
Loading…
Reference in a new issue