From 1581f91f90e60193ff3e7e354ab1858c0ab31bf6 Mon Sep 17 00:00:00 2001 From: wangbing Date: Fri, 3 Jan 2020 17:28:33 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: ecf8a29945919b5d35ae4fc9293b05736a670d49 --- .../SpringBoot/java/config/FreeMarkerConfig.java | 16 +++++++--------- .../SpringBoot/java/config/SecurityConfig.java | 16 +++------------- .../SpringBoot/java/config/WebMvcConfig.java | 8 ++------ 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/main/resources/modules/SpringBoot/java/config/FreeMarkerConfig.java b/src/main/resources/modules/SpringBoot/java/config/FreeMarkerConfig.java index b8fda4f9..a69d7af4 100644 --- a/src/main/resources/modules/SpringBoot/java/config/FreeMarkerConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/FreeMarkerConfig.java @@ -1,16 +1,10 @@ package ${basePackage}.config; -import ${basePackage}.frame.auth.LocalData; -import ${basePackage}.frame.base.Control; -import ${basePackage}.frame.utils.UrlUtil; -import static ${basePackage}.config.ActionConfig.CONTROL_PREFIX; -import static ${basePackage}.config.ActionConfig.SCREEN_PREFIX; import freemarker.template.SimpleScalar; import freemarker.template.TemplateMethodModelEx; import freemarker.template.TemplateModelException; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.validation.support.BindingAwareModelMap; import org.springframework.web.context.request.RequestContextHolder; @@ -19,6 +13,9 @@ import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.LocaleResolver; import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.frame.base.Control; +import ${basePackage}.frame.utils.UrlUtil; import javax.annotation.PostConstruct; import javax.servlet.http.HttpServletRequest; @@ -27,21 +24,22 @@ import java.io.File; import java.util.List; import java.util.Locale; +import static xyz.wbsite.config.ActionConfig.CONTROL_PREFIX; +import static xyz.wbsite.config.ActionConfig.SCREEN_PREFIX; + @Configuration public class FreeMarkerConfig { @Autowired private FreeMarkerViewResolver viewResolver; @Autowired private freemarker.template.Configuration configuration; - @Value("${r'${server.servlet.context-path}'}") - private String context; private String suffix = ".ftl"; @PostConstruct public void setSharedVariable() throws TemplateModelException { // 全局共享变量、函数 - configuration.setSharedVariable("context", context); + configuration.setSharedVariable("context", LocalData.getProp("server.servlet.context-path")); configuration.setSharedVariable("screenHolder", new ScreenHolder()); configuration.setSharedVariable("controlHolder", new ControlHolder()); configuration.setSharedVariable("UrlUtil", new UrlUtil()); diff --git a/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java b/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java index 23f0acb5..bc75c58d 100644 --- a/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java @@ -1,6 +1,5 @@ package ${basePackage}.config; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.access.AccessDeniedException; @@ -34,18 +33,9 @@ import java.util.regex.Pattern; @EnableGlobalMethodSecurity(securedEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { - @Value("${r'${web.url.auth.included}'}") - private String[] included; - @Value("${r'${web.url.auth.excluded}'}") - private String[] excluded; - @Value("${r'${spring.mvc.static-path-pattern}'}") - private String[] staticPath; - @Value("${r'${web.login.page}'}") - private String loginPage; - @Override public void configure(WebSecurity web) throws Exception { - web.ignoring().mvcMatchers(staticPath); + web.ignoring().mvcMatchers(LocalData.getProp("spring.mvc.static-path-pattern")); } @Override @@ -54,8 +44,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .and() .addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token .authorizeRequests() - .antMatchers(excluded).permitAll()// 放行排除的URL - .antMatchers(included).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL + .antMatchers(LocalData.getProp("web.url.auth.excluded")).permitAll()// 放行排除的URL + .antMatchers(LocalData.getProp("web.url.auth.included")).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL .and().cors() .and().headers().frameOptions().disable() .and().csrf().disable(); diff --git a/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java b/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java index 0ec11175..1916df86 100644 --- a/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java @@ -10,6 +10,7 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import ${basePackage}.frame.auth.LocalData; import ${basePackage}.frame.utils.LogUtil; import javax.servlet.http.HttpServletRequest; @@ -19,11 +20,6 @@ import java.util.List; @Configuration public class WebMvcConfig implements WebMvcConfigurer { - @Value("${r'${web.welcome.page}'}") - private String homePage; - @Value("${r'${spring.mvc.static-path-pattern}'}") - private String[] staticPath; - /** * 增加全局拦截器,可用于异常日志的收集 * @@ -43,7 +39,7 @@ public class WebMvcConfig implements WebMvcConfigurer { } } - }).addPathPatterns("/**").excludePathPatterns(staticPath); + }).addPathPatterns("/**").excludePathPatterns(LocalData.getProp("spring.mvc.static-path-pattern")); } /**