Former-commit-id: ecf8a29945919b5d35ae4fc9293b05736a670d49
master
wangbing 5 years ago
parent 531102b1d0
commit 1581f91f90

@ -1,16 +1,10 @@
package ${basePackage}.config; 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.SimpleScalar;
import freemarker.template.TemplateMethodModelEx; import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException; import freemarker.template.TemplateModelException;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.validation.support.BindingAwareModelMap; import org.springframework.validation.support.BindingAwareModelMap;
import org.springframework.web.context.request.RequestContextHolder; 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.LocaleResolver;
import org.springframework.web.servlet.View; import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; 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.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -27,21 +24,22 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import static xyz.wbsite.config.ActionConfig.CONTROL_PREFIX;
import static xyz.wbsite.config.ActionConfig.SCREEN_PREFIX;
@Configuration @Configuration
public class FreeMarkerConfig { public class FreeMarkerConfig {
@Autowired @Autowired
private FreeMarkerViewResolver viewResolver; private FreeMarkerViewResolver viewResolver;
@Autowired @Autowired
private freemarker.template.Configuration configuration; private freemarker.template.Configuration configuration;
@Value("${r'${server.servlet.context-path}'}")
private String context;
private String suffix = ".ftl"; private String suffix = ".ftl";
@PostConstruct @PostConstruct
public void setSharedVariable() throws TemplateModelException { 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("screenHolder", new ScreenHolder());
configuration.setSharedVariable("controlHolder", new ControlHolder()); configuration.setSharedVariable("controlHolder", new ControlHolder());
configuration.setSharedVariable("UrlUtil", new UrlUtil()); configuration.setSharedVariable("UrlUtil", new UrlUtil());

@ -1,6 +1,5 @@
package ${basePackage}.config; package ${basePackage}.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
@ -34,18 +33,9 @@ import java.util.regex.Pattern;
@EnableGlobalMethodSecurity(securedEnabled = true) @EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter { 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 @Override
public void configure(WebSecurity web) throws Exception { public void configure(WebSecurity web) throws Exception {
web.ignoring().mvcMatchers(staticPath); web.ignoring().mvcMatchers(LocalData.getProp("spring.mvc.static-path-pattern"));
} }
@Override @Override
@ -54,8 +44,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.and() .and()
.addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token .addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token
.authorizeRequests() .authorizeRequests()
.antMatchers(excluded).permitAll()// 放行排除的URL .antMatchers(LocalData.getProp("web.url.auth.excluded")).permitAll()// 放行排除的URL
.antMatchers(included).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL .antMatchers(LocalData.getProp("web.url.auth.included")).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL
.and().cors() .and().cors()
.and().headers().frameOptions().disable() .and().headers().frameOptions().disable()
.and().csrf().disable(); .and().csrf().disable();

@ -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.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -19,11 +20,6 @@ import java.util.List;
@Configuration @Configuration
public class WebMvcConfig implements WebMvcConfigurer { 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"));
} }
/** /**

Loading…
Cancel
Save

Powered by TurnKey Linux.