| | |
| | | import com.google.code.kaptcha.impl.DefaultKaptcha; |
| | | import com.google.code.kaptcha.util.Config; |
| | | import com.stylefeng.guns.config.properties.GunsProperties; |
| | | import com.stylefeng.guns.core.intercept.RestApiInteceptor; |
| | | import com.stylefeng.guns.core.listener.ConfigListener; |
| | | import com.stylefeng.guns.core.xss.XssFilter; |
| | | import edu.yale.its.tp.cas.client.filter.OnconMDWebCasFilter; |
| | | import org.jasig.cas.client.session.SingleSignOutFilter; |
| | | import org.jasig.cas.client.session.SingleSignOutHttpSessionListener; |
| | | import org.springframework.aop.Advisor; |
| | | import org.springframework.aop.support.DefaultPointcutAdvisor; |
| | | import org.springframework.aop.support.JdkRegexpMethodPointcut; |
| | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.context.request.RequestContextListener; |
| | | 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 java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Properties; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Configuration |
| | | public class WebConfig extends WebMvcConfigurerAdapter { |
| | | |
| | | @Autowired |
| | | private GunsProperties gunsProperties; |
| | | |
| | | /** |
| | | * 增加swagger的支持 |
| | | */ |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| | | if (gunsProperties.getSwaggerOpen()) { |
| | | registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); |
| | | registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 增加对rest api鉴权的spring mvc拦截器 |
| | | */ |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | | registry.addInterceptor(new RestApiInteceptor()).addPathPatterns("/api/**") |
| | | .excludePathPatterns("/api/placeOrder/notifyUrl") |
| | | .excludePathPatterns("/api/placeOrder/notifyUrlOne"); |
| | | } |
| | | |
| | | /** |
| | | * druidServlet注册 |
| | | */ |
| | | @Bean |
| | | public ServletRegistrationBean druidServletRegistration() { |
| | | ServletRegistrationBean registration = new ServletRegistrationBean(new StatViewServlet()); |
| | | registration.addUrlMappings("/druid/*"); |
| | | return registration; |
| | | } |
| | | |
| | | /** |
| | | * druid监控 配置URI拦截策略 |
| | | */ |
| | | @Bean |
| | | public FilterRegistrationBean druidStatFilter() { |
| | | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter()); |
| | | //添加过滤规则. |
| | | filterRegistrationBean.addUrlPatterns("/*"); |
| | | //添加不需要忽略的格式信息. |
| | | filterRegistrationBean.addInitParameter( |
| | | "exclusions", "/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid,/druid/*"); |
| | | //用于session监控页面的用户名显示 需要登录后主动将username注入到session里 |
| | | filterRegistrationBean.addInitParameter("principalSessionName", "username"); |
| | | return filterRegistrationBean; |
| | | } |
| | | |
| | | /** |
| | | * druid数据库连接池监控 |
| | | */ |
| | | @Bean |
| | | public DruidStatInterceptor druidStatInterceptor() { |
| | | return new DruidStatInterceptor(); |
| | | } |
| | | |
| | | @Bean |
| | | public JdkRegexpMethodPointcut druidStatPointcut() { |
| | | JdkRegexpMethodPointcut druidStatPointcut = new JdkRegexpMethodPointcut(); |
| | | String patterns = "com.stylefeng.guns.modular.*.service.*"; |
| | | //可以set多个 |
| | | druidStatPointcut.setPatterns(patterns); |
| | | return druidStatPointcut; |
| | | } |
| | | |
| | | /** |
| | | * druid数据库连接池监控 |
| | | */ |
| | | @Bean |
| | | public BeanTypeAutoProxyCreator beanTypeAutoProxyCreator() { |
| | | BeanTypeAutoProxyCreator beanTypeAutoProxyCreator = new BeanTypeAutoProxyCreator(); |
| | | beanTypeAutoProxyCreator.setTargetBeanType(DruidDataSource.class); |
| | | beanTypeAutoProxyCreator.setInterceptorNames("druidStatInterceptor"); |
| | | return beanTypeAutoProxyCreator; |
| | | } |
| | | |
| | | /** |
| | | * druid 为druidStatPointcut添加拦截 |
| | | * |
| | | * @return |
| | | */ |
| | | |
| | | @Autowired |
| | | private GunsProperties gunsProperties; |
| | | |
| | | /** |
| | | * 增加swagger的支持 |
| | | */ |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| | | if (gunsProperties.getSwaggerOpen()) { |
| | | registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); |
| | | registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 增加对rest api鉴权的spring mvc拦截器 |
| | | */ |
| | | //舍弃原有的权限校验功能 |
| | | // @Override |
| | | // public void addInterceptors(InterceptorRegistry registry) { |
| | | // registry.addInterceptor(new RestApiInteceptor()).addPathPatterns("/api/**"); |
| | | // } |
| | | |
| | | /** |
| | | * druidServlet注册 |
| | | */ |
| | | @Bean |
| | | public ServletRegistrationBean druidServletRegistration() { |
| | | ServletRegistrationBean registration = new ServletRegistrationBean(new StatViewServlet()); |
| | | registration.addUrlMappings("/druid/*"); |
| | | return registration; |
| | | } |
| | | |
| | | /** |
| | | * druid监控 配置URI拦截策略 |
| | | */ |
| | | @Bean |
| | | public FilterRegistrationBean druidStatFilter() { |
| | | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter()); |
| | | //添加过滤规则. |
| | | filterRegistrationBean.addUrlPatterns("/*"); |
| | | //添加不需要忽略的格式信息. |
| | | filterRegistrationBean.addInitParameter( |
| | | "exclusions", "/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid,/druid/*"); |
| | | //用于session监控页面的用户名显示 需要登录后主动将username注入到session里 |
| | | filterRegistrationBean.addInitParameter("principalSessionName", "username"); |
| | | return filterRegistrationBean; |
| | | } |
| | | |
| | | /** |
| | | * druid数据库连接池监控 |
| | | */ |
| | | @Bean |
| | | public BeanTypeAutoProxyCreator beanTypeAutoProxyCreator() { |
| | | BeanTypeAutoProxyCreator beanTypeAutoProxyCreator = new BeanTypeAutoProxyCreator(); |
| | | beanTypeAutoProxyCreator.setTargetBeanType(DruidDataSource.class); |
| | | beanTypeAutoProxyCreator.setInterceptorNames("druidStatInterceptor"); |
| | | return beanTypeAutoProxyCreator; |
| | | } |
| | | |
| | | /** |
| | | * druid 为druidStatPointcut添加拦截 |
| | | * |
| | | * @return |
| | | */ |
| | | @Bean |
| | | public Advisor druidStatAdvisor() { |
| | | return new DefaultPointcutAdvisor(druidStatPointcut(), druidStatInterceptor()); |
| | | } |
| | | |
| | | @Bean |
| | | public JdkRegexpMethodPointcut druidStatPointcut() { |
| | | JdkRegexpMethodPointcut druidStatPointcut = new JdkRegexpMethodPointcut(); |
| | | String patterns = "com.stylefeng.guns.modular.*.service.*"; |
| | | //可以set多个 |
| | | druidStatPointcut.setPatterns(patterns); |
| | | return druidStatPointcut; |
| | | } |
| | | |
| | | /** |
| | | * druid数据库连接池监控 |
| | | */ |
| | | @Bean |
| | | public DruidStatInterceptor druidStatInterceptor() { |
| | | return new DruidStatInterceptor(); |
| | | } |
| | | |
| | | /** |
| | | * xssFilter注册 |
| | |
| | | */ |
| | | @Bean |
| | | public DefaultKaptcha kaptcha() { |
| | | Properties properties = new Properties(); |
| | | properties.put("kaptcha.border", "no"); |
| | | properties.put("kaptcha.border.color", "105,179,90"); |
| | | properties.put("kaptcha.textproducer.font.color", "blue"); |
| | | properties.put("kaptcha.image.width", "125"); |
| | | properties.put("kaptcha.image.height", "45"); |
| | | properties.put("kaptcha.textproducer.font.size", "45"); |
| | | properties.put("kaptcha.session.key", "code"); |
| | | properties.put("kaptcha.textproducer.char.length", "4"); |
| | | properties.put("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑"); |
| | | Config config = new Config(properties); |
| | | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); |
| | | defaultKaptcha.setConfig(config); |
| | | return defaultKaptcha; |
| | | Properties properties = new Properties(); |
| | | properties.put("kaptcha.border", "no"); |
| | | properties.put("kaptcha.border.color", "105,179,90"); |
| | | properties.put("kaptcha.textproducer.font.color", "blue"); |
| | | properties.put("kaptcha.image.width", "125"); |
| | | properties.put("kaptcha.image.height", "45"); |
| | | properties.put("kaptcha.textproducer.font.size", "45"); |
| | | properties.put("kaptcha.session.key", "code"); |
| | | properties.put("kaptcha.textproducer.char.length", "4"); |
| | | properties.put("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑"); |
| | | Config config = new Config(properties); |
| | | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); |
| | | defaultKaptcha.setConfig(config); |
| | | return defaultKaptcha; |
| | | } |
| | | |
| | | |
| | | /********************黔云通单点登录拦截器**********************/ |
| | | |
| | | // @Override |
| | | // public void addViewControllers(ViewControllerRegistry registry) { |
| | | // registry.addViewController("/index").setViewName("index"); |
| | | // } |
| | | @Bean |
| | | public FilterRegistrationBean getOnconMDWebCasFilter() { |
| | | OnconMDWebCasFilter onconMDWebCasFilter = new OnconMDWebCasFilter(); |
| | | |
| | | FilterRegistrationBean registrationBean = new FilterRegistrationBean(); |
| | | registrationBean.setFilter(onconMDWebCasFilter); |
| | | List<String> urlPatterns = new ArrayList<String>(); |
| | | urlPatterns.add("/*");//拦截路径,可以添加多个 |
| | | registrationBean.setUrlPatterns(urlPatterns); |
| | | registrationBean.setOrder(2); |
| | | |
| | | registrationBean.addInitParameter("oncon.com.security.urls", "/api/**"); |
| | | registrationBean.addInitParameter("erp.si-tech.com.cn.noCheckUrl", "/index,/ajaxgetticket.jsp,/ssoAutologin.jsp,/login.jsp,/nologingetuserinfo.jsp,/toautologin.jsp,/autologin.jsp,/remotelogin.jsp,/toremotelogin.jsp,/js/**,/remoteloginajax.jsp"); |
| | | registrationBean.addInitParameter("erp.si-tech.com.cn.nologinstatus", "/*"); |
| | | registrationBean.addInitParameter("erp.si-tech.com.cn.loginstatus", "/login.jsp,/nologingetuserinfo.jsp"); |
| | | registrationBean.addInitParameter("com.oncon.sso.urlparams.nologin", "code,code2"); |
| | | |
| | | registrationBean.addInitParameter("edu.yale.its.tp.cas.client.filter.loginUrl", "https://testsso1.teamshub.com/login"); |
| | | registrationBean.addInitParameter("edu.yale.its.tp.cas.client.filter.validateUrl", "https://testsso1.teamshub.com/serviceValidate"); |
| | | registrationBean.addInitParameter("com.oncon.md.loginUrl", "https://testsso1.teamshub.com/sso-session/login"); |
| | | registrationBean.addInitParameter("edu.yale.its.tp.cas.client.filter.serverName", "172.26.200.34:9180"); |
| | | registrationBean.addInitParameter("edu.yale.its.tp.cas.client.filter.casServiceUrlForStatic", "http://172.26.200.34:9180/sso-springboot-client/getUserInfo"); |
| | | registrationBean.addInitParameter("edu.yale.its.tp.cas.client.filter.loginatUrlForStatic", ""); |
| | | registrationBean.addInitParameter("edu.yale.its.tp.cas.client.filter.loginFailedUrlForStatic", "http://172.26.200.34:9180/error.html"); |
| | | |
| | | |
| | | return registrationBean; |
| | | } |
| | | |
| | | @Bean |
| | | public FilterRegistrationBean getSingleSignOutFilter() { |
| | | SingleSignOutFilter singleSignOutFilter = new SingleSignOutFilter(); |
| | | FilterRegistrationBean registrationBean = new FilterRegistrationBean(); |
| | | registrationBean.setFilter(singleSignOutFilter); |
| | | List<String> urlPatterns = new ArrayList<String>(); |
| | | urlPatterns.add("/api/**");//拦截路径,可以添加多个 |
| | | registrationBean.setUrlPatterns(urlPatterns); |
| | | registrationBean.setOrder(1); |
| | | |
| | | registrationBean.addInitParameter("wmall.flag", "false"); |
| | | |
| | | return registrationBean; |
| | | } |
| | | |
| | | @Bean |
| | | public ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> getSingleSignOutHttpSessionListener() { |
| | | ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> servletListenerRegistrationBean |
| | | = new ServletListenerRegistrationBean<>(); |
| | | servletListenerRegistrationBean.setListener(new SingleSignOutHttpSessionListener()); |
| | | return servletListenerRegistrationBean; |
| | | } |
| | | } |