diff --git a/README.md b/README.md
index bde0402366e5262b8123212440cede38a9b1c5b7..bf9b9bdc016969705b570d65cff58c088bf63dce 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,9 @@
### 新一代 Spring Boot+Spring Security+Jwt 2.0来袭 ☟☟☟
-> 新一代基于Spring Boot、Spring Security、Oauth2等实现的权限控制和认证服务、支持第三方oauth授权和获取资源信息功能等、详情请点击下面的项目地址查看,欢迎大家使用体验,觉得不错的给个star,谢谢!
+新一代基于Spring Boot、Spring Security、Oauth2等实现的权限控制和认证服务、支持第三方oauth授权和获取资源信息功能等、详情请点击下面的项目地址查看,欢迎大家使用体验,觉得不错的给个star,谢谢!
+项目地址:https://gitee.com/micai-code/micai-platform-auth
-> 项目地址:https://gitee.com/micai-code/micai-platform-auth
-
-### RestApi接口增加JWT认证功能
+## RestApi接口增加JWT认证功能
用户填入用户名密码后,与数据库里存储的用户信息进行比对,如果通过,则认证成功。传统的方法是在认证通过后,创建sesstion,并给客户端返回cookie。
现在我们采用JWT来处理用户名密码的认证。区别在于,认证通过后,服务器生成一个token,将token返回给客户端,客户端以后的所有请求都需要在http头中指定该token。
@@ -76,9 +75,6 @@ curl -H "Content-Type: application/json"
#### 5.设置了1分钟后Token过期,如果1分钟后再次请求/users/userList接口返回Token过期的异常提示如下图:

