Subversion Repositories SmartDukaan

Rev

Rev 21734 | Rev 21812 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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.AuthenticationInterceptor;
15
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
21236 ashik.ali 16
import com.spice.profitmandi.web.interceptor.ApiRequestInterceptor;
21302 ashik.ali 17
import com.spice.profitmandi.web.interceptor.CreateRetailerRequestInterceptor;
21309 ashik.ali 18
import com.spice.profitmandi.web.interceptor.CreateShopRequestInterceptor;
21278 ashik.ali 19
import com.spice.profitmandi.web.interceptor.CreateUserRequestInterceptor;
21277 ashik.ali 20
import com.spice.profitmandi.web.interceptor.GoogleLoginRequestInterceptor;
21236 ashik.ali 21
import com.spice.profitmandi.web.interceptor.RoleRequestInterceptor;
21220 ashik.ali 22
 
21272 kshitij.so 23
import springfox.documentation.builders.PathSelectors;
24
import springfox.documentation.builders.RequestHandlerSelectors;
25
import springfox.documentation.service.ApiInfo;
26
import springfox.documentation.spi.DocumentationType;
27
import springfox.documentation.spring.web.plugins.Docket;
28
import springfox.documentation.swagger2.annotations.EnableSwagger2;
29
 
21165 ashik.ali 30
@Configuration
31
@EnableWebMvc
21272 kshitij.so 32
@EnableSwagger2
21220 ashik.ali 33
@ComponentScan("com.spice.profitmandi.*")
21165 ashik.ali 34
public class WebMVCConfig extends WebMvcConfigurerAdapter{
35
 
36
	private static final String RESOURCES_PATTERN="/resources/**";
37
	private static final String RESOURCES_LOCATION="/resources/";
38
 
21220 ashik.ali 39
	@Autowired
21236 ashik.ali 40
	ApiRequestInterceptor apiRequestInterceptor;
21165 ashik.ali 41
 
21236 ashik.ali 42
	@Autowired
43
	RoleRequestInterceptor roleRequestInterceptor;
44
 
21277 ashik.ali 45
	@Autowired
46
	GoogleLoginRequestInterceptor googleLoginRequestInterceptor;
21272 kshitij.so 47
 
21278 ashik.ali 48
	@Autowired
49
	CreateUserRequestInterceptor createUserRequestInterceptor;
21277 ashik.ali 50
 
21285 kshitij.so 51
	@Autowired
52
	SimpleCORSInterceptor simpleCORSInterceptor;
53
 
21302 ashik.ali 54
	@Autowired
55
	CreateRetailerRequestInterceptor createRetailerRequestInterceptor;
56
 
21309 ashik.ali 57
	@Autowired
58
	CreateShopRequestInterceptor createShopRequestInterceptor;
21452 amit.gupta 59
 
60
	@Autowired
61
	AuthenticationInterceptor authenticationInterceptor;
21302 ashik.ali 62
 
21272 kshitij.so 63
	@Bean
64
	public Docket api() {
65
		return new Docket(DocumentationType.SWAGGER_2).select()
66
				.apis(RequestHandlerSelectors.any())
67
				.paths(PathSelectors.any()).build()
68
				.apiInfo(apiInfo());
69
	}
70
 
21165 ashik.ali 71
	@Override
21272 kshitij.so 72
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
73
	    registry.addResourceHandler("swagger-ui.html")
74
	      .addResourceLocations("classpath:/META-INF/resources/");
75
	    registry.addResourceHandler("/webjars/**")
76
	      .addResourceLocations("classpath:/META-INF/resources/webjars/");
77
	    registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
78
	}
21165 ashik.ali 79
 
80
	@Override
81
	public void addInterceptors(InterceptorRegistry registry) {
21473 amit.gupta 82
		registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html", ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED);
21469 amit.gupta 83
		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN)
84
		.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**")
21471 amit.gupta 85
		.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP);
21469 amit.gupta 86
		//registry to check api access on basis of UserInfo
21474 amit.gupta 87
		registry.addInterceptor(googleLoginRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/");
21469 amit.gupta 88
		//registry.addInterceptor(createUserRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_USER, ProfitMandiConstants.URL_USER + "/");
21455 amit.gupta 89
 
90
 
21426 ashik.ali 91
		//registry.addInterceptor(createRetailerRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_RETAILER, ProfitMandiConstants.URL_RETAILER + "/");
21452 amit.gupta 92
		//registry.addInterceptor(createShopRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_SHOP, ProfitMandiConstants.URL_SHOP + "/");
21165 ashik.ali 93
	}
21272 kshitij.so 94
 
21285 kshitij.so 95
	@Override
96
	public void addCorsMappings(CorsRegistry registry) {
97
		registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
98
		allowedHeaders("*").allowCredentials(false);
99
	}
100
 
21272 kshitij.so 101
	private ApiInfo apiInfo() {
102
	    @SuppressWarnings("deprecation")
103
		ApiInfo apiInfo = new ApiInfo(
104
	      "ProfitMandi API",
105
	      "Api's for profitmandi app",
106
	      "API TOS",
107
	      "Terms of service",
108
	      "New Spice Solutions Pvt. Ltd.",
109
	      "License of API",
110
	      "API license URL");
111
	    return apiInfo;
112
	}
21220 ashik.ali 113
}