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

@ -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());

@ -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();

@ -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"));
}
/**

Loading…
Cancel
Save

Powered by TurnKey Linux.