From c843dcdfe3e5fc13c01a564ba3c8e9e9799f282e Mon Sep 17 00:00:00 2001 From: wangbing <1919101440@qq.com> Date: Thu, 24 Oct 2019 00:12:26 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manger/callable/SpringBootCallable.java | 6 ++--- .../SpringBoot/java/action/ajax/AuthAjax.java | 13 ---------- .../java/action/ajax/system/AuthAjax.java | 26 +++++++++++++++++++ .../java/config/SecurityConfig.java | 2 +- .../SpringBoot/java/config/WebMvcConfig.java | 9 ++++++- .../SpringBoot/resources/application-dev.ftl | 2 +- .../SpringBoot/resources/templates/403.ftl | 4 +-- .../resources/templates/layout/index.ftl | 2 +- 8 files changed, 42 insertions(+), 22 deletions(-) delete mode 100644 src/main/resources/modules/SpringBoot/java/action/ajax/AuthAjax.java create mode 100644 src/main/resources/modules/SpringBoot/java/action/ajax/system/AuthAjax.java diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java index db048745..9cd23b47 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java @@ -213,15 +213,15 @@ public class SpringBootCallable implements Callable { control.mkdirs(); File ajax = new File(root.getAbsolutePath(), "ajax"); ajax.mkdirs(); - File auth = new File(root.getAbsolutePath(), "auth"); - auth.mkdirs(); + File system = new File(ajax.getAbsolutePath(), "system"); + system.mkdirs(); File screen = new File(root.getAbsolutePath(), "screen"); screen.mkdirs(); freeMarkerManager.outputTemp(new File(control.getAbsolutePath(), "Footer.java"), option + "/java/action/control/Footer.java", ctx); freeMarkerManager.outputTemp(new File(control.getAbsolutePath(), "Header.java"), option + "/java/action/control/Header.java", ctx); - freeMarkerManager.outputTemp(new File(ajax.getAbsolutePath(), "AuthAjax.java"), option + "/java/action/ajax/system/AuthAjax.java", ctx); + freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "AuthAjax.java"), option + "/java/action/ajax/system/AuthAjax.java", ctx); freeMarkerManager.outputTemp(new File(screen.getAbsolutePath(), "Index.java"), option + "/java/action/screen/Index.java", ctx); diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/AuthAjax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/AuthAjax.java deleted file mode 100644 index 3b6003e0..00000000 --- a/src/main/resources/modules/SpringBoot/java/action/ajax/AuthAjax.java +++ /dev/null @@ -1,13 +0,0 @@ -package ${basePackage}.action.ajax.${moudle}; - -import ${basePackage}.frame.base.Ajax; -import ${basePackage}.frame.base.BaseResponse; - -public class UserAjax extends Ajax { - - public BaseResponse create(String param) { - BaseResponse baseResponse = new BaseResponse(); - - return baseResponse; - } -} diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/system/AuthAjax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/system/AuthAjax.java new file mode 100644 index 00000000..d8c95d09 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/system/AuthAjax.java @@ -0,0 +1,26 @@ +package ${basePackage}.action.ajax.system; + +import ${basePackage}.frame.base.Ajax; +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.frame.base.BaseResponse; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class AuthAjax extends Ajax { + + public BaseResponse login(String param) { + BaseResponse baseResponse = new BaseResponse(); + + // todo 设置cookie + HttpServletRequest request = LocalData.getRequest(); + HttpServletResponse response = LocalData.getResponse(); + Cookie token = new Cookie("token", ""); + token.setDomain(request.getServerName()); + token.setPath("/"); + response.addCookie(token); + + return baseResponse; + } +} diff --git a/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java b/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java index 4cfce623..5a553fd9 100644 --- a/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/SecurityConfig.java @@ -72,7 +72,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { //继承临时Token token1.addResourceSet(LocalData.getTempToken()); //管理员特有资源(这边请用正则表达式) - token1.putResource(".*\\.htm"); + token1.putResource(".*"); LocalData.setToken(token1); } diff --git a/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java b/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java index af92d99c..855522b8 100644 --- a/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/WebMvcConfig.java @@ -28,6 +28,8 @@ public class WebMvcConfig implements WebMvcConfigurer { @Value("${r'${web.welcome.page}'}") private String homePage; + @Value("${r'${spring.mvc.static-path-pattern}'}") + private String[] staticPath; /** * 增加全局拦截器,可用于 @@ -38,6 +40,11 @@ public class WebMvcConfig implements WebMvcConfigurer { public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new HandlerInterceptorAdapter() { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + return super.preHandle(request, response, handler); + } + @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { super.postHandle(request, response, handler, modelAndView); @@ -61,7 +68,7 @@ public class WebMvcConfig implements WebMvcConfigurer { } } - }).addPathPatterns("/**/*.htm").order(-1); + }).addPathPatterns("/**").excludePathPatterns(staticPath); } /** diff --git a/src/main/resources/modules/SpringBoot/resources/application-dev.ftl b/src/main/resources/modules/SpringBoot/resources/application-dev.ftl index c280cefa..e9dadf6c 100644 --- a/src/main/resources/modules/SpringBoot/resources/application-dev.ftl +++ b/src/main/resources/modules/SpringBoot/resources/application-dev.ftl @@ -76,4 +76,4 @@ web.login.page=/login.htm # 拦截验证 web.url.auth.included=/,/**/*.htm # 直接放行 -web.url.auth.excluded=/login.htm,/index.htm \ No newline at end of file +web.url.auth.excluded=/login.htm,/index.htm,/home.htm \ No newline at end of file diff --git a/src/main/resources/modules/SpringBoot/resources/templates/403.ftl b/src/main/resources/modules/SpringBoot/resources/templates/403.ftl index a1646512..8a8b9bdb 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/403.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/403.ftl @@ -70,7 +70,7 @@
- 返回上页 登录 + 返回上页 登录