Former-commit-id: a8419cd0abf8e656fef07b398caf9a65a077e865
master
wangbing 5 years ago
parent 1581f91f90
commit 80335ef7db

@ -6,6 +6,7 @@ import freemarker.template.TemplateModelException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.validation.support.BindingAwareModelMap;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@ -29,17 +30,18 @@ import static xyz.wbsite.config.ActionConfig.SCREEN_PREFIX;
@Configuration
public class FreeMarkerConfig {
@Autowired
private Environment environment;
@Autowired
private FreeMarkerViewResolver viewResolver;
@Autowired
private freemarker.template.Configuration configuration;
private String suffix = ".ftl";
@PostConstruct
public void setSharedVariable() throws TemplateModelException {
// 全局共享变量、函数
configuration.setSharedVariable("context", LocalData.getProp("server.servlet.context-path"));
configuration.setSharedVariable("context", environment.getProperty("server.servlet.context-path", "/"));
configuration.setSharedVariable("screenHolder", new ScreenHolder());
configuration.setSharedVariable("controlHolder", new ControlHolder());
configuration.setSharedVariable("UrlUtil", new UrlUtil());

@ -1,7 +1,9 @@
package ${basePackage}.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
@ -32,10 +34,12 @@ import java.util.regex.Pattern;
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private Environment environment;
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().mvcMatchers(LocalData.getProp("spring.mvc.static-path-pattern"));
web.ignoring().mvcMatchers(environment.getProperty("spring.mvc.static-path-pattern", ""));
}
@Override
@ -44,8 +48,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.and()
.addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token
.authorizeRequests()
.antMatchers(LocalData.getProp("web.url.auth.excluded")).permitAll()// 放行排除的URL
.antMatchers(LocalData.getProp("web.url.auth.included")).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL
.antMatchers(environment.getProperty("web.url.auth.excluded")).permitAll()// 放行排除的URL
.antMatchers(environment.getProperty("web.url.auth.included")).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL
.and().cors()
.and().headers().frameOptions().disable()
.and().csrf().disable();

@ -3,14 +3,16 @@ package ${basePackage}.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
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,6 +21,20 @@ import java.util.List;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
private Environment environment;
/**
*
*
* @param configurer
*/
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
AntPathMatcher matcher = new AntPathMatcher();
matcher.setCaseSensitive(false);
configurer.setPathMatcher(matcher);
}
/**
*
@ -39,7 +55,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
}
}
}).addPathPatterns("/**").excludePathPatterns(LocalData.getProp("spring.mvc.static-path-pattern"));
}).addPathPatterns("/**").excludePathPatterns(environment.getProperty("spring.mvc.static-path-pattern"));
}
/**

@ -70,7 +70,7 @@ public class LocalData {
}
public static ApplicationContext getApplicationContext() {
return ${basePackage}.frame.auth.LocalData.applicationContext;
return LocalData.applicationContext;
}
public static void setApplicationContext(ApplicationContext applicationContext) {

Loading…
Cancel
Save

Powered by TurnKey Linux.