初次提交
This commit is contained in:
parent
92528a70c1
commit
ad3f99c9ab
|
@ -5,14 +5,10 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="af4c07b7-4ec6-4591-87e0-621479a360cc" name="更改" comment="初次提交">
|
<list default="true" id="af4c07b7-4ec6-4591-87e0-621479a360cc" name="更改" comment="初次提交">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/hivekion/baseData/service/impl/TblDataModelServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/hivekion/baseData/service/impl/TblDataModelServiceImpl.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/hivekion/common/filter/JwtAuthenticationFilter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/hivekion/common/filter/JwtAuthenticationFilter.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/hivekion/baseData/service/impl/TblShipFuelServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/hivekion/baseData/service/impl/TblShipFuelServiceImpl.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/hivekion/common/security/JwtTokenUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/hivekion/common/security/JwtTokenUtils.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/hivekion/common/encrypt/AESUtil.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/hivekion/common/encrypt/AESUtil.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/hivekion/system/controller/SysAuthorityController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/hivekion/system/controller/SysAuthorityController.java" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -43,8 +39,12 @@
|
||||||
"Maven.springbootmybatis [clean].executor": "Run",
|
"Maven.springbootmybatis [clean].executor": "Run",
|
||||||
"Maven.springbootmybatis [compile].executor": "Run",
|
"Maven.springbootmybatis [compile].executor": "Run",
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
|
"RequestMappingsPanelOrder0": "0",
|
||||||
|
"RequestMappingsPanelOrder1": "1",
|
||||||
|
"RequestMappingsPanelWidth0": "75",
|
||||||
|
"RequestMappingsPanelWidth1": "75",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"Spring Boot.DemoApplication.executor": "Run",
|
"Spring Boot.DemoApplication.executor": "Debug",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
|
@ -58,6 +58,9 @@
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
|
<component name="ReactorSettings">
|
||||||
|
<option name="notificationShown" value="true" />
|
||||||
|
</component>
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<configuration name="DemoApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
|
<configuration name="DemoApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
|
||||||
<module name="springbootmybatis" />
|
<module name="springbootmybatis" />
|
||||||
|
@ -84,7 +87,7 @@
|
||||||
<updated>1754560710248</updated>
|
<updated>1754560710248</updated>
|
||||||
<workItem from="1754560714503" duration="2195000" />
|
<workItem from="1754560714503" duration="2195000" />
|
||||||
<workItem from="1754563543522" duration="8000" />
|
<workItem from="1754563543522" duration="8000" />
|
||||||
<workItem from="1754564611042" duration="517000" />
|
<workItem from="1754564611042" duration="1866000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="初次提交">
|
<task id="LOCAL-00001" summary="初次提交">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
@ -102,7 +105,15 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1754562853375</updated>
|
<updated>1754562853375</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="3" />
|
<task id="LOCAL-00003" summary="初次提交">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1754565249597</created>
|
||||||
|
<option name="number" value="00003" />
|
||||||
|
<option name="presentableId" value="LOCAL-00003" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1754565249597</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="4" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
@ -112,6 +123,17 @@
|
||||||
<MESSAGE value="初次提交" />
|
<MESSAGE value="初次提交" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="初次提交" />
|
<option name="LAST_COMMIT_MESSAGE" value="初次提交" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="XDebuggerManager">
|
||||||
|
<breakpoint-manager>
|
||||||
|
<breakpoints>
|
||||||
|
<line-breakpoint enabled="true" type="java-line">
|
||||||
|
<url>file://$PROJECT_DIR$/src/main/java/com/hivekion/common/filter/JwtAuthenticationFilter.java</url>
|
||||||
|
<line>83</line>
|
||||||
|
<option name="timeStamp" value="1" />
|
||||||
|
</line-breakpoint>
|
||||||
|
</breakpoints>
|
||||||
|
</breakpoint-manager>
|
||||||
|
</component>
|
||||||
<component name="XSLT-Support.FileAssociations.UIState">
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
<expand />
|
<expand />
|
||||||
<select />
|
<select />
|
||||||
|
|
16
pom.xml
16
pom.xml
|
@ -137,8 +137,20 @@
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
<artifactId>jjwt</artifactId>
|
<artifactId>jjwt-api</artifactId>
|
||||||
<version>0.9.1</version>
|
<version>0.11.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-impl</artifactId>
|
||||||
|
<version>0.11.5</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-jackson</artifactId>
|
||||||
|
<version>0.11.5</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--代码自动生成器的依赖-->
|
<!--代码自动生成器的依赖-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class JwtAuthenticationFilter extends BasicAuthenticationFilter {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String userName = JwtTokenUtils.getUsernameFromToken(token);
|
String userName = JwtTokenUtils.getUsernameFromToken(token);
|
||||||
log.info("");
|
|
||||||
if (StringUtils.isNotBlank(userName)) {
|
if (StringUtils.isNotBlank(userName)) {
|
||||||
Object obj = redisUtil.getUsernameByToken(token);
|
Object obj = redisUtil.getUsernameByToken(token);
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
|
|
|
@ -2,26 +2,15 @@ package com.hivekion.common.security;
|
||||||
|
|
||||||
import com.hivekion.common.entity.vo.LoginUser;
|
import com.hivekion.common.entity.vo.LoginUser;
|
||||||
import com.hivekion.common.exception.BusinessException;
|
import com.hivekion.common.exception.BusinessException;
|
||||||
import com.hivekion.system.service.ISysUserService;
|
import io.jsonwebtoken.*;
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.security.Keys;
|
||||||
import io.jsonwebtoken.Jwts;
|
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Date;
|
import java.security.Key;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JWT工具类
|
|
||||||
*
|
|
||||||
* @author Louis
|
|
||||||
* @date Jun 29, 2019
|
|
||||||
*/
|
|
||||||
public class JwtTokenUtils {
|
public class JwtTokenUtils {
|
||||||
|
|
||||||
public static final String TOKEN_PREFIX = "Bearer "; // 前缀
|
public static final String TOKEN_PREFIX = "Bearer "; // 前缀
|
||||||
|
@ -31,15 +20,20 @@ public class JwtTokenUtils {
|
||||||
private static final String USERID = Claims.ID; // 用户ID
|
private static final String USERID = Claims.ID; // 用户ID
|
||||||
private static final String CREATED = "created"; // 创建时间
|
private static final String CREATED = "created"; // 创建时间
|
||||||
private static final String AUTHORITIES = "authorities"; // 权限列表
|
private static final String AUTHORITIES = "authorities"; // 权限列表
|
||||||
private static final String SECRET = "1q2w3E*"; // 密钥
|
|
||||||
private static final long EXPIRE_TIME = 2 * 60 * 60 * 1000; // 有效期2小时
|
// 密钥长度必须大于等于 64 字节
|
||||||
@Autowired
|
private static final String SECRET = "this_is_a_very_long_secret_key_for_hs512_algorithm_1234567890!@#$%^&*()_+abcd";
|
||||||
ISysUserService userService;
|
private static final long EXPIRE_TIME = 24 * 60 * 60 * 1000; // 有效期24小时
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 新增统一的 Key 获取方法
|
||||||
|
private static Key getKey() {
|
||||||
|
return Keys.hmacShaKeyFor(SECRET.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成令牌
|
* 生成令牌
|
||||||
*
|
|
||||||
* @return 令牌
|
|
||||||
*/
|
*/
|
||||||
public static String generateToken(Authentication authentication) {
|
public static String generateToken(Authentication authentication) {
|
||||||
Map<String, Object> claims = new HashMap<>(3);
|
Map<String, Object> claims = new HashMap<>(3);
|
||||||
|
@ -49,32 +43,26 @@ public class JwtTokenUtils {
|
||||||
|
|
||||||
Date expirationDate = new Date(System.currentTimeMillis() + EXPIRE_TIME);
|
Date expirationDate = new Date(System.currentTimeMillis() + EXPIRE_TIME);
|
||||||
return Jwts.builder()
|
return Jwts.builder()
|
||||||
.setClaims(claims) //
|
.setClaims(claims)
|
||||||
.setExpiration(expirationDate) // 过期时间
|
.setExpiration(expirationDate)
|
||||||
.signWith(SignatureAlgorithm.HS512, SECRET)
|
.signWith(getKey(), SignatureAlgorithm.HS512)
|
||||||
.compact();
|
.compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从数据声明生成令牌
|
* 从数据声明生成令牌
|
||||||
*
|
|
||||||
* @param claims 数据声明
|
|
||||||
* @return 令牌
|
|
||||||
*/
|
*/
|
||||||
private static String generateToken(Map<String, Object> claims) {
|
private static String generateToken(Map<String, Object> claims) {
|
||||||
Date expirationDate = new Date(System.currentTimeMillis() + EXPIRE_TIME);
|
Date expirationDate = new Date(System.currentTimeMillis() + EXPIRE_TIME);
|
||||||
return Jwts.builder()
|
return Jwts.builder()
|
||||||
.setClaims(claims) //
|
.setClaims(claims)
|
||||||
.setExpiration(expirationDate) // 过期时间
|
.setExpiration(expirationDate)
|
||||||
.signWith(SignatureAlgorithm.HS512, SECRET)
|
.signWith(getKey(), SignatureAlgorithm.HS512)
|
||||||
.compact();
|
.compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从令牌中获取用户名
|
* 从令牌中获取用户名
|
||||||
*
|
|
||||||
* @param token 令牌
|
|
||||||
* @return 用户名
|
|
||||||
*/
|
*/
|
||||||
public static String getUsernameFromToken(String token) {
|
public static String getUsernameFromToken(String token) {
|
||||||
String username;
|
String username;
|
||||||
|
@ -89,8 +77,6 @@ public class JwtTokenUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据请求令牌获取登录认证信息
|
* 根据请求令牌获取登录认证信息
|
||||||
*
|
|
||||||
* @return 用户名
|
|
||||||
*/
|
*/
|
||||||
public static Authentication getAuthenticationeFromToken(HttpServletRequest request) {
|
public static Authentication getAuthenticationeFromToken(HttpServletRequest request) {
|
||||||
Authentication authentication = null;
|
Authentication authentication = null;
|
||||||
|
@ -114,12 +100,12 @@ public class JwtTokenUtils {
|
||||||
Object authors = claims.get(AUTHORITIES); // 权限列表
|
Object authors = claims.get(AUTHORITIES); // 权限列表
|
||||||
LoginUser user = new LoginUser();
|
LoginUser user = new LoginUser();
|
||||||
authentication =
|
authentication =
|
||||||
new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>());
|
new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>());
|
||||||
} else {
|
} else {
|
||||||
if (validateToken(token, SecurityUtils.getUsername())) {
|
if (validateToken(token, SecurityUtils.getUsername())) {
|
||||||
authentication =
|
authentication =
|
||||||
SecurityUtils
|
SecurityUtils
|
||||||
.getAuthentication(); // 如果上下文中Authentication非空,且请求令牌合法,直接返回当前登录认证信息
|
.getAuthentication(); // 如果上下文中Authentication非空,且请求令牌合法,直接返回当前登录认证信息
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,14 +114,16 @@ public class JwtTokenUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从令牌中获取数据声明
|
* 从令牌中获取数据声明
|
||||||
*
|
|
||||||
* @param token 令牌
|
|
||||||
* @return 数据声明
|
|
||||||
*/
|
*/
|
||||||
private static Claims getClaimsFromToken(String token) {
|
private static Claims getClaimsFromToken(String token) {
|
||||||
Claims claims;
|
Claims claims;
|
||||||
try {
|
try {
|
||||||
claims = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody();
|
// 这里用新版API
|
||||||
|
claims = Jwts.parserBuilder()
|
||||||
|
.setSigningKey(getKey())
|
||||||
|
.build()
|
||||||
|
.parseClaimsJws(token)
|
||||||
|
.getBody();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
claims = null;
|
claims = null;
|
||||||
}
|
}
|
||||||
|
@ -144,21 +132,14 @@ public class JwtTokenUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证令牌
|
* 验证令牌
|
||||||
*
|
|
||||||
* @param token
|
|
||||||
* @param username
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static Boolean validateToken(String token, String username) {
|
public static Boolean validateToken(String token, String username) {
|
||||||
String userName = getUsernameFromToken(token);
|
String userName = getUsernameFromToken(token);
|
||||||
return (userName.equals(username) && !isTokenExpired(token));
|
return (userName != null && userName.equals(username) && !isTokenExpired(token));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 刷新令牌
|
* 刷新令牌
|
||||||
*
|
|
||||||
* @param token
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static String refreshToken(String token) {
|
public static String refreshToken(String token) {
|
||||||
String refreshedToken;
|
String refreshedToken;
|
||||||
|
@ -174,9 +155,6 @@ public class JwtTokenUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断令牌是否过期
|
* 判断令牌是否过期
|
||||||
*
|
|
||||||
* @param token 令牌
|
|
||||||
* @return 是否过期
|
|
||||||
*/
|
*/
|
||||||
public static Boolean isTokenExpired(String token) {
|
public static Boolean isTokenExpired(String token) {
|
||||||
try {
|
try {
|
||||||
|
@ -190,9 +168,6 @@ public class JwtTokenUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求token
|
* 获取请求token
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static String getToken(HttpServletRequest request) {
|
public static String getToken(HttpServletRequest request) {
|
||||||
String token = request.getHeader("Authorization");
|
String token = request.getHeader("Authorization");
|
||||||
|
@ -208,4 +183,4 @@ public class JwtTokenUtils {
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user