Subversion Repositories SmartDukaan

Rev

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