0

I'm running Vaadin on Spring-Boot. I tried implementing WebMvcConfigurer & and HandlerInterceptor to disable PUT & DELETE requests, but it is not working. I can see WebMvcConfigurer is getting loaded, but the preHandle method in the custom HandlerInterceptor never gets called. I noticed Vaadin is loading AtmosphereInterceptor, wondering if that is overriding my custom spring settings. Any idea what can I do to disable PUT & DELETE on all paths (/**) by default in vaadin?

edit code:

@Component
class HTTPRequestInterceptor extends HandlerInterceptor {
  override def preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean = {
    if (HttpMethod.GET.matches(request.getMethod) || HttpMethod.POST.matches(request.getMethod)) {
      true
    } else {
      response.sendError(HttpStatus.METHOD_NOT_ALLOWED.value())
      false
    }
  }
}

@Configuration
class HTTPRequestInterceptorConfig (@Autowired interceptor: HTTPRequestInterceptor) extends WebMvcConfigurer {
  private val log = LoggerFactory.getLogger(classOf[HTTPRequestInterceptorConfig])
  override def addInterceptors(registry: InterceptorRegistry): Unit = {
    log.info("adding interceptors")
    registry.addInterceptor(interceptor).addPathPatterns("/**")
  }
}

Note: I tried both with & without @Autowired parameter.

TiN
  • 179
  • 1
  • 12
  • 1
    Please add the code, you have tried. – cfrick Jul 12 '22 at 06:46
  • Does this answer your question? [Disable HTTP OPTIONS method in spring boot application](https://stackoverflow.com/questions/42367975/disable-http-options-method-in-spring-boot-application) – Simon Martinelli Jul 15 '22 at 07:06

0 Answers0