Newer
Older
huludao / src / main / java / com / newfiber / api / config / WebMvcConfig.java
package com.newfiber.api.config;

import com.newfiber.api.core.interceptor.JurInterceptor;
import com.newfiber.api.core.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.newfiber.api.core.interceptor.MaliciousReqInterceptor;
import com.newfiber.api.core.interceptor.ReqHeaderValidInterceptor;

import java.util.List;

/**
 * MVC配置
 * @author hy
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
	/** 登录请求拦截器 */
	@Autowired
	private LoginInterceptor loginInterceptor;
	/** 权限验证拦截器 */
	@Autowired
	private JurInterceptor jurInterceptor;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry
				.addInterceptor(loginInterceptor)
				.addPathPatterns("/**")
				.excludePathPatterns("/logininfo/login",
						"/logininfo/logout",
						"/logininfo/validateToken",
						"/logininfo/validateIp",
						"/menu_list_by_user",
						"/select_remark_list",
						"/pumpInfo/queryAllSanwei",
						"/pumpInfo/operationSanwei",
						"/meet/people/list",
						"/pipe/list",
						"/location//update",
						"/ipcall/call",
						"/location/selectByUserNo",
						"/location/selectOnlineUser",
						"/tempData/queryData",
						"/house/queryAll",
						"/manPump/queryPage",
						"/users/getProjectUser",
						"/users/getNoProjectUser",
						"/swagger-resources/**",
						"/webjars/**",
						"/v2/**",
						"/swagger-ui.html/**",
                        "/doc.html/**",
                        "/rest_template/**",
						"/prositeinfo/listTempDataAllSite",
						"/prositeinfo/update",
						"/manPump/queryAll",
						"/pumpRuntime/selectRuntimeData",
						"/dataReport/batchExportHistoryData",
						"/site/getHeads",
						"/data/selectSiteSiteManHistoryDataMongoBySerial",
						"/data/selectSiteSiteManBySerial",
						"/site/selectSitePropertyList",
						"/data/siteDataEchat",
						"/groups/selectSiteNoByGroupsNo",
						"/sys/stationbase/listExtend",
						"/sys/stationbase/getTempData",
						"/warn/log/listWarnLog");
		registry
				.addInterceptor(jurInterceptor)
				.addPathPatterns("/**")
				.excludePathPatterns("/logininfo/login",
						"/logininfo/logout",
						"/logininfo/validateToken",
						"/logininfo/validateIp",
						"/menu_list_by_user",
						"/select_remark_list",
						"/pumpInfo/queryAllSanwei",
						"/pumpInfo/operationSanwei",
						"/meet/people/list",
						"/pipe/list",
						"/location//update",
						"/ipcall/call",
						"/location/selectByUserNo",
						"/location/selectOnlineUser",
						"/tempData/queryData",
						"/house/queryAll",
						"/manPump/queryPage",
						"/users/getProjectUser",
						"/users/getNoProjectUser",
						"/swagger-resources/**",
						"/webjars/**",
						"/v2/**",
						"/swagger-ui.html/**",
						"/doc.html/**",
                        "/rest_template/**",
						"/prositeinfo/listTempDataAllSite",
						"/prositeinfo/update",
						"/manPump/queryAll",
						"/pumpRuntime/selectRuntimeData",
						"/dataReport/batchExportHistoryData",
						"/site/getHeads",
						"/data/selectSiteSiteManHistoryDataMongoBySerial",
						"/data/selectSiteSiteManBySerial",
						"/site/selectSitePropertyList",
						"/data/siteDataEchat",
						"/groups/selectSiteNoByGroupsNo",
						"/sys/stationbase/listExtend",
						"/sys/stationbase/getTempData",
						"/warn/log/listWarnLog");
		super.addInterceptors(registry);
	}

	/**
	 * 配置静态访问资源
	 * @param registry
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		registry.addResourceHandler("swagger-ui.html","doc.html")
				.addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**")
				.addResourceLocations("classpath:/META-INF/resources/webjars/");
		super.addResourceHandlers(registry);
	}
}