SHARE
TWEET

Untitled

a guest Jan 24th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.eightbit.mostbet.bonus.configuration;
  2.  
  3. import com.eightbit.mostbet.bonus.application.storage.ProjectStorage;
  4. import com.eightbit.mostbet.bonus.infrastructure.ProjectRepository;
  5. import com.eightbit.mostbet.bonus.infrastructure.logging.FingerprintMDCFilter;
  6. import com.eightbit.mostbet.bonus.infrastructure.logging.HttpLoggingFilter;
  7. import com.eightbit.mostbet.bonus.presentation.http.request.middleware.ProjectExistence;
  8. import com.eightbit.mostbet.bonus.presentation.http.request.middleware.ProjectFilterInitialize;
  9. import com.eightbit.mostbet.bonus.presentation.http.request.middleware.ProjectUuidExistence;
  10. import com.eightbit.mostbet.bonus.presentation.http.transformer.JsonTransformer;
  11. import org.springframework.boot.context.properties.ConfigurationProperties;
  12. import org.springframework.boot.web.servlet.FilterRegistrationBean;
  13. import org.springframework.context.annotation.Bean;
  14. import org.springframework.context.annotation.Configuration;
  15.  
  16. import javax.persistence.EntityManager;
  17.  
  18. @Configuration
  19. @ConfigurationProperties(prefix = "config.slf4jfilter")
  20. public class FilterConfiguration {
  21.  
  22.     public static final String MDC_SESSION_KEY = "session_fingerprint";
  23.     public static final String MNC_PROCESS_KEY = "process_fingerprint";
  24.     public static final String REQUEST_HEADER = "x-session-fingerprint";
  25.  
  26.     @Bean
  27.     public FilterRegistrationBean<FingerprintMDCFilter> fingerprintRegistrationBean() {
  28.         final FilterRegistrationBean<FingerprintMDCFilter> registrationBean = new FilterRegistrationBean<>();
  29.         registrationBean.setFilter(createFingerprintFilter());
  30.         registrationBean.setOrder(2);
  31.  
  32.         return registrationBean;
  33.     }
  34.  
  35.     @Bean
  36.     public FilterRegistrationBean<HttpLoggingFilter> requestRegistrationBean() {
  37.         final FilterRegistrationBean<HttpLoggingFilter> registrationBean = new FilterRegistrationBean<>();
  38.         registrationBean.setFilter(createRequestFilter());
  39.         registrationBean.setOrder(3);
  40.  
  41.         return registrationBean;
  42.     }
  43.  
  44.     @Bean
  45.     public FilterRegistrationBean<ProjectUuidExistence> projectUuidExistence(JsonTransformer jsonTransformer) {
  46.         final FilterRegistrationBean<ProjectUuidExistence> registrationBean = new FilterRegistrationBean<>();
  47.         registrationBean.setFilter(createProjectUuidExistenceFilter(jsonTransformer));
  48.         registrationBean.setOrder(4);
  49.  
  50.         return registrationBean;
  51.     }
  52.  
  53.     @Bean
  54.     public FilterRegistrationBean<ProjectExistence> projectExistence(ProjectStorage projectStorage, ProjectRepository projectRepository, JsonTransformer jsonTransformer) {
  55.         final FilterRegistrationBean<ProjectExistence> registrationBean = new FilterRegistrationBean<>();
  56.         registrationBean.setFilter(createProjectExistence(projectStorage, projectRepository, jsonTransformer));
  57.         registrationBean.setOrder(5);
  58.  
  59.         return registrationBean;
  60.     }
  61.  
  62.     @Bean
  63.     public FilterRegistrationBean<ProjectFilterInitialize> projectFilterInitialize(EntityManager entityManager, ProjectStorage projectStorage, JsonTransformer jsonTransformer) {
  64.         final FilterRegistrationBean<ProjectFilterInitialize> registrationBean = new FilterRegistrationBean<>();
  65.         registrationBean.setFilter(createProjectFilterInitialize(entityManager, projectStorage, jsonTransformer));
  66.         registrationBean.setOrder(6);
  67.  
  68.         return registrationBean;
  69.     }
  70.  
  71.     private FingerprintMDCFilter createFingerprintFilter() {
  72.         return new FingerprintMDCFilter(MDC_SESSION_KEY, MNC_PROCESS_KEY, REQUEST_HEADER);
  73.     }
  74.  
  75.     private HttpLoggingFilter createRequestFilter() {
  76.         return new HttpLoggingFilter();
  77.     }
  78.  
  79.     private ProjectUuidExistence createProjectUuidExistenceFilter(JsonTransformer jsonTransformer) {
  80.         return new ProjectUuidExistence(jsonTransformer);
  81.     }
  82.  
  83.     private ProjectExistence createProjectExistence(ProjectStorage projectStorage, ProjectRepository projectRepository, JsonTransformer jsonTransformer) {
  84.         return new ProjectExistence(projectStorage, projectRepository, jsonTransformer);
  85.     }
  86.  
  87.     private ProjectFilterInitialize createProjectFilterInitialize(EntityManager entityManager, ProjectStorage projectStorage, JsonTransformer jsonTransformer) {
  88.         return new ProjectFilterInitialize(entityManager, projectStorage, jsonTransformer);
  89.     }
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top