From ccd1edea7ed6080524bdd9bf3f046119bc8c3452 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Fri, 1 Dec 2023 21:07:51 +0200 Subject: [PATCH] Add the routes to the AuthorizedInterceptor's configuration. --- .../spring_rest_example/config/WebConfig.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/kklochko/spring_rest_example/config/WebConfig.java b/src/main/java/space/kklochko/spring_rest_example/config/WebConfig.java index 946802a..d6a9c7f 100644 --- a/src/main/java/space/kklochko/spring_rest_example/config/WebConfig.java +++ b/src/main/java/space/kklochko/spring_rest_example/config/WebConfig.java @@ -1,8 +1,6 @@ package space.kklochko.spring_rest_example.config; -import java.sql.Timestamp; import java.util.List; -import java.util.UUID; import jakarta.persistence.EntityManager; import org.springframework.context.annotation.Bean; @@ -11,9 +9,11 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import space.kklochko.spring_rest_example.db.factories.EntityManagerConnection; import space.kklochko.spring_rest_example.db.repositories.IndicatorRepository; +import space.kklochko.spring_rest_example.interceptors.AuthorizedInterceptor; import space.kklochko.spring_rest_example.models.factories.TokenFactory; import space.kklochko.spring_rest_example.security.tokens.SimpleRandomToken; import space.kklochko.spring_rest_example.security.tokens.StringTokenFactory; @@ -42,4 +42,17 @@ public class WebConfig implements WebMvcConfigurer { StringTokenFactory stringTokenFactory = new SimpleRandomToken(); return new TokenFactory(stringTokenFactory); } + + @Bean + public AuthorizedInterceptor authorizedInterceptor() { + return new AuthorizedInterceptor(); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(authorizedInterceptor()) + .addPathPatterns("/api/v1/departments/**") + .addPathPatterns("/api/v1/patients/**") + .addPathPatterns("/api/v1/indicators/**"); + } }