Wednesday, 6 May 2020

interceptor in spring boot

https://medium.com/@dila.gurung/intercepting-incoming-request-using-springs-interceptor-bc1300e03f9


registry.addInterceptor(new LogInterceptor()).addPathPatterns("/secure-code");
//addPathPattern ensure that interceptor is levied to specified pattern. In our case it is applicable to path with this pattern "/admin/login"
Similiary path can be exculded from intercepting using code given below.
" registry.addInterceptor(new LogInterceptor()).addPathPatterns("/secure-code/*").excludePathPatterns("/secure-code/public"); "


https://stackoverflow.com/questions/34970179/exclude-spring-request-handlerinterceptor-by-path-pattern



@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LocaleInterceptor());
        registry.addInterceptor(new ThemeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**");

        // multiple urls (same is possible for `exludePathPatterns`)
        registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/secure/*", "/admin/**", "/profile/**");
    }
}

No comments:

Post a Comment