| 21165 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
|
|
2 |
|
| 23691 |
tejbeer |
3 |
import java.time.format.DateTimeFormatter;
|
|
|
4 |
|
| 21220 |
ashik.ali |
5 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21272 |
kshitij.so |
6 |
import org.springframework.context.annotation.Bean;
|
| 21165 |
ashik.ali |
7 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
8 |
import org.springframework.context.annotation.Configuration;
|
| 21285 |
kshitij.so |
9 |
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
| 21165 |
ashik.ali |
10 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
11 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
12 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
13 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
|
14 |
|
| 21236 |
ashik.ali |
15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21743 |
ashik.ali |
16 |
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
|
| 21812 |
amit.gupta |
17 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
| 21220 |
ashik.ali |
18 |
|
| 21272 |
kshitij.so |
19 |
import springfox.documentation.builders.PathSelectors;
|
|
|
20 |
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
21 |
import springfox.documentation.service.ApiInfo;
|
|
|
22 |
import springfox.documentation.spi.DocumentationType;
|
|
|
23 |
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
24 |
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
25 |
|
| 21165 |
ashik.ali |
26 |
@Configuration
|
|
|
27 |
@EnableWebMvc
|
| 21272 |
kshitij.so |
28 |
@EnableSwagger2
|
| 21220 |
ashik.ali |
29 |
@ComponentScan("com.spice.profitmandi.*")
|
| 21165 |
ashik.ali |
30 |
public class WebMVCConfig extends WebMvcConfigurerAdapter{
|
|
|
31 |
|
|
|
32 |
private static final String RESOURCES_PATTERN="/resources/**";
|
|
|
33 |
private static final String RESOURCES_LOCATION="/resources/";
|
| 23691 |
tejbeer |
34 |
public static final DateTimeFormatter FORMATTER =DateTimeFormatter.ofPattern("dd::MM::yyyy");
|
| 21165 |
ashik.ali |
35 |
|
| 21220 |
ashik.ali |
36 |
@Autowired
|
| 21285 |
kshitij.so |
37 |
SimpleCORSInterceptor simpleCORSInterceptor;
|
| 21452 |
amit.gupta |
38 |
|
|
|
39 |
@Autowired
|
|
|
40 |
AuthenticationInterceptor authenticationInterceptor;
|
| 21302 |
ashik.ali |
41 |
|
| 21272 |
kshitij.so |
42 |
@Bean
|
|
|
43 |
public Docket api() {
|
|
|
44 |
return new Docket(DocumentationType.SWAGGER_2).select()
|
|
|
45 |
.apis(RequestHandlerSelectors.any())
|
|
|
46 |
.paths(PathSelectors.any()).build()
|
|
|
47 |
.apiInfo(apiInfo());
|
|
|
48 |
}
|
|
|
49 |
|
| 21165 |
ashik.ali |
50 |
@Override
|
| 21272 |
kshitij.so |
51 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
52 |
registry.addResourceHandler("swagger-ui.html")
|
|
|
53 |
.addResourceLocations("classpath:/META-INF/resources/");
|
|
|
54 |
registry.addResourceHandler("/webjars/**")
|
|
|
55 |
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
56 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
|
|
57 |
}
|
| 21165 |
ashik.ali |
58 |
|
|
|
59 |
@Override
|
|
|
60 |
public void addInterceptors(InterceptorRegistry registry) {
|
| 21473 |
amit.gupta |
61 |
registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html", ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED);
|
| 21469 |
amit.gupta |
62 |
registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN)
|
| 22812 |
amit.gupta |
63 |
.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**").excludePathPatterns("/document")
|
| 21471 |
amit.gupta |
64 |
.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP);
|
| 21469 |
amit.gupta |
65 |
//registry to check api access on basis of UserInfo
|
| 21165 |
ashik.ali |
66 |
}
|
| 21272 |
kshitij.so |
67 |
|
| 21285 |
kshitij.so |
68 |
@Override
|
|
|
69 |
public void addCorsMappings(CorsRegistry registry) {
|
|
|
70 |
registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
|
|
|
71 |
allowedHeaders("*").allowCredentials(false);
|
|
|
72 |
}
|
|
|
73 |
|
| 21272 |
kshitij.so |
74 |
private ApiInfo apiInfo() {
|
|
|
75 |
@SuppressWarnings("deprecation")
|
|
|
76 |
ApiInfo apiInfo = new ApiInfo(
|
|
|
77 |
"ProfitMandi API",
|
|
|
78 |
"Api's for profitmandi app",
|
|
|
79 |
"API TOS",
|
|
|
80 |
"Terms of service",
|
|
|
81 |
"New Spice Solutions Pvt. Ltd.",
|
|
|
82 |
"License of API",
|
|
|
83 |
"API license URL");
|
|
|
84 |
return apiInfo;
|
|
|
85 |
}
|
| 21220 |
ashik.ali |
86 |
}
|