| 21165 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
|
|
2 |
|
| 23947 |
tejbeer |
3 |
import java.util.List;
|
| 23691 |
tejbeer |
4 |
|
| 28585 |
amit.gupta |
5 |
import javax.xml.transform.Source;
|
|
|
6 |
|
| 33766 |
ranu |
7 |
import com.spice.profitmandi.web.interceptor.PostInterceptor;
|
| 23954 |
tejbeer |
8 |
import org.apache.logging.log4j.LogManager;
|
|
|
9 |
import org.apache.logging.log4j.Logger;
|
| 21220 |
ashik.ali |
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21272 |
kshitij.so |
11 |
import org.springframework.context.annotation.Bean;
|
| 21165 |
ashik.ali |
12 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
13 |
import org.springframework.context.annotation.Configuration;
|
| 27014 |
amit.gupta |
14 |
import org.springframework.http.MediaType;
|
| 28585 |
amit.gupta |
15 |
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
| 23947 |
tejbeer |
16 |
import org.springframework.http.converter.HttpMessageConverter;
|
| 28585 |
amit.gupta |
17 |
import org.springframework.http.converter.ResourceHttpMessageConverter;
|
| 23947 |
tejbeer |
18 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
| 28585 |
amit.gupta |
19 |
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
|
|
20 |
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
|
| 27014 |
amit.gupta |
21 |
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
| 21285 |
kshitij.so |
22 |
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
| 21165 |
ashik.ali |
23 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
24 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
25 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
| 28585 |
amit.gupta |
26 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
| 23965 |
amit.gupta |
27 |
|
|
|
28 |
import com.fasterxml.jackson.databind.DeserializationFeature;
|
| 23947 |
tejbeer |
29 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 23954 |
tejbeer |
30 |
import com.fasterxml.jackson.databind.SerializationFeature;
|
| 23947 |
tejbeer |
31 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
| 21236 |
ashik.ali |
32 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21743 |
ashik.ali |
33 |
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
|
| 21812 |
amit.gupta |
34 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
| 23965 |
amit.gupta |
35 |
|
| 21272 |
kshitij.so |
36 |
import springfox.documentation.builders.PathSelectors;
|
|
|
37 |
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
38 |
import springfox.documentation.service.ApiInfo;
|
|
|
39 |
import springfox.documentation.spi.DocumentationType;
|
|
|
40 |
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
41 |
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
42 |
|
| 21165 |
ashik.ali |
43 |
@Configuration
|
|
|
44 |
@EnableWebMvc
|
| 21272 |
kshitij.so |
45 |
@EnableSwagger2
|
| 21220 |
ashik.ali |
46 |
@ComponentScan("com.spice.profitmandi.*")
|
| 28585 |
amit.gupta |
47 |
public class WebMVCConfig extends WebMvcConfigurerAdapter {
|
| 27119 |
tejbeer |
48 |
|
|
|
49 |
private static final String RESOURCES_PATTERN = "/resources/**";
|
|
|
50 |
private static final String RESOURCES_LOCATION = "/resources/";
|
|
|
51 |
|
| 23954 |
tejbeer |
52 |
private static final Logger log = LogManager.getLogger(WebMVCConfig.class);
|
| 27119 |
tejbeer |
53 |
|
| 21220 |
ashik.ali |
54 |
@Autowired
|
| 21285 |
kshitij.so |
55 |
SimpleCORSInterceptor simpleCORSInterceptor;
|
| 21452 |
amit.gupta |
56 |
|
|
|
57 |
@Autowired
|
| 33766 |
ranu |
58 |
PostInterceptor postInterceptor;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
| 21452 |
amit.gupta |
61 |
AuthenticationInterceptor authenticationInterceptor;
|
| 27119 |
tejbeer |
62 |
|
| 37150 |
amit |
63 |
@Autowired
|
|
|
64 |
com.spice.profitmandi.web.interceptor.ApiKeyInterceptor apiKeyInterceptor;
|
|
|
65 |
|
| 21272 |
kshitij.so |
66 |
@Bean
|
|
|
67 |
public Docket api() {
|
| 27119 |
tejbeer |
68 |
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
|
|
|
69 |
.paths(PathSelectors.any()).build().apiInfo(apiInfo());
|
| 21272 |
kshitij.so |
70 |
}
|
| 27119 |
tejbeer |
71 |
|
| 21165 |
ashik.ali |
72 |
@Override
|
| 21272 |
kshitij.so |
73 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
| 27119 |
tejbeer |
74 |
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
|
|
75 |
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
76 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
| 21272 |
kshitij.so |
77 |
}
|
| 27119 |
tejbeer |
78 |
|
| 21165 |
ashik.ali |
79 |
@Override
|
|
|
80 |
public void addInterceptors(InterceptorRegistry registry) {
|
| 33766 |
ranu |
81 |
registry.addInterceptor(postInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html",
|
|
|
82 |
ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED,
|
|
|
83 |
ProfitMandiConstants.URL_CCAVENUE_PAY_RESPONSE, ProfitMandiConstants.URL_CCAVENUE_PAY_CANCELLED,
|
|
|
84 |
ProfitMandiConstants.URL_PINELABS_PAY_RESPONSE, ProfitMandiConstants.URL_LOAN_CCAVENUE_PAY_CANCELLED,
|
|
|
85 |
ProfitMandiConstants.URL_LOAN_CCAVENUE_PAY_RESPONSE,
|
|
|
86 |
ProfitMandiConstants.URL_POST_OFFICE,
|
|
|
87 |
ProfitMandiConstants.HOOK_URL_CALLER_ID,
|
| 37150 |
amit |
88 |
ProfitMandiConstants.URL_NEW_LEAD,
|
|
|
89 |
"/external/**");
|
| 33766 |
ranu |
90 |
|
| 33768 |
ranu |
91 |
registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html","/clickToCall/**",
|
| 27113 |
tejbeer |
92 |
ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED,
|
|
|
93 |
ProfitMandiConstants.URL_CCAVENUE_PAY_RESPONSE, ProfitMandiConstants.URL_CCAVENUE_PAY_CANCELLED,
|
| 28570 |
amit.gupta |
94 |
ProfitMandiConstants.URL_PINELABS_PAY_RESPONSE, ProfitMandiConstants.URL_LOAN_CCAVENUE_PAY_CANCELLED,
|
| 32704 |
amit.gupta |
95 |
ProfitMandiConstants.URL_LOAN_CCAVENUE_PAY_RESPONSE,
|
|
|
96 |
ProfitMandiConstants.URL_POST_OFFICE,
|
|
|
97 |
ProfitMandiConstants.HOOK_URL_CALLER_ID,
|
| 33784 |
ranu |
98 |
ProfitMandiConstants.URL_NEW_LEAD,
|
| 37150 |
amit |
99 |
ProfitMandiConstants.URL_SHOPIFY, "/user/token/unregistered",
|
|
|
100 |
"/external/**");
|
| 27113 |
tejbeer |
101 |
|
| 26863 |
amit.gupta |
102 |
registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**")
|
| 35272 |
amit |
103 |
.excludePathPatterns("/user/token/unregistered")
|
| 27119 |
tejbeer |
104 |
.excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN).excludePathPatterns("/**/swagger*/**")
|
| 36353 |
vikas |
105 |
.excludePathPatterns("/document")
|
| 32704 |
amit.gupta |
106 |
.excludePathPatterns(ProfitMandiConstants.HOOK_URL_CALLER_ID)
|
| 33784 |
ranu |
107 |
.excludePathPatterns(ProfitMandiConstants.URL_SHOPIFY)
|
| 28588 |
amit.gupta |
108 |
.excludePathPatterns("/store/generateInvoice")
|
| 27119 |
tejbeer |
109 |
.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN,
|
| 36353 |
vikas |
110 |
ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP)
|
|
|
111 |
.excludePathPatterns("/store/token").excludePathPatterns("/gc/**").excludePathPatterns("/stores/**")
|
| 36957 |
aman |
112 |
.excludePathPatterns(ProfitMandiConstants.URL_AI_LEAD_INTAKE)
|
| 36963 |
vikas |
113 |
.excludePathPatterns("/v2/api-docs/**")
|
| 37388 |
vikas |
114 |
// Inbound gateway callback only. /botpenguin-test/** is deliberately NOT excluded:
|
|
|
115 |
// those endpoints send real messages from the business number, so they keep auth.
|
|
|
116 |
.excludePathPatterns("/botpenguin/wa-listen")
|
| 37150 |
amit |
117 |
.excludePathPatterns("/external/**");
|
| 27119 |
tejbeer |
118 |
|
| 37150 |
amit |
119 |
// third-party partner APIs: X-Api-Key auth only (docs page is open)
|
|
|
120 |
registry.addInterceptor(apiKeyInterceptor).addPathPatterns("/external/**")
|
|
|
121 |
.excludePathPatterns("/external/v1/docs");
|
|
|
122 |
|
| 27119 |
tejbeer |
123 |
// registry to check api access on basis of UserInfo
|
| 21165 |
ashik.ali |
124 |
}
|
| 27119 |
tejbeer |
125 |
|
| 21285 |
kshitij.so |
126 |
@Override
|
|
|
127 |
public void addCorsMappings(CorsRegistry registry) {
|
| 27119 |
tejbeer |
128 |
registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("*").allowCredentials(false);
|
| 21285 |
kshitij.so |
129 |
}
|
| 27119 |
tejbeer |
130 |
|
| 21272 |
kshitij.so |
131 |
private ApiInfo apiInfo() {
|
| 27119 |
tejbeer |
132 |
@SuppressWarnings("deprecation")
|
|
|
133 |
ApiInfo apiInfo = new ApiInfo("ProfitMandi API", "Api's for profitmandi app", "API TOS", "Terms of service",
|
|
|
134 |
"New Spice Solutions Pvt. Ltd.", "License of API", "API license URL");
|
|
|
135 |
return apiInfo;
|
| 21272 |
kshitij.so |
136 |
}
|
| 27119 |
tejbeer |
137 |
|
| 23947 |
tejbeer |
138 |
@Override
|
| 28585 |
amit.gupta |
139 |
public void configureMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
|
| 28581 |
amit.gupta |
140 |
|
| 28587 |
amit.gupta |
141 |
messageConverters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
| 28588 |
amit.gupta |
142 |
messageConverters.add(new ByteArrayHttpMessageConverter());
|
|
|
143 |
messageConverters.add(new ResourceHttpMessageConverter());
|
|
|
144 |
messageConverters.add(new SourceHttpMessageConverter<Source>());
|
|
|
145 |
messageConverters.add(new AllEncompassingFormHttpMessageConverter());
|
| 28585 |
amit.gupta |
146 |
super.configureMessageConverters(messageConverters);
|
| 27119 |
tejbeer |
147 |
}
|
|
|
148 |
|
| 23949 |
amit.gupta |
149 |
@Bean
|
|
|
150 |
public ObjectMapper objectMapper() {
|
| 27119 |
tejbeer |
151 |
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
152 |
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
153 |
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
|
|
154 |
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
|
|
155 |
objectMapper.registerModule(javaTimeModule);
|
|
|
156 |
return objectMapper;
|
| 23947 |
tejbeer |
157 |
}
|
| 23954 |
tejbeer |
158 |
|
| 27014 |
amit.gupta |
159 |
@Override
|
|
|
160 |
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
|
|
161 |
configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
162 |
}
|
|
|
163 |
|
| 21220 |
ashik.ali |
164 |
}
|