1、Properties

Former-commit-id: e791ecedc1159595c48caa5aeee99eaf3ac19474
master
wangbing 5 years ago
parent 6daba33166
commit 137efb3b95

@ -3,7 +3,6 @@ package ${basePackage}.action;
import com.fasterxml.jackson.core.TreeNode;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
@ -33,6 +32,7 @@ import ${basePackage}.frame.utils.AESUtil;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MD5Util;
import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.Properties;
import ${basePackage}.frame.utils.RequestUtil;
import javax.servlet.http.HttpServletRequest;
@ -65,10 +65,6 @@ import java.util.regex.Pattern;
@ControllerAdvice
public class GlobalController implements ErrorController {
@Value("${r'${web.welcome.page}'}")
private String homePage;
@Value("${r'${web.login.page}'}")
private String loginPage;
@Autowired
private FreeMarkerViewResolver viewResolver;
@ -115,7 +111,7 @@ public class GlobalController implements ErrorController {
return "404";
case 403:
String errorUrl = RequestUtil.getErrorUrl(request);
if ((errorUrl.equals(homePage) || errorUrl.equals("/")) && LocalData.getToken() == null) {
if ((errorUrl.equals(Properties.homePage) || errorUrl.equals("/")) && LocalData.getToken() == null) {
try {
response.sendRedirect("/login.htm");
} catch (IOException e) {
@ -134,9 +130,9 @@ public class GlobalController implements ErrorController {
public String home() {
Token token = LocalData.getToken();
if (token == null) {
return "redirect:" + loginPage;
return "redirect:" + Properties.context + Properties.loginPage;
} else {
return "redirect:" + homePage;
return "redirect:" + Properties.context + Properties.homePage;
}
}

@ -2,7 +2,6 @@ package ${basePackage}.action.ajax.system;
import com.fasterxml.jackson.core.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartFile;
import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
@ -14,6 +13,7 @@ import ${basePackage}.frame.utils.CookieUtil;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MD5Util;
import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.Properties;
import ${basePackage}.frame.utils.RequestUtil;
import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.frame.utils.ValidationUtil;
@ -50,10 +50,6 @@ import java.util.UUID;
public class UserAjax {
@Value("${r'${web.url.auth.admin}'}")
private String admin;
@Value("${r'${web.url.auth.pwd}'}")
private String pwd;
@Autowired
private TokensManager tokensManager;
@Autowired
@ -87,9 +83,9 @@ public class UserAjax {
return response;
}
if (request.getUsername().equals(admin)) {//超级管理员登录
if (request.getUsername().equals(Properties.authAdmin)) {//超级管理员登录
String generatePwd = MD5Util.generatePwd(request.getPassword());
if (!generatePwd.equals(pwd)) {
if (!generatePwd.equals(Properties.authPwd)) {
response.addError(ErrorType.BUSINESS_ERROR, "用户名或密码错误!");
} else {
Date current = new Date();
@ -100,7 +96,7 @@ public class UserAjax {
TokensCreateRequest tokensCreateRequest = new TokensCreateRequest();
tokensCreateRequest.setToken(UUID.randomUUID().toString());
tokensCreateRequest.setUserId(0L);
tokensCreateRequest.setUserName(admin);
tokensCreateRequest.setUserName(Properties.authAdmin);
tokensCreateRequest.setLoginTime(current);
tokensCreateRequest.setValidTime(instance.getTime());
tokensCreateRequest.setValid(true);

@ -5,7 +5,6 @@ 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;
@ -16,6 +15,7 @@ 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.Properties;
import ${basePackage}.frame.utils.UrlUtil;
import javax.annotation.PostConstruct;
@ -34,15 +34,13 @@ public class FreeMarkerConfig {
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", Properties.context);
configuration.setSharedVariable("screenHolder", new ScreenHolder());
configuration.setSharedVariable("controlHolder", new ControlHolder());
configuration.setSharedVariable("UrlUtil", new UrlUtil());

@ -1,8 +1,8 @@
package ${basePackage}.config;
import ${basePackage}.frame.utils.ResourceUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import ${basePackage}.frame.utils.Properties;
import ${basePackage}.frame.utils.ResourceUtil;
import javax.annotation.PostConstruct;
import java.io.File;
@ -12,13 +12,10 @@ import java.util.regex.Pattern;
@Configuration
public class SQLiteConfig {
@Value("${r'${spring.datasource.url}'}")
private String url;
@PostConstruct
public void generateDB() {
Pattern compile = Pattern.compile("jdbc:sqlite:(.*.db).*");
Matcher matcher = compile.matcher(url);
Matcher matcher = compile.matcher(Properties.datasourceUrl);
if (matcher.find()) {
String group = matcher.group(1);
File file = new File(group);

@ -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;
@ -15,6 +14,7 @@ import org.springframework.security.web.access.intercept.FilterSecurityIntercept
import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.auth.Token;
import ${basePackage}.frame.utils.CookieUtil;
import ${basePackage}.frame.utils.Properties;
import ${basePackage}.module.system.mgr.TokensManager;
import ${basePackage}.module.system.req.TokensBuildRequest;
import ${basePackage}.module.system.rsp.TokensBuildResponse;
@ -34,18 +34,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(Properties.staticPath);
}
@Override
@ -54,8 +45,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(Properties.authExcluded).permitAll()// 放行排除的URL
.antMatchers(Properties.authIncluded).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL
.and().cors()
.and().headers().frameOptions().disable()
.and().csrf().disable();

@ -3,7 +3,6 @@ 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.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@ -11,6 +10,7 @@ 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.utils.LogUtil;
import ${basePackage}.frame.utils.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -19,11 +19,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 +38,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
}
}
}).addPathPatterns("/**").excludePathPatterns(staticPath);
}).addPathPatterns("/**").excludePathPatterns(Properties.staticPath);
}
/**

@ -0,0 +1,51 @@
package ${basePackage}.frame.utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
@Configuration
public class Properties {
@Value("${r'${spring.mvc.static-path-pattern}'}")
private String[] staticPath_;
@Value("${r'${server.servlet.context-path}'}")
private String context_;
@Value("${r'${spring.datasource.url}'}")
private String datasourceUrl_;
@Value("${r'${web.home.page}'}")
private String homePage_;
@Value("${r'${web.login.page}'}")
private String loginPage_;
@Value("${r'${web.url.auth.included}'}")
private String[] authIncluded_;
@Value("${r'${web.url.auth.excluded}'}")
private String[] authExcluded_;
@Value("${r'${web.url.auth.admin}'}")
private String authAdmin_;
@Value("${r'${web.url.auth.pwd}'}")
private String authPwd_;
public static String[] staticPath;
public static String context;
public static String datasourceUrl;
public static String homePage;
public static String loginPage;
public static String[] authIncluded;
public static String[] authExcluded;
public static String authAdmin;
public static String authPwd;
@PostConstruct
public void generateDB() {
staticPath = staticPath_;
context = context_;
datasourceUrl = datasourceUrl_;
homePage = homePage_;
loginPage = loginPage_;
authIncluded = authIncluded_;
authExcluded = authExcluded_;
authAdmin = authAdmin_;
authPwd = authPwd_;
}
}

@ -4,7 +4,6 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@ -16,6 +15,7 @@ import ${basePackage}.frame.auth.Token;
import ${basePackage}.frame.utils.IDgenerator;
import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.Message;
import ${basePackage}.frame.utils.Properties;
import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.module.system.ent.Tokens;
import ${basePackage}.module.system.mpr.TokensMapper;
@ -47,8 +47,6 @@ import ${basePackage}.module.system.rsp.TokensUpdateResponse;
@Service
public class TokensManagerImpl implements ${basePackage}.module.system.mgr.TokensManager {
@Value("${r'${web.url.auth.admin}'}")
private String admin;
@Autowired
private TokensMapper tokensMapper;
@Autowired
@ -228,11 +226,11 @@ public class TokensManagerImpl implements ${basePackage}.module.system.mgr.Token
} else {
Tokens tokens = tokensFindResponse.getResult().get(0);
Token newToken = new Token();
if (tokens.getUserName().equals(admin)) {//超级管理员
if (tokens.getUserName().equals(Properties.authAdmin)) {//超级管理员
newToken.setId(0);
newToken.setToken(tokensFindResponse.getResult().get(0).getToken());
newToken.setUserId(0);
newToken.setUserName(admin);
newToken.setUserName(Properties.authAdmin);
newToken.putRes(".*");
// 获取用户的资源

@ -122,7 +122,7 @@ server.tomcat.max-http-post-size=-1
# 自定义配置
# 根路径默认页,'/'跳转至该页
web.welcome.page=/index.htm
web.home.page=/index.htm
# 登录页
web.login.page=/login.htm
# 拦截验证

@ -122,7 +122,7 @@ server.tomcat.max-http-post-size=-1
# 自定义配置
# 根路径默认页,'/'跳转至该页
web.welcome.page=/index.htm
web.home.page=/index.htm
# 登录页
web.login.page=/login.htm
# 拦截验证

@ -2,20 +2,20 @@
var jsonService = axios.create({
method: 'post',
timeout: 30000,
baseURL: '',
baseURL: '${context?default("")}',
headers: {'Content-Type': 'application/json;charset=UTF-8'},
});
var downloadService = axios.create({
method: 'post',
timeout: 30000,
baseURL: '',
baseURL: '${context?default("")}',
responseType: 'blob',
headers: {'Content-Type': 'application/json;charset=UTF-8'},
});
var uploadService = axios.create({
method: 'post',
timeout: 30000,
baseURL: '',
baseURL: '${context?default("")}',
responseType: 'blob',
headers: {'Content-Type': 'multipart/form-data'},
onUploadProgress: function (progressEvent) {

Loading…
Cancel
Save

Powered by TurnKey Linux.