diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index e69de29..ee9f695 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 53bb56e..0711d5b 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,3 @@
-
@@ -22,5 +21,7 @@
-
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 351a24d..9b79cc1 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,90 +4,54 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
@@ -106,6 +70,12 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/etl-auth/etl-auth-common/pom.xml b/etl-auth/etl-auth-common/pom.xml
index 819a14f..7c9a605 100644
--- a/etl-auth/etl-auth-common/pom.xml
+++ b/etl-auth/etl-auth-common/pom.xml
@@ -16,6 +16,10 @@
2.6.13
+
+ com.baomidou
+ mybatis-plus-boot-starter
+
org.springframework.boot
spring-boot-starter-jdbc
@@ -36,6 +40,12 @@
spring-boot-starter-test
test
+
+ io.swagger
+ swagger-annotations
+ 1.6.6
+ compile
+
diff --git a/etl-auth/etl-auth-common/src/main/java/com/auth/common/entity/PathPermission.java b/etl-auth/etl-auth-common/src/main/java/com/auth/common/entity/PathPermission.java
new file mode 100644
index 0000000..43726c2
--- /dev/null
+++ b/etl-auth/etl-auth-common/src/main/java/com/auth/common/entity/PathPermission.java
@@ -0,0 +1,33 @@
+package com.auth.common.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@TableName("t_data_source")
+public class PathPermission {
+ @TableId(value = "id",type = IdType.AUTO)
+ private Integer id;
+
+ @ApiModelProperty(value = "权限代号")
+ private String permissionCode;
+
+ @ApiModelProperty(value = "路由层次")
+ private String hierarchy;
+
+ @ApiModelProperty(value = "路由")
+ private String path;
+
+ @ApiModelProperty(value = "功能描述")
+ private String description;
+
+ @ApiModelProperty(value = "状态 0-废弃 1-正在使用")
+ private boolean status;
+}
diff --git a/etl-auth/etl-auth-common/src/main/java/com/auth/common/entity/RolesPermission.java b/etl-auth/etl-auth-common/src/main/java/com/auth/common/entity/RolesPermission.java
new file mode 100644
index 0000000..7860c7d
--- /dev/null
+++ b/etl-auth/etl-auth-common/src/main/java/com/auth/common/entity/RolesPermission.java
@@ -0,0 +1,24 @@
+package com.auth.common.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@TableName("t_role_source")
+@AllArgsConstructor
+@NoArgsConstructor
+public class RolesPermission {
+ @TableId(value = "id",type = IdType.AUTO)
+ private Integer id;
+
+ @ApiModelProperty(value = "权限代号")
+ private String permissionCode;
+
+ @ApiModelProperty(value = "角色")
+ private String role;
+}
diff --git a/etl-auth/etl-auth-common/src/main/java/com/auth/common/entity/UserAccount.java b/etl-auth/etl-auth-common/src/main/java/com/auth/common/entity/UserAccount.java
new file mode 100644
index 0000000..897184c
--- /dev/null
+++ b/etl-auth/etl-auth-common/src/main/java/com/auth/common/entity/UserAccount.java
@@ -0,0 +1,23 @@
+package com.auth.common.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@TableName("t_user")
+public class UserAccount {
+ @TableId(value = "id",type = IdType.AUTO)
+ private Integer id;
+
+ @ApiModelProperty("角色")
+ private String roles;
+
+ @ApiModelProperty("名称")
+ private String username;
+
+ @ApiModelProperty("密码/")
+ private String password;
+}
diff --git a/etl-auth/etl-auth-common/src/main/java/com/auth/common/enums/PermissionConstants.java b/etl-auth/etl-auth-common/src/main/java/com/auth/common/enums/PermissionConstants.java
new file mode 100644
index 0000000..a9c314c
--- /dev/null
+++ b/etl-auth/etl-auth-common/src/main/java/com/auth/common/enums/PermissionConstants.java
@@ -0,0 +1,8 @@
+package com.auth.common.enums;
+
+public class PermissionConstants {
+ public static final String ROLES = "roles";
+ public static final String CODE_LIST = "codeList";
+ public static final String ROLE = "role";
+ public static final String PERMISSION_CODE = "permission_code";
+}
diff --git a/etl-auth/etl-auth-server/pom.xml b/etl-auth/etl-auth-server/pom.xml
index 0018d6c..ad9687d 100644
--- a/etl-auth/etl-auth-server/pom.xml
+++ b/etl-auth/etl-auth-server/pom.xml
@@ -2,11 +2,12 @@
4.0.0
- com.auth.server
+
+ com.bwie
+ etl-auth
+ 1.0-SNAPSHOT
+
etl-auth-server
- 0.0.1-SNAPSHOT
- etl-auth-server
- etl-auth-server
1.8
UTF-8
@@ -15,10 +16,32 @@
2021.0.5.0
+
+
+ org.apache.shiro
+ shiro-spring
+ 1.4.0
+
+
+ io.springfox
+ springfox-swagger2
+ 3.0.0
+
com.bwie
etl-jwt-manage
1.0-SNAPSHOT
+
+
+ servlet-api
+ javax.servlet
+
+
+
+
+ com.bwie
+ etl-auth-common
+ 1.0-SNAPSHOT
com.bwie
diff --git a/etl-auth/etl-auth-server/src/main/java/com/auth/server/EtlAuthServerApplication.java b/etl-auth/etl-auth-server/src/main/java/com/auth/server/EtlAuthServerApplication.java
index af67fbb..c4c4638 100644
--- a/etl-auth/etl-auth-server/src/main/java/com/auth/server/EtlAuthServerApplication.java
+++ b/etl-auth/etl-auth-server/src/main/java/com/auth/server/EtlAuthServerApplication.java
@@ -3,9 +3,12 @@ package com.auth.server;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@MapperScan("com.auth.server.mapper")
+@ComponentScan(basePackages = {"com.etl.jwt.util", "com.etl.jwt.config",
+ "com.auth.server.controller","com.auth.server.service","com.auth.server.service.impl"})
public class EtlAuthServerApplication {
public static void main(String[] args) {
diff --git a/etl-auth/etl-auth-server/src/main/java/com/auth/server/config/ShiroConfig.java b/etl-auth/etl-auth-server/src/main/java/com/auth/server/config/ShiroConfig.java
index 5acdff3..ced631e 100644
--- a/etl-auth/etl-auth-server/src/main/java/com/auth/server/config/ShiroConfig.java
+++ b/etl-auth/etl-auth-server/src/main/java/com/auth/server/config/ShiroConfig.java
@@ -3,6 +3,8 @@ package com.auth.server.config;
import com.auth.server.util.UserRealm;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
+import org.apache.shiro.mgt.DefaultSecurityManager;
+import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
@@ -66,4 +68,5 @@ public class ShiroConfig {
return hashedCredentialsMatcher;
}
+
}
diff --git a/etl-auth/etl-auth-server/src/main/java/com/auth/server/controller/LoginControler.java b/etl-auth/etl-auth-server/src/main/java/com/auth/server/controller/LoginControler.java
index 245c841..74b3da8 100644
--- a/etl-auth/etl-auth-server/src/main/java/com/auth/server/controller/LoginControler.java
+++ b/etl-auth/etl-auth-server/src/main/java/com/auth/server/controller/LoginControler.java
@@ -1,29 +1,33 @@
package com.auth.server.controller;
import com.alibaba.nacos.api.model.v2.Result;
-import com.auth.server.entity.UserAccount;
+import com.auth.common.entity.UserAccount;
import com.auth.server.service.UserManageService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.etl.common.enums.ResponseCodeEnum;
+import com.etl.common.result.CommonResult;
import com.etl.jwt.util.JwtTokenUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.authc.AuthenticationException;
-import org.apache.shiro.authc.IncorrectCredentialsException;
-import org.apache.shiro.authc.UnknownAccountException;
-import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.authc.*;
+import org.apache.shiro.mgt.DefaultSecurityManager;
+import org.apache.shiro.realm.SimpleAccountRealm;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
+/**
+ * 登录 controller层
+ */
@RestController
@Slf4j
@Api(tags = "登录-API")
+@RequestMapping("/user")
public class LoginControler {
@Autowired
private UserManageService userManageService;
@@ -35,15 +39,27 @@ public class LoginControler {
{
String username=user.getUsername();
String password=user.getPassword();
+
+ // 创建SimpleAccountRealm并添加账户信息
+ SimpleAccountRealm simpleAccountRealm = new SimpleAccountRealm();
+ // 确保这里添加的用户名和密码与用户提供的匹配
+ simpleAccountRealm.addAccount(username, password, user.getRoles());
+
+ // 配置SecurityManager并设置Realm
+ DefaultSecurityManager securityManager = new DefaultSecurityManager(simpleAccountRealm);
+ SecurityUtils.setSecurityManager(securityManager);
+
//shiro验证
Subject subject= SecurityUtils.getSubject();
+ log.info("!11"+subject);
//根据用户名密码生成一个令牌
- UsernamePasswordToken token=new UsernamePasswordToken(username,password);
+ AuthenticationToken token=new UsernamePasswordToken(username,password);
+
try {
//执行登录操作
subject.login(token);
} catch (UnknownAccountException e) {
- log.info("登录用户不存在");
+ log.info("登录用户不存在:{}",e);
return new Result<>(416,"用户不存在",username);
} catch (IncorrectCredentialsException e) {
log.info("登录密码错误");
@@ -61,4 +77,59 @@ public class LoginControler {
userManageService.getOne(new QueryWrapper().eq("username",username)).getRoles();
return Result.success(tokenMap);
}
+
+ /**
+ * 刷新JWT令牌,用旧的令牌换新的令牌
+ * 参数为需要刷新的令牌
+ * header中携带刷新令牌
+ */
+
+ /**
+ * 当认证服务返回给客户端的 JWT 也就是 access_token 过期后,客户端如果需要再次通过发送登录请求重新拿到 access_token会使得用户体验很不友好。
+ * 而JWT 生成后是不能篡改里面的内容,即使是 JWT 的有效期也不行。所以延长 access_token 有效期的做法并不适合,而且如果长期保持一个 access_token 有效,
+ * 也是不安全的。所以我们时常使用refresh token来进行token的刷新。
+ *
+ * 我们一般会把 refresh_token 设置的过期时间稍微长一点,比如两倍于 access_token,当 access_token 过期后,refresh_token 如果还没有过期,
+ * 就可以利用两者的过期时间差进行重新生成令牌的操作,也就是刷新令牌,同时删除掉redis中缓存的旧令牌。
+ * @param token
+ * @return
+ */
+ @GetMapping("/token/refresh")
+ public CommonResult