-### 建议及改进
-若您有任何建议,可以通过发送邮件至827358369@qq.com向我反馈。本人承诺,任何
-建议都将会被认真考虑,优秀的建议将会被采用,但不保证一定会在当前版本中实现。
### 集成Swagger-ui,方便前后端分离开发,默认访问地址:http://localhost:8080/swagger-ui.html
@@ -89,7 +85,7 @@ curl -H "Content-Type: application/json"
### 加入微信交流群
-添加群主微信拉你进群,备注进群(免费哈) dlzhaoxinguo
+添加微信拉你进群,备注进群(免费哈) dlzhaoxinguo
### 加入讨论群
微信群:
@@ -98,19 +94,8 @@ curl -H "Content-Type: application/json"
QQ群:
-### 增加了刷新token的机制
-
-
-
### 更新日志
-#### 2021-11-19
-1、升级spring-boot版本为最新版本,当前版本为:2.6.0-RC1
-2、暂时注释掉swagger的集成,后续再考虑
-#### 2021-11-29
-1、增加了过滤器返回自定义异常
-2、去掉了redis的集成,更加轻量级
-3、集成了hutool工具包
-
+见wiki
diff --git a/doc/sql/image-20221227165801242.png b/doc/sql/image-20221227165801242.png
index 966fcc040e6f13bcf1d7f09c5b76b69bf09b9d66..0196a335799f1baa8b1ef1f01fef929f9bc3d70a 100644
Binary files a/doc/sql/image-20221227165801242.png and b/doc/sql/image-20221227165801242.png differ
diff --git a/pom.xml b/pom.xml
index 5878fbc356ff7f48ab195597d90e7eb1c64a2d5f..1215de2d1cd3271067d12dd500e7d6818407ce8d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
- * Author: 赵新国
+ * Author: zhaoxinguo
* Date: 2017/12/12 15:32
*/
@Configuration
diff --git a/src/main/java/boss/portal/security/WebSecurityConfig.java b/src/main/java/boss/portal/config/WebSecurityConfig.java
similarity index 84%
rename from src/main/java/boss/portal/security/WebSecurityConfig.java
rename to src/main/java/boss/portal/config/WebSecurityConfig.java
index 86eca0fb8924e89f18dda5af4fcf7934d4fd7f20..7e2051e6fb58345e3d7712606233e4eabbf7304c 100644
--- a/src/main/java/boss/portal/security/WebSecurityConfig.java
+++ b/src/main/java/boss/portal/config/WebSecurityConfig.java
@@ -1,5 +1,6 @@
-package boss.portal.security;
+package boss.portal.config;
+import boss.portal.constant.AuthWhiteList;
import boss.portal.filter.JWTAuthenticationFilter;
import boss.portal.filter.JWTLoginFilter;
import boss.portal.handler.Http401AuthenticationEntryPoint;
@@ -27,24 +28,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@EnableGlobalMethodSecurity(securedEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
- /**
- * 需要放行的URL
- */
- private static final String[] AUTH_WHITELIST = {
- // -- register url
- "/users/signup",
- "/users/addTask",
- // -- swagger ui
- "/v2/api-docs",
- "/swagger-resources",
- "/swagger-resources/**",
- "/configuration/ui",
- "/configuration/security",
- "/swagger-ui.html",
- "/webjars/**"
- // other public endpoints of your API may be appended to this array
- };
-
@Autowired
private UserDetailsService userDetailsService;
@@ -57,7 +40,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
LogoutConfigurer
- *
- * @author: 赵新国
- * @date: 2018/3/12 16:07
- */
-public class ConstantKey {
-
- /**
- * 签名key
- */
- public static final String SIGNING_KEY = "spring-security-@Jwt!&Secret^#";
-
- /**
- * 持票人
- */
- public static final String BEARER = "Bearer ";
-
- /**
- * 在头部标签中存放Token的key
- */
- public static final String HEADER_KEY = "Authorization";
+package boss.portal.constant;
+
+/**
+ * 描述:
+ *
+ *
+ * @author: zhaoxinguo
+ * @date: 2018/3/12 16:07
+ */
+public class ConstantKey {
+
+ /**
+ * 签名key
+ */
+ public static final String SIGNING_KEY = "spring-security-@Jwt!&Secret^#";
+
+ /**
+ * 持票人
+ */
+ public static final String BEARER = "Bearer ";
+
+ /**
+ * 在头部标签中存放Token的key
+ */
+ public static final String HEADER_KEY = "Authorization";
}
\ No newline at end of file
diff --git a/src/main/java/boss/portal/controller/BaseController.java b/src/main/java/boss/portal/controller/BaseController.java
index 967545f3d7f7f3b7c0a7925609732aa8c10295be..b74e70a6ded6cdb369219ce4fdb4c3d13bbc616e 100644
--- a/src/main/java/boss/portal/controller/BaseController.java
+++ b/src/main/java/boss/portal/controller/BaseController.java
@@ -1,47 +1,47 @@
-package boss.portal.controller;
-
-import boss.portal.repository.UserRepository;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * 描述:
- *
- *
- * @author: 赵新国
- * @date: 2018/6/5 18:35
- */
-public abstract class BaseController {
-
- protected Logger logger = LoggerFactory.getLogger(BaseController.class);
-
- @Autowired
- protected UserRepository userRepository;
-
- @Autowired
- protected BCryptPasswordEncoder bCryptPasswordEncoder;
-
- /**
- * 获取用户所拥有的权限列表
- * @return
- */
- public List
+ *
+ * @author: zhaoxinguo
+ * @date: 2018/6/5 18:35
+ */
+public abstract class BaseController {
+
+ protected Logger logger = LoggerFactory.getLogger(BaseController.class);
+
+ @Autowired
+ protected UserRepository userRepository;
+
+ @Autowired
+ protected BCryptPasswordEncoder bCryptPasswordEncoder;
+
+ /**
+ * 获取用户所拥有的权限列表
+ * @return
+ */
+ public List
*
- * @author: 赵新国
+ * @author: zhaoxinguo
* @date: 2018/4/11 23:06
*/
public class ServiceException extends RuntimeException {
diff --git a/src/main/java/boss/portal/filter/JWTAuthenticationFilter.java b/src/main/java/boss/portal/filter/JWTAuthenticationFilter.java
index ca4cf9b56546ebc6418bdcd882b8e2a2fd07dbba..711dd9f590e6e7e77b38a849fd2ece96bdcc9d9d 100644
--- a/src/main/java/boss/portal/filter/JWTAuthenticationFilter.java
+++ b/src/main/java/boss/portal/filter/JWTAuthenticationFilter.java
@@ -1,5 +1,6 @@
package boss.portal.filter;
+import boss.portal.constant.AuthWhiteList;
import boss.portal.constant.ConstantKey;
import boss.portal.exception.ServiceException;
import boss.portal.service.impl.GrantedAuthorityImpl;
@@ -18,9 +19,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
+import java.util.*;
/**
* 自定义JWT认证过滤器
@@ -39,11 +38,23 @@ public class JWTAuthenticationFilter extends BasicAuthenticationFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
+ String requestURI = request.getRequestURI();
String header = request.getHeader(ConstantKey.HEADER_KEY);
if (ObjectUtil.isEmpty(header) || !header.startsWith(ConstantKey.BEARER)) {
chain.doFilter(request, response);
return;
}
+
+ // 如果token不为空,并且是以指定票据开头
+ if (ObjectUtil.isNotEmpty(header) && header.startsWith(ConstantKey.BEARER)) {
+ // 如果请求路径是放行路径,则直接跳过认证
+ List
- *
- * @author: 赵新国
- * @date: 2018/6/4 20:48
- */
-public class LoginParam {
-
- private String username;
- private String password;
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-}
+package boss.portal.param;
+
+/**
+ * 描述:
+ *
+ *
+ * @author: zhaoxinguo
+ * @date: 2018/6/4 20:48
+ */
+public class LoginParam {
+
+ private String username;
+ private String password;
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
diff --git a/src/main/java/boss/portal/result/Result.java b/src/main/java/boss/portal/param/Result.java
similarity index 97%
rename from src/main/java/boss/portal/result/Result.java
rename to src/main/java/boss/portal/param/Result.java
index a2cb8b3c2d31bfea28a988c219cc11efc59d9398..6db6dcc9b8eaa9134799e06581bf114f3412e890 100644
--- a/src/main/java/boss/portal/result/Result.java
+++ b/src/main/java/boss/portal/param/Result.java
@@ -1,4 +1,4 @@
-package boss.portal.result;
+package boss.portal.param;
import java.util.HashMap;
import java.util.Map;
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index d5c53d286187fbd40b5c6f41198a63fb5b09c0e0..68729ac861fc7d1c95659c8900478d5f231fe6a3 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,15 +1,13 @@
+# JDBC Config
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=root
-
+# JPA Config
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jackson.serialization.indent_output=true
-
-# ????Springfox??????????AntPathMatcher???Spring Boot 2.6.0????PathPatternMatcher?
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
-
# JWT Config
jwt.header=Authorization
jwt.secret=NDU0NTY4amhmc3NkeHp6eGNxdzIlMjFAJTIxQCUyM2ZmNQ==
@@ -17,3 +15,8 @@ jwt.expiration=7200000
+
+
+
+
+
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000000000000000000000000000000000000..bb14b82c94d4ad85c204ef9166426ffd583a63d2
--- /dev/null
+++ b/src/main/resources/logback-spring.xml
@@ -0,0 +1,189 @@
+
+
+
+
+
+