1、Properties恢复

Former-commit-id: 62b8253c95c48d84122a99cbe703d15c231d154e
master
王兵 5 years ago
parent 137efb3b95
commit 7b4ac951c3

@ -3,6 +3,7 @@ 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;
@ -32,7 +33,6 @@ 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,6 +65,10 @@ import java.util.regex.Pattern;
@ControllerAdvice
public class GlobalController implements ErrorController {
@Value("${r'${web.home.page}'}")
private String homePage;
@Value("${r'${web.login.page}'}")
private String loginPage;
@Autowired
private FreeMarkerViewResolver viewResolver;
@ -111,7 +115,7 @@ public class GlobalController implements ErrorController {
return "404";
case 403:
String errorUrl = RequestUtil.getErrorUrl(request);
if ((errorUrl.equals(Properties.homePage) || errorUrl.equals("/")) && LocalData.getToken() == null) {
if ((errorUrl.equals(homePage) || errorUrl.equals("/")) && LocalData.getToken() == null) {
try {
response.sendRedirect("/login.htm");
} catch (IOException e) {
@ -130,9 +134,9 @@ public class GlobalController implements ErrorController {
public String home() {
Token token = LocalData.getToken();
if (token == null) {
return "redirect:" + Properties.context + Properties.loginPage;
return "redirect:" + loginPage;
} else {
return "redirect:" + Properties.context + Properties.homePage;
return "redirect:" + homePage;
}
}

@ -2,6 +2,7 @@ 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;
@ -13,7 +14,6 @@ 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,6 +50,10 @@ 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
@ -83,9 +87,9 @@ public class UserAjax {
return response;
}
if (request.getUsername().equals(Properties.authAdmin)) {//超级管理员登录
if (request.getUsername().equals(admin)) {//超级管理员登录
String generatePwd = MD5Util.generatePwd(request.getPassword());
if (!generatePwd.equals(Properties.authPwd)) {
if (!generatePwd.equals(pwd)) {
response.addError(ErrorType.BUSINESS_ERROR, "用户名或密码错误!");
} else {
Date current = new Date();
@ -96,7 +100,7 @@ public class UserAjax {
TokensCreateRequest tokensCreateRequest = new TokensCreateRequest();
tokensCreateRequest.setToken(UUID.randomUUID().toString());
tokensCreateRequest.setUserId(0L);
tokensCreateRequest.setUserName(Properties.authAdmin);
tokensCreateRequest.setUserName(admin);
tokensCreateRequest.setLoginTime(current);
tokensCreateRequest.setValidTime(instance.getTime());
tokensCreateRequest.setValid(true);

@ -5,6 +5,7 @@ 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;
@ -15,7 +16,6 @@ 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,13 +34,15 @@ 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", Properties.context);
configuration.setSharedVariable("context", context);
configuration.setSharedVariable("screenHolder", new ScreenHolder());
configuration.setSharedVariable("controlHolder", new ControlHolder());
configuration.setSharedVariable("UrlUtil", new UrlUtil());

@ -1,8 +1,8 @@
package ${basePackage}.config;
import org.springframework.context.annotation.Configuration;
import ${basePackage}.frame.utils.Properties;
import ${basePackage}.frame.utils.ResourceUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.io.File;
@ -12,10 +12,13 @@ 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(Properties.datasourceUrl);
Matcher matcher = compile.matcher(url);
if (matcher.find()) {
String group = matcher.group(1);
File file = new File(group);

@ -1,5 +1,6 @@
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;
@ -14,7 +15,6 @@ 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,9 +34,18 @@ 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(Properties.staticPath);
web.ignoring().mvcMatchers(staticPath);
}
@Override
@ -45,8 +54,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.and()
.addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token
.authorizeRequests()
.antMatchers(Properties.authExcluded).permitAll()// 放行排除的URL
.antMatchers(Properties.authIncluded).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL
.antMatchers(excluded).permitAll()// 放行排除的URL
.antMatchers(included).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL
.and().cors()
.and().headers().frameOptions().disable()
.and().csrf().disable();

@ -3,6 +3,7 @@ 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;
@ -10,7 +11,6 @@ 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,6 +19,11 @@ import java.util.List;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Value("${r'${web.home.page}'}")
private String homePage;
@Value("${r'${spring.mvc.static-path-pattern}'}")
private String[] staticPath;
/**
*
*
@ -38,7 +43,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
}
}
}).addPathPatterns("/**").excludePathPatterns(Properties.staticPath);
}).addPathPatterns("/**").excludePathPatterns(staticPath);
}
/**

@ -1,51 +0,0 @@
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,6 +4,7 @@ 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;
@ -15,7 +16,6 @@ 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,6 +47,8 @@ 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
@ -226,11 +228,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(Properties.authAdmin)) {//超级管理员
if (tokens.getUserName().equals(admin)) {//超级管理员
newToken.setId(0);
newToken.setToken(tokensFindResponse.getResult().get(0).getToken());
newToken.setUserId(0);
newToken.setUserName(Properties.authAdmin);
newToken.setUserName(admin);
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
# 拦截验证

Loading…
Cancel
Save

Powered by TurnKey Linux.