Former-commit-id: e1460d423cafe8d1dc363d514938830013853d15
master
wangbing 5 years ago
parent d11b7c5c27
commit c9334902f2

@ -5,8 +5,8 @@ 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.core.env.Environment;
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;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
@ -30,18 +30,19 @@ import static ${basePackage}.config.ActionConfig.SCREEN_PREFIX;
@Configuration @Configuration
public class FreeMarkerConfig { public class FreeMarkerConfig {
@Autowired
private Environment environment;
@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", environment.getProperty("server.servlet.context-path", "/")); configuration.setSharedVariable("context", context);
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,9 +1,8 @@
package ${basePackage}.config; package ${basePackage}.config;
import org.springframework.beans.factory.annotation.Autowired; 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.core.env.Environment;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
@ -34,12 +33,19 @@ import java.util.regex.Pattern;
@Configuration @Configuration
@EnableGlobalMethodSecurity(securedEnabled = true) @EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter { public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private Environment environment; @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(environment.getProperty("spring.mvc.static-path-pattern", "")); web.ignoring().mvcMatchers(staticPath);
} }
@Override @Override
@ -48,8 +54,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.and() .and()
.addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token .addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token
.authorizeRequests() .authorizeRequests()
.antMatchers(environment.getProperty("web.url.auth.excluded")).permitAll()// 放行排除的URL .antMatchers(excluded).permitAll()// 放行排除的URL
.antMatchers(environment.getProperty("web.url.auth.included")).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL .antMatchers(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();

@ -3,9 +3,8 @@ package ${basePackage}.config;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
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.core.env.Environment;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.util.AntPathMatcher; import org.springframework.util.AntPathMatcher;
@ -21,8 +20,11 @@ import java.util.List;
@Configuration @Configuration
public class WebMvcConfig implements WebMvcConfigurer { public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
private Environment environment; @Value("${r'${web.welcome.page}'}")
private String homePage;
@Value("${r'${spring.mvc.static-path-pattern}'}")
private String[] staticPath;
/** /**
* *
@ -55,7 +57,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
} }
} }
}).addPathPatterns("/**").excludePathPatterns(environment.getProperty("spring.mvc.static-path-pattern")); }).addPathPatterns("/**").excludePathPatterns(staticPath);
} }
/** /**

Loading…
Cancel
Save

Powered by TurnKey Linux.