Add the routes to the AuthorizedInterceptor's configuration.
continuous-integration/drone/push Build is passing Details

main
KKlochko 1 year ago
parent 81971295c0
commit ccd1edea7e

@ -1,8 +1,6 @@
package space.kklochko.spring_rest_example.config; package space.kklochko.spring_rest_example.config;
import java.sql.Timestamp;
import java.util.List; import java.util.List;
import java.util.UUID;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import org.springframework.context.annotation.Bean; 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.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; 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 org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import space.kklochko.spring_rest_example.db.factories.EntityManagerConnection; import space.kklochko.spring_rest_example.db.factories.EntityManagerConnection;
import space.kklochko.spring_rest_example.db.repositories.IndicatorRepository; 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.models.factories.TokenFactory;
import space.kklochko.spring_rest_example.security.tokens.SimpleRandomToken; import space.kklochko.spring_rest_example.security.tokens.SimpleRandomToken;
import space.kklochko.spring_rest_example.security.tokens.StringTokenFactory; import space.kklochko.spring_rest_example.security.tokens.StringTokenFactory;
@ -42,4 +42,17 @@ public class WebConfig implements WebMvcConfigurer {
StringTokenFactory stringTokenFactory = new SimpleRandomToken(); StringTokenFactory stringTokenFactory = new SimpleRandomToken();
return new TokenFactory(stringTokenFactory); 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/**");
}
} }

Loading…
Cancel
Save