mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-10-21 11:07:23 +08:00
修复 sa-token-core 中的代码警告
This commit is contained in:
@@ -79,7 +79,7 @@ public class SaManager {
|
||||
|
||||
/**
|
||||
* 获取 Sa-Token 的全局配置信息
|
||||
* @return
|
||||
* @return 全局配置信息
|
||||
*/
|
||||
public static SaTokenConfig getConfig() {
|
||||
if (config == null) {
|
||||
@@ -275,7 +275,7 @@ public class SaManager {
|
||||
/**
|
||||
* StpLogic 集合, 记录框架所有成功初始化的 StpLogic
|
||||
*/
|
||||
public static Map<String, StpLogic> stpLogicMap = new LinkedHashMap<String, StpLogic>();
|
||||
public static Map<String, StpLogic> stpLogicMap = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* 向全局集合中 put 一个 StpLogic
|
||||
|
@@ -160,7 +160,7 @@ public interface SaGetValueInterface {
|
||||
|
||||
// 如果 obj 为 null,则直接返回默认值
|
||||
if(valueIsNull(value)) {
|
||||
return (T)defaultValue;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
// 开始转换类型
|
||||
|
@@ -34,14 +34,14 @@ public interface SaSetValueInterface extends SaGetValueInterface {
|
||||
* @param value 值
|
||||
* @return 对象自身
|
||||
*/
|
||||
public abstract SaSetValueInterface set(String key, Object value);
|
||||
SaSetValueInterface set(String key, Object value);
|
||||
|
||||
/**
|
||||
* 删值
|
||||
* @param key 要删除的key
|
||||
* @return 对象自身
|
||||
*/
|
||||
public abstract SaSetValueInterface delete(String key);
|
||||
SaSetValueInterface delete(String key);
|
||||
|
||||
|
||||
// --------- 接口提供封装的方法
|
||||
@@ -55,7 +55,7 @@ public interface SaSetValueInterface extends SaGetValueInterface {
|
||||
* @return 值
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public default <T> T get(String key, SaRetFunction fun) {
|
||||
default <T> T get(String key, SaRetFunction fun) {
|
||||
Object value = get(key);
|
||||
if(value == null) {
|
||||
value = fun.run();
|
||||
@@ -70,8 +70,8 @@ public interface SaSetValueInterface extends SaGetValueInterface {
|
||||
* @param value 值
|
||||
* @return 对象自身
|
||||
*/
|
||||
public default SaSetValueInterface setByNull(String key, Object value) {
|
||||
if(has(key) == false) {
|
||||
default SaSetValueInterface setByNull(String key, Object value) {
|
||||
if( ! has(key)) {
|
||||
set(key, value);
|
||||
}
|
||||
return this;
|
||||
|
@@ -54,7 +54,7 @@ public class SaBasicTemplate {
|
||||
String authorization = SaHolder.getRequest().getHeader("Authorization");
|
||||
|
||||
// 如果不是以 Basic 作为前缀,则视为无效
|
||||
if(authorization == null || authorization.startsWith("Basic ") == false) {
|
||||
if(authorization == null || ! authorization.startsWith("Basic ")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class SaBasicTemplate {
|
||||
account = SaManager.getConfig().getBasic();
|
||||
}
|
||||
String authorization = getAuthorizationValue();
|
||||
if(SaFoxUtil.isEmpty(authorization) || authorization.equals(account) == false) {
|
||||
if(SaFoxUtil.isEmpty(authorization) || ! authorization.equals(account)) {
|
||||
throwNotBasicAuthException(realm);
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ public class SaSignConfig {
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* 接口调用时的时间戳允许的差距(单位:ms),-1代表不校验差距,默认15分钟
|
||||
* 接口调用时的时间戳允许的差距(单位:ms),-1 代表不校验差距,默认15分钟
|
||||
*
|
||||
* <p> 比如此处你配置了60秒,当一个请求从 client 发起后,如果 server 端60秒内没有处理,60秒后再想处理就无法校验通过了。</p>
|
||||
* <p> timestamp + nonce 有效防止重放攻击。 </p>
|
||||
@@ -63,7 +63,7 @@ public class SaSignConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 接口调用时的时间戳允许的差距(单位:ms),-1代表不校验差距,默认15分钟
|
||||
* 获取 接口调用时的时间戳允许的差距(单位:ms),-1 代表不校验差距,默认15分钟
|
||||
*
|
||||
* <p> 比如此处你配置了60秒,当一个请求从 client 发起后,如果 server 端60秒内没有处理,60秒后再想处理就无法校验通过了。</p>
|
||||
* <p> timestamp + nonce 有效防止重放攻击。 </p>
|
||||
@@ -75,7 +75,7 @@ public class SaSignConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 接口调用时的时间戳允许的差距(单位:ms),-1代表不校验差距,默认15分钟
|
||||
* 设置 接口调用时的时间戳允许的差距(单位:ms),-1 代表不校验差距,默认15分钟
|
||||
*
|
||||
* <p> 比如此处你配置了60秒,当一个请求从 client 发起后,如果 server 端60秒内没有处理,60秒后再想处理就无法校验通过了。</p>
|
||||
* <p> timestamp + nonce 有效防止重放攻击。 </p>
|
||||
|
@@ -22,8 +22,11 @@ import java.io.Serializable;
|
||||
/**
|
||||
* Sa-Token 配置类 Model
|
||||
*
|
||||
* <p> 你可以通过yml、properties、java代码等形式配置本类参数,具体请查阅官方文档: https://sa-token.cc/ </p>
|
||||
*
|
||||
* <p>
|
||||
* 你可以通过yml、properties、java代码等形式配置本类参数,具体请查阅官方文档:
|
||||
* <a href="https://sa-token.cc">https://sa-token.cc</a>
|
||||
* </p>
|
||||
*
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
@@ -34,7 +37,7 @@ public class SaTokenConfig implements Serializable {
|
||||
/** token 名称 (同时也是: cookie 名称、提交 token 时参数的名称、存储 token 时的 key 前缀) */
|
||||
private String tokenName = "satoken";
|
||||
|
||||
/** token 有效期(单位:秒) 默认30天,-1代表永久 */
|
||||
/** token 有效期(单位:秒) 默认30天,-1 代表永久 */
|
||||
private long timeout = 60 * 60 * 24 * 30;
|
||||
|
||||
/**
|
||||
@@ -89,7 +92,7 @@ public class SaTokenConfig implements Serializable {
|
||||
private String tokenStyle = "uuid";
|
||||
|
||||
/**
|
||||
* 默认 SaTokenDao 实现类中,每次清理过期数据间隔的时间(单位: 秒),默认值30秒,设置为-1代表不启动定时清理
|
||||
* 默认 SaTokenDao 实现类中,每次清理过期数据间隔的时间(单位: 秒),默认值30秒,设置为 -1 代表不启动定时清理
|
||||
*/
|
||||
private int dataRefreshPeriod = 30;
|
||||
|
||||
@@ -186,14 +189,14 @@ public class SaTokenConfig implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return token 有效期(单位:秒) 默认30天,-1代表永久
|
||||
* @return token 有效期(单位:秒) 默认30天,-1 代表永久
|
||||
*/
|
||||
public long getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timeout token 有效期(单位:秒) 默认30天,-1代表永久
|
||||
* @param timeout token 有效期(单位:秒) 默认30天,-1 代表永久
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaTokenConfig setTimeout(long timeout) {
|
||||
@@ -364,14 +367,14 @@ public class SaTokenConfig implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 默认 SaTokenDao 实现类中,每次清理过期数据间隔的时间(单位: 秒),默认值30秒,设置为-1代表不启动定时清理
|
||||
* @return 默认 SaTokenDao 实现类中,每次清理过期数据间隔的时间(单位: 秒),默认值30秒,设置为 -1 代表不启动定时清理
|
||||
*/
|
||||
public int getDataRefreshPeriod() {
|
||||
return dataRefreshPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataRefreshPeriod 默认 SaTokenDao 实现类中,每次清理过期数据间隔的时间(单位: 秒),默认值30秒,设置为-1代表不启动定时清理
|
||||
* @param dataRefreshPeriod 默认 SaTokenDao 实现类中,每次清理过期数据间隔的时间(单位: 秒),默认值30秒,设置为 -1 代表不启动定时清理
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaTokenConfig setDataRefreshPeriod(int dataRefreshPeriod) {
|
||||
|
@@ -61,9 +61,9 @@ public class SaTokenConfigFactory {
|
||||
*/
|
||||
public static SaTokenConfig createConfig(String path) {
|
||||
Map<String, String> map = readPropToMap(path);
|
||||
if (map == null) {
|
||||
// if (map == null) {
|
||||
// throw new RuntimeException("找不到配置文件:" + configPath, null);
|
||||
}
|
||||
// }
|
||||
return (SaTokenConfig) initPropByMap(map, new SaTokenConfig());
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class SaTokenConfigFactory {
|
||||
* @return 一个Map
|
||||
*/
|
||||
private static Map<String, String> readPropToMap(String propertiesPath) {
|
||||
Map<String, String> map = new HashMap<String, String>(16);
|
||||
Map<String, String> map = new HashMap<>(16);
|
||||
try {
|
||||
InputStream is = SaTokenConfigFactory.class.getClassLoader().getResourceAsStream(propertiesPath);
|
||||
if (is == null) {
|
||||
@@ -101,11 +101,11 @@ public class SaTokenConfigFactory {
|
||||
private static Object initPropByMap(Map<String, String> map, Object obj) {
|
||||
|
||||
if (map == null) {
|
||||
map = new HashMap<String, String>(16);
|
||||
map = new HashMap<>(16);
|
||||
}
|
||||
|
||||
// 1、取出类型
|
||||
Class<?> cs = null;
|
||||
Class<?> cs;
|
||||
if (obj instanceof Class) {
|
||||
// 如果是一个类型,则将obj=null,以便完成静态属性反射赋值
|
||||
cs = (Class<?>) obj;
|
||||
|
@@ -34,7 +34,7 @@ public class SaTokenContextForThreadLocalStorage {
|
||||
/**
|
||||
* 基于 ThreadLocal 的 [ Box 存储器 ]
|
||||
*/
|
||||
public static ThreadLocal<Box> boxThreadLocal = new InheritableThreadLocal<Box>();
|
||||
public static ThreadLocal<Box> boxThreadLocal = new InheritableThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 初始化当前线程的 [ Box 存储器 ]
|
||||
@@ -45,14 +45,14 @@ public class SaTokenContextForThreadLocalStorage {
|
||||
public static void setBox(SaRequest request, SaResponse response, SaStorage storage) {
|
||||
Box bok = new Box(request, response, storage);
|
||||
boxThreadLocal.set(bok);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除当前线程的 [ Box 存储器 ]
|
||||
*/
|
||||
public static void clearBox() {
|
||||
boxThreadLocal.remove();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前线程的 [ Box 存储器 ]
|
||||
@@ -60,7 +60,7 @@ public class SaTokenContextForThreadLocalStorage {
|
||||
*/
|
||||
public static Box getBox() {
|
||||
return boxThreadLocal.get();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前线程的 [ Box 存储器 ], 如果为空则抛出异常
|
||||
@@ -72,7 +72,7 @@ public class SaTokenContextForThreadLocalStorage {
|
||||
throw new InvalidContextException("未能获取有效的上下文").setCode(SaErrorCode.CODE_10002);
|
||||
}
|
||||
return box;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 在当前线程的 SaRequest 包装对象
|
||||
@@ -108,10 +108,6 @@ public class SaTokenContextForThreadLocalStorage {
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
/**
|
||||
* @author click33
|
||||
*
|
||||
*/
|
||||
public static class Box {
|
||||
|
||||
public SaRequest request;
|
||||
|
@@ -48,7 +48,7 @@ public class SaCookie {
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 有效时长 (单位:秒),-1代表为临时Cookie 浏览器关闭后自动删除
|
||||
* 有效时长 (单位:秒),-1 代表为临时Cookie 浏览器关闭后自动删除
|
||||
*/
|
||||
private int maxAge = -1;
|
||||
|
||||
@@ -129,14 +129,14 @@ public class SaCookie {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 有效时长 (单位:秒),-1代表为临时Cookie 浏览器关闭后自动删除
|
||||
* @return 有效时长 (单位:秒),-1 代表为临时Cookie 浏览器关闭后自动删除
|
||||
*/
|
||||
public int getMaxAge() {
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxAge 有效时长 (单位:秒),-1代表为临时Cookie 浏览器关闭后自动删除
|
||||
* @param maxAge 有效时长 (单位:秒),-1 代表为临时Cookie 浏览器关闭后自动删除
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaCookie setMaxAge(int maxAge) {
|
||||
@@ -236,7 +236,7 @@ public class SaCookie {
|
||||
/**
|
||||
* 构建一下
|
||||
*/
|
||||
public void builde() {
|
||||
public void builder() {
|
||||
if(path == null) {
|
||||
path = "/";
|
||||
}
|
||||
@@ -247,7 +247,7 @@ public class SaCookie {
|
||||
* @return /
|
||||
*/
|
||||
public String toHeaderValue() {
|
||||
this.builde();
|
||||
this.builder();
|
||||
|
||||
if(SaFoxUtil.isEmpty(name)) {
|
||||
throw new SaTokenException("name不能为空").setCode(SaErrorCode.CODE_12002);
|
||||
|
@@ -34,14 +34,14 @@ public interface SaRequest {
|
||||
* 获取底层被包装的源对象
|
||||
* @return /
|
||||
*/
|
||||
public Object getSource();
|
||||
Object getSource();
|
||||
|
||||
/**
|
||||
* 在 [ 请求体 ] 里获取一个参数值
|
||||
* @param name 键
|
||||
* @return 值
|
||||
*/
|
||||
public String getParam(String name);
|
||||
String getParam(String name);
|
||||
|
||||
/**
|
||||
* 在 [ 请求体 ] 里获取一个参数值,值为空时返回默认值
|
||||
@@ -49,7 +49,7 @@ public interface SaRequest {
|
||||
* @param defaultValue 值为空时的默认值
|
||||
* @return 值
|
||||
*/
|
||||
public default String getParam(String name, String defaultValue) {
|
||||
default String getParam(String name, String defaultValue) {
|
||||
String value = getParam(name);
|
||||
if(SaFoxUtil.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
@@ -63,7 +63,7 @@ public interface SaRequest {
|
||||
* @param value 值
|
||||
* @return 是否相等
|
||||
*/
|
||||
public default boolean isParam(String name, String value) {
|
||||
default boolean isParam(String name, String value) {
|
||||
String paramValue = getParam(name);
|
||||
return SaFoxUtil.isNotEmpty(paramValue) && paramValue.equals(value);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public interface SaRequest {
|
||||
* @param name 参数名称
|
||||
* @return 是否提供
|
||||
*/
|
||||
public default boolean hasParam(String name) {
|
||||
default boolean hasParam(String name) {
|
||||
return SaFoxUtil.isNotEmpty(getParam(name));
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public interface SaRequest {
|
||||
* @param name 键
|
||||
* @return 参数值
|
||||
*/
|
||||
public default String getParamNotNull(String name) {
|
||||
default String getParamNotNull(String name) {
|
||||
String paramValue = getParam(name);
|
||||
if(SaFoxUtil.isEmpty(paramValue)) {
|
||||
throw new SaTokenException("缺少参数:" + name).setCode(SaErrorCode.CODE_12001);
|
||||
@@ -94,20 +94,20 @@ public interface SaRequest {
|
||||
* 获取 [ 请求体 ] 里提交的所有参数名称
|
||||
* @return 参数名称列表
|
||||
*/
|
||||
public List<String> getParamNames();
|
||||
List<String> getParamNames();
|
||||
|
||||
/**
|
||||
* 获取 [ 请求体 ] 里提交的所有参数
|
||||
* @return 参数列表
|
||||
*/
|
||||
public Map<String, String> getParamMap();
|
||||
Map<String, String> getParamMap();
|
||||
|
||||
/**
|
||||
* 在 [ 请求头 ] 里获取一个值
|
||||
* @param name 键
|
||||
* @return 值
|
||||
*/
|
||||
public String getHeader(String name);
|
||||
String getHeader(String name);
|
||||
|
||||
/**
|
||||
* 在 [ 请求头 ] 里获取一个值
|
||||
@@ -115,7 +115,7 @@ public interface SaRequest {
|
||||
* @param defaultValue 值为空时的默认值
|
||||
* @return 值
|
||||
*/
|
||||
public default String getHeader(String name, String defaultValue) {
|
||||
default String getHeader(String name, String defaultValue) {
|
||||
String value = getHeader(name);
|
||||
if(SaFoxUtil.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
@@ -128,20 +128,20 @@ public interface SaRequest {
|
||||
* @param name 键
|
||||
* @return 值
|
||||
*/
|
||||
public String getCookieValue(String name);
|
||||
String getCookieValue(String name);
|
||||
|
||||
/**
|
||||
* 返回当前请求path (不包括上下文名称)
|
||||
* @return /
|
||||
*/
|
||||
public String getRequestPath();
|
||||
String getRequestPath();
|
||||
|
||||
/**
|
||||
* 返回当前请求 path 是否为指定值
|
||||
* @param path path
|
||||
* @return /
|
||||
*/
|
||||
public default boolean isPath(String path) {
|
||||
default boolean isPath(String path) {
|
||||
return getRequestPath().equals(path);
|
||||
}
|
||||
|
||||
@@ -149,19 +149,19 @@ public interface SaRequest {
|
||||
* 返回当前请求的url,不带query参数,例:http://xxx.com/test
|
||||
* @return /
|
||||
*/
|
||||
public String getUrl();
|
||||
String getUrl();
|
||||
|
||||
/**
|
||||
* 返回当前请求的类型
|
||||
* @return /
|
||||
*/
|
||||
public String getMethod();
|
||||
String getMethod();
|
||||
|
||||
/**
|
||||
* 判断此请求是否为 Ajax 异步请求
|
||||
* @return /
|
||||
*/
|
||||
public default boolean isAjax() {
|
||||
default boolean isAjax() {
|
||||
return getHeader("X-Requested-With") != null;
|
||||
}
|
||||
|
||||
@@ -170,6 +170,6 @@ public interface SaRequest {
|
||||
* @param path 转发地址
|
||||
* @return 任意值
|
||||
*/
|
||||
public Object forward(String path);
|
||||
Object forward(String path);
|
||||
|
||||
}
|
||||
|
@@ -26,19 +26,19 @@ public interface SaResponse {
|
||||
/**
|
||||
* 指定前端可以获取到哪些响应头时使用的参数名
|
||||
*/
|
||||
public static final String ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
|
||||
String ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
|
||||
|
||||
/**
|
||||
* 获取底层被包装的源对象
|
||||
* @return /
|
||||
*/
|
||||
public Object getSource();
|
||||
Object getSource();
|
||||
|
||||
/**
|
||||
* 删除指定Cookie
|
||||
* @param name Cookie名称
|
||||
*/
|
||||
public default void deleteCookie(String name) {
|
||||
default void deleteCookie(String name) {
|
||||
addCookie(name, null, null, null, 0);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public interface SaResponse {
|
||||
* @param path Cookie 路径
|
||||
* @param domain Cookie 作用域
|
||||
*/
|
||||
public default void deleteCookie(String name, String path, String domain) {
|
||||
default void deleteCookie(String name, String path, String domain) {
|
||||
addCookie(name, null, path, domain, 0);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public interface SaResponse {
|
||||
* @param domain Cookie的作用域
|
||||
* @param timeout 过期时间 (秒)
|
||||
*/
|
||||
public default void addCookie(String name, String value, String path, String domain, int timeout) {
|
||||
default void addCookie(String name, String value, String path, String domain, int timeout) {
|
||||
this.addCookie(new SaCookie(name, value).setPath(path).setDomain(domain).setMaxAge(timeout));
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public interface SaResponse {
|
||||
* 写入指定Cookie
|
||||
* @param cookie Cookie-Model
|
||||
*/
|
||||
public default void addCookie(SaCookie cookie) {
|
||||
default void addCookie(SaCookie cookie) {
|
||||
this.addHeader(SaCookie.HEADER_NAME, cookie.toHeaderValue());
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public interface SaResponse {
|
||||
* @param sc 响应状态码
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaResponse setStatus(int sc);
|
||||
SaResponse setStatus(int sc);
|
||||
|
||||
/**
|
||||
* 在响应头里写入一个值
|
||||
@@ -85,7 +85,7 @@ public interface SaResponse {
|
||||
* @param value 值
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaResponse setHeader(String name, String value);
|
||||
SaResponse setHeader(String name, String value);
|
||||
|
||||
/**
|
||||
* 在响应头里添加一个值
|
||||
@@ -93,14 +93,14 @@ public interface SaResponse {
|
||||
* @param value 值
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaResponse addHeader(String name, String value);
|
||||
SaResponse addHeader(String name, String value);
|
||||
|
||||
/**
|
||||
* 在响应头写入 [Server] 服务器名称
|
||||
* @param value 服务器名称
|
||||
* @return 对象自身
|
||||
*/
|
||||
public default SaResponse setServer(String value) {
|
||||
default SaResponse setServer(String value) {
|
||||
return this.setHeader("Server", value);
|
||||
}
|
||||
|
||||
@@ -109,6 +109,6 @@ public interface SaResponse {
|
||||
* @param url 重定向地址
|
||||
* @return 任意值
|
||||
*/
|
||||
public Object redirect(String url);
|
||||
Object redirect(String url);
|
||||
|
||||
}
|
||||
|
@@ -31,20 +31,20 @@ public interface SaStorage extends SaSetValueInterface {
|
||||
* 获取底层被包装的源对象
|
||||
* @return /
|
||||
*/
|
||||
public Object getSource();
|
||||
Object getSource();
|
||||
|
||||
// ---- 实现接口存取值方法
|
||||
|
||||
/** 取值 */
|
||||
@Override
|
||||
public Object get(String key);
|
||||
Object get(String key);
|
||||
|
||||
/** 写值 */
|
||||
@Override
|
||||
public SaStorage set(String key, Object value);
|
||||
SaStorage set(String key, Object value);
|
||||
|
||||
/** 删值 */
|
||||
@Override
|
||||
public SaStorage delete(String key);
|
||||
SaStorage delete(String key);
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,3 @@
|
||||
/**
|
||||
* 因为不能确定最终运行的 web 容器属于标准 Servlet 模型还是非 Servlet 模型,特封装此包下的包装类进行对接。
|
||||
* 调用路径为:Sa-Token 功能函数 -> SaRequest 封装接口 -> SaRequest 具体实现类。
|
||||
*/
|
||||
/*
|
||||
* Copyright 2020-2099 sa-token.cc
|
||||
*
|
||||
@@ -17,4 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* 因为不能确定最终运行的 web 容器属于标准 Servlet 模型还是非 Servlet 模型,特封装此包下的包装类进行对接。
|
||||
* 调用路径为:Sa-Token 功能函数 -> SaRequest 封装接口 -> SaRequest 具体实现类。
|
||||
*/
|
||||
package cn.dev33.satoken.context.model;
|
@@ -28,6 +28,6 @@ public interface SaTokenSecondContextCreator {
|
||||
* 创建一个二级 Context 处理器
|
||||
* @return /
|
||||
*/
|
||||
public SaTokenSecondContext create();
|
||||
SaTokenSecondContext create();
|
||||
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ package cn.dev33.satoken.dao;
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -218,9 +217,8 @@ public class SaTokenDaoDefaultImpl implements SaTokenDao {
|
||||
* 清理所有已经过期的 key
|
||||
*/
|
||||
public void refreshDataMap() {
|
||||
Iterator<String> keys = expireMap.keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
clearKeyByTimeout(keys.next());
|
||||
for (String s : expireMap.keySet()) {
|
||||
clearKeyByTimeout(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +239,7 @@ public class SaTokenDaoDefaultImpl implements SaTokenDao {
|
||||
try {
|
||||
try {
|
||||
// 如果已经被标记为结束
|
||||
if(refreshFlag == false) {
|
||||
if( ! refreshFlag) {
|
||||
return;
|
||||
}
|
||||
// 执行清理
|
||||
@@ -254,7 +252,7 @@ public class SaTokenDaoDefaultImpl implements SaTokenDao {
|
||||
if(dataRefreshPeriod <= 0) {
|
||||
dataRefreshPeriod = 1;
|
||||
}
|
||||
Thread.sleep(dataRefreshPeriod * 1000);
|
||||
Thread.sleep(dataRefreshPeriod * 1000L);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@@ -38,32 +38,32 @@ public class DisableServiceException extends SaTokenException {
|
||||
/**
|
||||
* 账号类型
|
||||
*/
|
||||
private String loginType;
|
||||
private final String loginType;
|
||||
|
||||
/**
|
||||
* 被封禁的账号id
|
||||
*/
|
||||
private Object loginId;
|
||||
private final Object loginId;
|
||||
|
||||
/**
|
||||
* 具体被封禁的服务
|
||||
*/
|
||||
private String service;
|
||||
private final String service;
|
||||
|
||||
/**
|
||||
* 具体被封禁的等级
|
||||
*/
|
||||
private int level;
|
||||
private final int level;
|
||||
|
||||
/**
|
||||
* 校验时要求低于的等级
|
||||
*/
|
||||
private int limitLevel;
|
||||
private final int limitLevel;
|
||||
|
||||
/**
|
||||
* 封禁剩余时间,单位:秒
|
||||
*/
|
||||
private long disableTime;
|
||||
private final long disableTime;
|
||||
|
||||
/**
|
||||
* 获取:账号类型
|
||||
|
@@ -74,7 +74,7 @@ public class NotLoginException extends SaTokenException {
|
||||
/**
|
||||
* 异常类型
|
||||
*/
|
||||
private String type;
|
||||
private final String type;
|
||||
|
||||
/**
|
||||
* 获取异常类型
|
||||
@@ -88,7 +88,7 @@ public class NotLoginException extends SaTokenException {
|
||||
/**
|
||||
* 账号类型
|
||||
*/
|
||||
private String loginType;
|
||||
private final String loginType;
|
||||
|
||||
/**
|
||||
* 获得账号类型
|
||||
@@ -129,7 +129,7 @@ public class NotLoginException extends SaTokenException {
|
||||
* @return 构建完毕的异常对象
|
||||
*/
|
||||
public static NotLoginException newInstance(String loginType, String type, String token) {
|
||||
String message = null;
|
||||
String message;
|
||||
if(NOT_TOKEN.equals(type)) {
|
||||
message = NOT_TOKEN_MESSAGE;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class NotLoginException extends SaTokenException {
|
||||
else {
|
||||
message = DEFAULT_MESSAGE;
|
||||
}
|
||||
if(SaFoxUtil.isEmpty(token) == false) {
|
||||
if( ! SaFoxUtil.isEmpty(token)) {
|
||||
message = message + ":" + token;
|
||||
}
|
||||
return new NotLoginException(message, loginType, type);
|
||||
|
@@ -31,7 +31,7 @@ public class NotPermissionException extends SaTokenException {
|
||||
private static final long serialVersionUID = 6806129545290130141L;
|
||||
|
||||
/** 权限码 */
|
||||
private String permission;
|
||||
private final String permission;
|
||||
|
||||
/**
|
||||
* @return 获得具体缺少的权限码
|
||||
@@ -43,7 +43,7 @@ public class NotPermissionException extends SaTokenException {
|
||||
/**
|
||||
* 账号类型
|
||||
*/
|
||||
private String loginType;
|
||||
private final String loginType;
|
||||
|
||||
/**
|
||||
* 获得账号类型
|
||||
|
@@ -31,7 +31,7 @@ public class NotRoleException extends SaTokenException {
|
||||
private static final long serialVersionUID = 8243974276159004739L;
|
||||
|
||||
/** 角色标识 */
|
||||
private String role;
|
||||
private final String role;
|
||||
|
||||
/**
|
||||
* @return 获得角色标识
|
||||
@@ -43,7 +43,7 @@ public class NotRoleException extends SaTokenException {
|
||||
/**
|
||||
* 账号类型
|
||||
*/
|
||||
private String loginType;
|
||||
private final String loginType;
|
||||
|
||||
/**
|
||||
* 获得账号类型
|
||||
|
@@ -34,17 +34,17 @@ public class NotSafeException extends SaTokenException {
|
||||
/**
|
||||
* 账号类型
|
||||
*/
|
||||
private String loginType;
|
||||
private final String loginType;
|
||||
|
||||
/**
|
||||
* 未通过校验的 Token 值
|
||||
*/
|
||||
private Object tokenValue;
|
||||
private final Object tokenValue;
|
||||
|
||||
/**
|
||||
* 未通过校验的服务
|
||||
*/
|
||||
private String service;
|
||||
private final String service;
|
||||
|
||||
/**
|
||||
* 获取:账号类型
|
||||
|
@@ -40,6 +40,6 @@ public class SaJsonTemplateDefaultImpl implements SaJsonTemplate {
|
||||
@Override
|
||||
public Map<String, Object> parseJsonToMap(String jsonStr) {
|
||||
throw new NotImplException(ERROR_MESSAGE).setCode(SaErrorCode.CODE_10003);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ public enum SaHttpMethod {
|
||||
*/
|
||||
public static SaHttpMethod toEnum(String method) {
|
||||
if(method == null) {
|
||||
throw new SaTokenException("无效Method:" + method).setCode(SaErrorCode.CODE_10321);
|
||||
throw new SaTokenException("Method 不可以是 null").setCode(SaErrorCode.CODE_10321);
|
||||
}
|
||||
SaHttpMethod reqMethod = map.get(method.toUpperCase());
|
||||
if(reqMethod == null) {
|
||||
|
@@ -71,7 +71,7 @@ public class SaSameTemplate {
|
||||
* @param token /
|
||||
*/
|
||||
public void checkToken(String token) {
|
||||
if(isValid(token) == false) {
|
||||
if( ! isValid(token)) {
|
||||
token = (token == null ? "" : token);
|
||||
throw new SameTokenInvalidException("无效Same-Token:" + token).setCode(SaErrorCode.CODE_10301);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class SaSameTemplate {
|
||||
|
||||
// 1. 先将当前 Same-Token 写入到 Past-Same-Token 中
|
||||
String sameToken = getTokenNh();
|
||||
if(SaFoxUtil.isEmpty(sameToken) == false) {
|
||||
if( ! SaFoxUtil.isEmpty(sameToken)) {
|
||||
savePastToken(sameToken, getTokenTimeout());
|
||||
}
|
||||
|
||||
|
@@ -46,6 +46,7 @@ import java.security.SecureRandom;
|
||||
* @author Damien Miller
|
||||
* @since 4.1.1
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class BCrypt {
|
||||
// BCrypt parameters
|
||||
private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10;
|
||||
|
@@ -15,12 +15,9 @@
|
||||
*/
|
||||
package cn.dev33.satoken.secure;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
import cn.dev33.satoken.error.SaErrorCode;
|
||||
import cn.dev33.satoken.exception.SaTokenException;
|
||||
|
||||
/**
|
||||
* Sa-Token Base64 工具类
|
||||
*
|
||||
@@ -29,8 +26,8 @@ import cn.dev33.satoken.exception.SaTokenException;
|
||||
*/
|
||||
public class SaBase64Util {
|
||||
|
||||
private static Base64.Encoder encoder = Base64.getEncoder();
|
||||
private static Base64.Decoder decoder = Base64.getDecoder();
|
||||
private static final Base64.Encoder encoder = Base64.getEncoder();
|
||||
private static final Base64.Decoder decoder = Base64.getDecoder();
|
||||
|
||||
/**
|
||||
* Base64编码,byte[] 转 String
|
||||
@@ -56,11 +53,7 @@ public class SaBase64Util {
|
||||
* @return Base64格式字符串
|
||||
*/
|
||||
public static String encode(String text){
|
||||
try {
|
||||
return encoder.encodeToString(text.getBytes("UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new SaTokenException(e).setCode(SaErrorCode.CODE_12101);
|
||||
}
|
||||
return encoder.encodeToString(text.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,11 +62,7 @@ public class SaBase64Util {
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String decode(String base64Text){
|
||||
try {
|
||||
return new String(decoder.decode(base64Text), "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new SaTokenException(e).setCode(SaErrorCode.CODE_12101);
|
||||
}
|
||||
return new String(decoder.decode(base64Text), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
package cn.dev33.satoken.secure;
|
||||
|
||||
import cn.dev33.satoken.error.SaErrorCode;
|
||||
import cn.dev33.satoken.exception.SaTokenException;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.*;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
@@ -33,14 +33,6 @@ import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import cn.dev33.satoken.error.SaErrorCode;
|
||||
import cn.dev33.satoken.exception.SaTokenException;
|
||||
|
||||
/**
|
||||
* Sa-Token 常见加密算法工具类
|
||||
*
|
||||
@@ -55,12 +47,12 @@ public class SaSecureUtil {
|
||||
/**
|
||||
* Base64编码
|
||||
*/
|
||||
private static Base64.Encoder encoder = Base64.getEncoder();
|
||||
private static final Base64.Encoder encoder = Base64.getEncoder();
|
||||
|
||||
/**
|
||||
* Base64解码
|
||||
*/
|
||||
private static Base64.Decoder decoder = Base64.getDecoder();
|
||||
private static final Base64.Decoder decoder = Base64.getDecoder();
|
||||
|
||||
// ----------------------- 摘要加密 -----------------------
|
||||
|
||||
@@ -133,8 +125,8 @@ public class SaSecureUtil {
|
||||
byte[] bytes = messageDigest.digest();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String temp;
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
temp = Integer.toHexString(bytes[i] & 0xFF);
|
||||
for (byte aByte : bytes) {
|
||||
temp = Integer.toHexString(aByte & 0xFF);
|
||||
if (temp.length() == 1) {
|
||||
builder.append("0");
|
||||
}
|
||||
@@ -205,8 +197,7 @@ public class SaSecureUtil {
|
||||
* 生成加密秘钥
|
||||
* @param password 秘钥
|
||||
* @return SecretKeySpec
|
||||
* @throws NoSuchAlgorithmException
|
||||
*/
|
||||
*/
|
||||
private static SecretKeySpec getSecretKey(final String password) throws NoSuchAlgorithmException {
|
||||
KeyGenerator kg = KeyGenerator.getInstance("AES");
|
||||
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
||||
@@ -243,7 +234,7 @@ public class SaSecureUtil {
|
||||
RSAPublicKey rsaPublicKey = (RSAPublicKey) keyPair.getPublic();
|
||||
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
|
||||
|
||||
HashMap<String, String> map = new HashMap<String, String>(16);
|
||||
HashMap<String, String> map = new HashMap<>(16);
|
||||
map.put("private", encoder.encodeToString(rsaPrivateKey.getEncoded()));
|
||||
map.put("public", encoder.encodeToString(rsaPublicKey.getEncoded()));
|
||||
return map;
|
||||
@@ -397,7 +388,7 @@ public class SaSecureUtil {
|
||||
// 数据拆分后的组数,余数不为0时加1
|
||||
int quotient = remainder != 0 ? bytes.length / splitLength + 1 : bytes.length / splitLength;
|
||||
byte[][] arrays = new byte[quotient][];
|
||||
byte[] array = null;
|
||||
byte[] array;
|
||||
for (int i = 0; i < quotient; i++) {
|
||||
// 如果是最后一组(quotient-1),同时余数不等于0,就将最后一组设置为remainder的长度
|
||||
if (i == quotient - 1 && remainder != 0) {
|
||||
@@ -415,10 +406,10 @@ public class SaSecureUtil {
|
||||
/** 将字节数组转换成16进制字符串 */
|
||||
private static String bytesToHexString(byte[] bytes) {
|
||||
|
||||
StringBuffer sb = new StringBuffer(bytes.length);
|
||||
String temp = null;
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
temp = Integer.toHexString(0xFF & bytes[i]);
|
||||
StringBuilder sb = new StringBuilder(bytes.length);
|
||||
String temp;
|
||||
for (byte aByte : bytes) {
|
||||
temp = Integer.toHexString(0xFF & aByte);
|
||||
if (temp.length() < 2) {
|
||||
sb.append(0);
|
||||
}
|
||||
|
@@ -453,7 +453,7 @@ public class SaSession implements SaSetValueInterface, Serializable {
|
||||
*/
|
||||
@Override
|
||||
public SaSession setByNull(String key, Object value) {
|
||||
if(has(key) == false) {
|
||||
if( ! has(key)) {
|
||||
dataMap.put(key, value);
|
||||
update();
|
||||
}
|
||||
|
@@ -287,6 +287,7 @@ public class SaSignTemplate {
|
||||
* @param paramMap 待校验的请求参数集合
|
||||
* @return 是否合法
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public boolean isValidParamMap(Map<String, String> paramMap) {
|
||||
// 获取必须的三个参数
|
||||
String timestampValue = paramMap.get(timestamp);
|
||||
|
@@ -240,17 +240,14 @@ public class SaLoginModel {
|
||||
* @return /
|
||||
*/
|
||||
public boolean isSetExtraData() {
|
||||
if(extraData == null || extraData.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return extraData != null && extraData.size() != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Cookie时长
|
||||
*/
|
||||
public int getCookieTimeout() {
|
||||
if(getIsLastingCookieOrFalse() == false) {
|
||||
if( ! getIsLastingCookieOrFalse()) {
|
||||
return -1;
|
||||
}
|
||||
if(getTimeoutOrGlobalConfig() == SaTokenDao.NEVER_EXPIRE) {
|
||||
|
@@ -37,7 +37,7 @@ public interface StpInterface {
|
||||
* @param loginType 账号类型
|
||||
* @return 该账号id具有的权限码集合
|
||||
*/
|
||||
public List<String> getPermissionList(Object loginId, String loginType);
|
||||
List<String> getPermissionList(Object loginId, String loginType);
|
||||
|
||||
/**
|
||||
* 返回指定账号id所拥有的角色标识集合
|
||||
@@ -46,6 +46,6 @@ public interface StpInterface {
|
||||
* @param loginType 账号类型
|
||||
* @return 该账号id具有的角色标识集合
|
||||
*/
|
||||
public List<String> getRoleList(Object loginId, String loginType);
|
||||
List<String> getRoleList(Object loginId, String loginType);
|
||||
|
||||
}
|
||||
|
@@ -30,12 +30,12 @@ public class StpInterfaceDefaultImpl implements StpInterface {
|
||||
|
||||
@Override
|
||||
public List<String> getPermissionList(Object loginId, String loginType) {
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRoleList(Object loginId, String loginType) {
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -235,9 +235,9 @@ public class StpLogic {
|
||||
|
||||
// 2. 如果打开了前缀模式,则裁剪掉它
|
||||
String tokenPrefix = getConfig().getTokenPrefix();
|
||||
if(SaFoxUtil.isEmpty(tokenPrefix) == false) {
|
||||
if(SaFoxUtil.isNotEmpty(tokenPrefix)) {
|
||||
// 如果 token 并没有按照指定的前缀开头,则视为未提供token
|
||||
if(SaFoxUtil.isEmpty(tokenValue) || tokenValue.startsWith(tokenPrefix + SaTokenConsts.TOKEN_CONNECTOR_CHAT) == false) {
|
||||
if(SaFoxUtil.isEmpty(tokenValue) || ! tokenValue.startsWith(tokenPrefix + SaTokenConsts.TOKEN_CONNECTOR_CHAT)) {
|
||||
tokenValue = null;
|
||||
} else {
|
||||
// 裁剪掉前缀
|
||||
@@ -443,7 +443,7 @@ public class StpLogic {
|
||||
// 1、获取全局配置的 isConcurrent 参数
|
||||
// 如果配置为:不允许一个账号多地同时登录,则需要先将这个账号的历史登录会话标记为:被顶下线
|
||||
Boolean isConcurrent = getConfig().getIsConcurrent();
|
||||
if(isConcurrent == false) {
|
||||
if( ! isConcurrent) {
|
||||
replaced(id, loginModel.getDevice());
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ public class StpLogic {
|
||||
return loginModel.getToken();
|
||||
}
|
||||
|
||||
// 3、只有在配置了 [ 允许一个账号多地同时登录 ] 时,才尝试复用旧 token,这样可以避免不必须的查询,节省开销
|
||||
// 3、只有在配置了 [ 允许一个账号多地同时登录 ] 时,才尝试复用旧 token,这样可以避免不必要地查询,节省开销
|
||||
if(isConcurrent) {
|
||||
|
||||
// 3.1、看看全局配置的 IsShare 参数,配置为 true 才是允许复用旧 token
|
||||
@@ -1625,7 +1625,7 @@ public class StpLogic {
|
||||
* @param role 角色标识
|
||||
*/
|
||||
public void checkRole(String role) {
|
||||
if(hasRole(role) == false) {
|
||||
if( ! hasRole(role)) {
|
||||
throw new NotRoleException(role, this.loginType).setCode(SaErrorCode.CODE_11041);
|
||||
}
|
||||
}
|
||||
@@ -1763,7 +1763,7 @@ public class StpLogic {
|
||||
* @param permission 权限码
|
||||
*/
|
||||
public void checkPermission(String permission) {
|
||||
if(hasPermission(permission) == false) {
|
||||
if( ! hasPermission(permission)) {
|
||||
throw new NotPermissionException(permission, this.loginType).setCode(SaErrorCode.CODE_11051);
|
||||
}
|
||||
}
|
||||
@@ -2010,13 +2010,11 @@ public class StpLogic {
|
||||
}
|
||||
} catch (NotPermissionException e) {
|
||||
// 权限认证校验未通过,再开始角色认证校验
|
||||
if(at.orRole().length > 0) {
|
||||
for (String role : at.orRole()) {
|
||||
String[] rArr = SaFoxUtil.convertStringToArray(role);
|
||||
// 某一项 role 认证通过,则可以提前退出了,代表通过
|
||||
if(hasRoleAnd(rArr)) {
|
||||
return;
|
||||
}
|
||||
for (String role : at.orRole()) {
|
||||
String[] rArr = SaFoxUtil.convertStringToArray(role);
|
||||
// 某一项 role 认证通过,则可以提前退出了,代表通过
|
||||
if (hasRoleAnd(rArr)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
@@ -2351,8 +2349,6 @@ public class StpLogic {
|
||||
try {
|
||||
switchTo(loginId);
|
||||
function.run();
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
endSwitch();
|
||||
}
|
||||
@@ -2439,7 +2435,7 @@ public class StpLogic {
|
||||
*/
|
||||
public void checkSafe(String service) {
|
||||
String tokenValue = getTokenValue();
|
||||
if (isSafe(tokenValue, service) == false) {
|
||||
if ( ! isSafe(tokenValue, service)) {
|
||||
throw new NotSafeException(loginType, tokenValue, service).setCode(SaErrorCode.CODE_11071);
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,6 @@ import java.util.UUID;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Sa-Token 策略对象
|
||||
|
@@ -37,7 +37,7 @@ public interface SaTempInterface {
|
||||
/**
|
||||
* 为指定 value 创建一个临时 Token
|
||||
* @param value 指定值
|
||||
* @param timeout 有效时间,单位:秒,-1代表永久有效
|
||||
* @param timeout 有效时间,单位:秒,-1 代表永久有效
|
||||
* @return 生成的 token
|
||||
*/
|
||||
default String createToken(Object value, long timeout) {
|
||||
@@ -48,7 +48,7 @@ public interface SaTempInterface {
|
||||
* 为指定 业务标识、指定 value 创建一个 Token
|
||||
* @param service 业务标识
|
||||
* @param value 指定值
|
||||
* @param timeout 有效期,单位:秒,-1代表永久有效
|
||||
* @param timeout 有效期,单位:秒,-1 代表永久有效
|
||||
* @return 生成的token
|
||||
*/
|
||||
default String createToken(String service, Object value, long timeout) {
|
||||
|
@@ -37,7 +37,7 @@ public class SaTempUtil {
|
||||
/**
|
||||
* 为指定 value 创建一个临时 Token
|
||||
* @param value 指定值
|
||||
* @param timeout 有效期,单位:秒,-1代表永久有效
|
||||
* @param timeout 有效期,单位:秒,-1 代表永久有效
|
||||
* @return 生成的token
|
||||
*/
|
||||
public static String createToken(Object value, long timeout) {
|
||||
@@ -48,7 +48,7 @@ public class SaTempUtil {
|
||||
* 为指定 业务标识、指定 value 创建一个 Token
|
||||
* @param service 业务标识
|
||||
* @param value 指定值
|
||||
* @param timeout 有效期,单位:秒,-1代表永久有效
|
||||
* @param timeout 有效期,单位:秒,-1 代表永久有效
|
||||
* @return 生成的token
|
||||
*/
|
||||
public static String createToken(String service, Object value, long timeout) {
|
||||
|
@@ -181,11 +181,9 @@ public class SaFoxUtil {
|
||||
keyword = "";
|
||||
}
|
||||
// 挑选出所有符合条件的
|
||||
List<String> list = new ArrayList<String>();
|
||||
Iterator<String> keys = dataList.iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
if (key.startsWith(prefix) && key.indexOf(keyword) > -1) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String key : dataList) {
|
||||
if (key.startsWith(prefix) && key.contains(keyword)) {
|
||||
list.add(key);
|
||||
}
|
||||
}
|
||||
@@ -205,7 +203,7 @@ public class SaFoxUtil {
|
||||
*/
|
||||
public static List<String> searchList(List<String> list, int start, int size, boolean sortType) {
|
||||
// 如果是反序的话
|
||||
if(sortType == false) {
|
||||
if( ! sortType) {
|
||||
Collections.reverse(list);
|
||||
}
|
||||
// start 至少为0
|
||||
@@ -220,7 +218,7 @@ public class SaFoxUtil {
|
||||
end = start + size;
|
||||
}
|
||||
// 取出的数据放到新集合中
|
||||
List<String> list2 = new ArrayList<String>();
|
||||
List<String> list2 = new ArrayList<>();
|
||||
for (int i = start; i < end; i++) {
|
||||
// 如果已经取到list的末尾,则直接退出
|
||||
if (i >= list.size()) {
|
||||
@@ -250,7 +248,7 @@ public class SaFoxUtil {
|
||||
return false;
|
||||
}
|
||||
// 如果表达式不带有*号,则只需简单equals即可 (这样可以使速度提升200倍左右)
|
||||
if(patt.indexOf("*") == -1) {
|
||||
if( ! patt.contains("*")) {
|
||||
return patt.equals(str);
|
||||
}
|
||||
// 正则匹配
|
||||
@@ -291,7 +289,7 @@ public class SaFoxUtil {
|
||||
}
|
||||
// 开始转换
|
||||
String obj2 = String.valueOf(obj);
|
||||
Object obj3 = null;
|
||||
Object obj3;
|
||||
if (cs.equals(String.class)) {
|
||||
obj3 = obj2;
|
||||
} else if (cs.equals(int.class) || cs.equals(Integer.class)) {
|
||||
@@ -311,7 +309,7 @@ public class SaFoxUtil {
|
||||
} else if (cs.equals(char.class) || cs.equals(Character.class)) {
|
||||
obj3 = obj2.charAt(0);
|
||||
} else {
|
||||
obj3 = (T)obj;
|
||||
obj3 = obj;
|
||||
}
|
||||
return (T)obj3;
|
||||
}
|
||||
@@ -319,12 +317,12 @@ public class SaFoxUtil {
|
||||
/**
|
||||
* 在url上拼接上kv参数并返回
|
||||
* @param url url
|
||||
* @param parameStr 参数, 例如 id=1001
|
||||
* @param paramStr 参数, 例如 id=1001
|
||||
* @return 拼接后的url字符串
|
||||
*/
|
||||
public static String joinParam(String url, String parameStr) {
|
||||
public static String joinParam(String url, String paramStr) {
|
||||
// 如果参数为空, 直接返回
|
||||
if(parameStr == null || parameStr.length() == 0) {
|
||||
if(paramStr == null || paramStr.length() == 0) {
|
||||
return url;
|
||||
}
|
||||
if(url == null) {
|
||||
@@ -333,20 +331,20 @@ public class SaFoxUtil {
|
||||
int index = url.lastIndexOf('?');
|
||||
// ? 不存在
|
||||
if(index == -1) {
|
||||
return url + '?' + parameStr;
|
||||
return url + '?' + paramStr;
|
||||
}
|
||||
// ? 是最后一位
|
||||
if(index == url.length() - 1) {
|
||||
return url + parameStr;
|
||||
return url + paramStr;
|
||||
}
|
||||
// ? 是其中一位
|
||||
if(index > -1 && index < url.length() - 1) {
|
||||
if(index < url.length() - 1) {
|
||||
String separatorChar = "&";
|
||||
// 如果最后一位是 不是&, 且 parameStr 第一位不是 &, 就增送一个 &
|
||||
if(url.lastIndexOf(separatorChar) != url.length() - 1 && parameStr.indexOf(separatorChar) != 0) {
|
||||
return url + separatorChar + parameStr;
|
||||
// 如果最后一位是 不是&, 且 paramStr 第一位不是 &, 就赠送一个 &
|
||||
if(url.lastIndexOf(separatorChar) != url.length() - 1 && paramStr.indexOf(separatorChar) != 0) {
|
||||
return url + separatorChar + paramStr;
|
||||
} else {
|
||||
return url + parameStr;
|
||||
return url + paramStr;
|
||||
}
|
||||
}
|
||||
// 正常情况下, 代码不可能执行到此
|
||||
@@ -371,12 +369,12 @@ public class SaFoxUtil {
|
||||
/**
|
||||
* 在url上拼接锚参数
|
||||
* @param url url
|
||||
* @param parameStr 参数, 例如 id=1001
|
||||
* @param paramStr 参数, 例如 id=1001
|
||||
* @return 拼接后的url字符串
|
||||
*/
|
||||
public static String joinSharpParam(String url, String parameStr) {
|
||||
public static String joinSharpParam(String url, String paramStr) {
|
||||
// 如果参数为空, 直接返回
|
||||
if(parameStr == null || parameStr.length() == 0) {
|
||||
if(paramStr == null || paramStr.length() == 0) {
|
||||
return url;
|
||||
}
|
||||
if(url == null) {
|
||||
@@ -385,20 +383,20 @@ public class SaFoxUtil {
|
||||
int index = url.lastIndexOf('#');
|
||||
// ? 不存在
|
||||
if(index == -1) {
|
||||
return url + '#' + parameStr;
|
||||
return url + '#' + paramStr;
|
||||
}
|
||||
// ? 是最后一位
|
||||
if(index == url.length() - 1) {
|
||||
return url + parameStr;
|
||||
return url + paramStr;
|
||||
}
|
||||
// ? 是其中一位
|
||||
if(index > -1 && index < url.length() - 1) {
|
||||
if(index < url.length() - 1) {
|
||||
String separatorChar = "&";
|
||||
// 如果最后一位是 不是&, 且 parameStr 第一位不是 &, 就增送一个 &
|
||||
if(url.lastIndexOf(separatorChar) != url.length() - 1 && parameStr.indexOf(separatorChar) != 0) {
|
||||
return url + separatorChar + parameStr;
|
||||
// 如果最后一位是 不是&, 且 paramStr 第一位不是 &, 就赠送一个 &
|
||||
if(url.lastIndexOf(separatorChar) != url.length() - 1 && paramStr.indexOf(separatorChar) != 0) {
|
||||
return url + separatorChar + paramStr;
|
||||
} else {
|
||||
return url + parameStr;
|
||||
return url + paramStr;
|
||||
}
|
||||
}
|
||||
// 正常情况下, 代码不可能执行到此
|
||||
@@ -455,14 +453,14 @@ public class SaFoxUtil {
|
||||
if(arr == null) {
|
||||
return "";
|
||||
}
|
||||
String str = "";
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
str += arr[i];
|
||||
str.append(arr[i]);
|
||||
if(i != arr.length - 1) {
|
||||
str += ",";
|
||||
str.append(",");
|
||||
}
|
||||
}
|
||||
return str;
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,14 +512,14 @@ public class SaFoxUtil {
|
||||
* @return 分割后的字符串集合
|
||||
*/
|
||||
public static List<String> convertStringToList(String str) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
List<String> list = new ArrayList<>();
|
||||
if(isEmpty(str)) {
|
||||
return list;
|
||||
}
|
||||
String[] arr = str.split(",");
|
||||
for (String s : arr) {
|
||||
s = s.trim();
|
||||
if(isEmpty(s) == false) {
|
||||
if(!isEmpty(s)) {
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
@@ -537,14 +535,14 @@ public class SaFoxUtil {
|
||||
if(list == null || list.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
String str = "";
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
str += list.get(i);
|
||||
str.append(list.get(i));
|
||||
if(i != list.size() - 1) {
|
||||
str += ",";
|
||||
str.append(",");
|
||||
}
|
||||
}
|
||||
return str;
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -554,7 +552,7 @@ public class SaFoxUtil {
|
||||
*/
|
||||
public static String[] convertStringToArray(String str) {
|
||||
List<String> list = convertStringToList(str);
|
||||
return list.toArray(new String[list.size()]);
|
||||
return list.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -580,15 +578,11 @@ public class SaFoxUtil {
|
||||
|
||||
/**
|
||||
* String数组转集合
|
||||
* @param strs String数组
|
||||
* @param str String数组
|
||||
* @return 集合
|
||||
*/
|
||||
public static List<String> toList(String... strs) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String str : strs) {
|
||||
list.add(str);
|
||||
}
|
||||
return list;
|
||||
public static List<String> toList(String... str) {
|
||||
return new ArrayList<>(Arrays.asList(str));
|
||||
}
|
||||
|
||||
public static List<String> logLevelList = Arrays.asList("", "trace", "debug", "info", "warn", "error", "fatal");
|
||||
@@ -622,6 +616,7 @@ public class SaFoxUtil {
|
||||
* 判断当前系统是否可以打印彩色日志,判断准确率并非100%,但基本可以满足大部分场景
|
||||
* @return /
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public static boolean isCanColorLog() {
|
||||
|
||||
// 获取当前环境相关信息
|
||||
|
@@ -86,7 +86,7 @@ public class SaResult extends LinkedHashMap<String, Object> implements Serializa
|
||||
* @return data
|
||||
*/
|
||||
public Object getData() {
|
||||
return (Object)this.get("data");
|
||||
return this.get("data");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,8 +198,9 @@ public class SaResult extends LinkedHashMap<String, Object> implements Serializa
|
||||
* 转换 value 值:
|
||||
* 如果 value 值属于 String 类型,则在前后补上引号
|
||||
* 如果 value 值属于其它类型,则原样返回
|
||||
* @param value
|
||||
* @return
|
||||
*
|
||||
* @param value 具体要操作的值
|
||||
* @return 转换后的值
|
||||
*/
|
||||
private String transValue(Object value) {
|
||||
if(value == null) {
|
||||
|
@@ -74,7 +74,7 @@ public class StrFormatter {
|
||||
final int placeHolderLength = placeHolder.length();
|
||||
|
||||
// 初始化定义好的长度以获得更好的性能
|
||||
final StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
|
||||
final StringBuilder sbu = new StringBuilder(strPatternLength + 50);
|
||||
|
||||
int handledPosition = 0;// 记录已经处理到的位置
|
||||
int delimIndex;// 占位符所在位置
|
||||
@@ -85,35 +85,35 @@ public class StrFormatter {
|
||||
return strPattern;
|
||||
}
|
||||
// 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
|
||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||
return sbuf.toString();
|
||||
sbu.append(strPattern, handledPosition, strPatternLength);
|
||||
return sbu.toString();
|
||||
}
|
||||
|
||||
// 转义符
|
||||
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) {// 转义符
|
||||
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) {// 双转义符
|
||||
// 转义符之前还有一个转义符,占位符依旧有效
|
||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbuf.append(String.valueOf(argArray[argIndex]));
|
||||
sbu.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbu.append(argArray[argIndex]);
|
||||
handledPosition = delimIndex + placeHolderLength;
|
||||
} else {
|
||||
// 占位符被转义
|
||||
argIndex--;
|
||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbuf.append(placeHolder.charAt(0));
|
||||
sbu.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbu.append(placeHolder.charAt(0));
|
||||
handledPosition = delimIndex + 1;
|
||||
}
|
||||
} else {// 正常占位符
|
||||
sbuf.append(strPattern, handledPosition, delimIndex);
|
||||
sbuf.append(String.valueOf(argArray[argIndex]));
|
||||
sbu.append(strPattern, handledPosition, delimIndex);
|
||||
sbu.append(argArray[argIndex]);
|
||||
handledPosition = delimIndex + placeHolderLength;
|
||||
}
|
||||
}
|
||||
|
||||
// 加入最后一个占位符后所有的字符
|
||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||
sbu.append(strPattern, handledPosition, strPatternLength);
|
||||
|
||||
return sbuf.toString();
|
||||
return sbu.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user