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