review code.
This commit is contained in:
@@ -16,4 +16,12 @@ public class Const implements com.orion.lang.constant.Const {
|
||||
|
||||
public static final Integer IS_DELETED = 1;
|
||||
|
||||
public static final int BEARER_PREFIX_LEN = 7;
|
||||
|
||||
public static final int MD5_LEN = 32;
|
||||
|
||||
public static final String UNKNOWN = "未知";
|
||||
|
||||
public static final String INTRANET_IP = "内网IP";
|
||||
|
||||
}
|
||||
|
||||
@@ -13,10 +13,16 @@ public interface ErrorMessage {
|
||||
|
||||
String ID_MISSING = "id 不能为空";
|
||||
|
||||
String USERNAME_PASSWORD_ERROR = "用户名或密码错误";
|
||||
|
||||
String DATA_PRESENT = "数据已存在";
|
||||
|
||||
String DATA_ABSENT = "数据不存在";
|
||||
|
||||
String USERNAME_PASSWORD_ERROR = "用户名或密码错误";
|
||||
|
||||
String MAX_LOGIN_FAILED = "登陆失败次数已上限";
|
||||
|
||||
String USER_DISABLED = "用户已被禁用";
|
||||
|
||||
String USER_LOCKED = "用户已被锁定";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.orion.ops.framework.common.crypto;
|
||||
|
||||
import com.orion.lang.utils.codec.Base62s;
|
||||
import com.orion.lang.utils.crypto.symmetric.SymmetricCrypto;
|
||||
|
||||
/**
|
||||
@@ -16,4 +17,24 @@ public interface ValueCrypto extends SymmetricCrypto {
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* 加密后 base62 编码
|
||||
*
|
||||
* @param plain 明文
|
||||
* @return 密文
|
||||
*/
|
||||
default String encryptBase62(String plain) {
|
||||
return new String(Base62s.encode(this.encrypt(plain)));
|
||||
}
|
||||
|
||||
/**
|
||||
* base62 解码后解密
|
||||
*
|
||||
* @param text 密文
|
||||
* @return 明文
|
||||
*/
|
||||
default String decryptBase62(String text) {
|
||||
return new String(this.decrypt(Base62s.decode(text)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.orion.ops.framework.common.security;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@@ -12,26 +13,25 @@ import java.util.List;
|
||||
* @since 2023/7/6 18:36
|
||||
*/
|
||||
@Data
|
||||
@Schema(name = "LoginUser", description = "当前登录用户对象")
|
||||
public class LoginUser {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 花名
|
||||
*/
|
||||
@Schema(description = "花名")
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*/
|
||||
@Schema(description = "用户状态")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "头像地址")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "角色")
|
||||
private List<String> roles;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.orion.ops.framework.common.utils;
|
||||
|
||||
import com.orion.lang.utils.crypto.symmetric.SymmetricCrypto;
|
||||
import com.orion.ops.framework.common.crypto.ValueCrypto;
|
||||
|
||||
/**
|
||||
* 加密工具类
|
||||
@@ -11,10 +11,7 @@ import com.orion.lang.utils.crypto.symmetric.SymmetricCrypto;
|
||||
*/
|
||||
public class CryptoUtils {
|
||||
|
||||
/**
|
||||
* 加密器 供 framework 赋值
|
||||
*/
|
||||
public static SymmetricCrypto delegate;
|
||||
private static ValueCrypto delegate;
|
||||
|
||||
/**
|
||||
* 加密
|
||||
@@ -118,4 +115,28 @@ public class CryptoUtils {
|
||||
return delegate.verify(plain, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密后 base62 编码
|
||||
*
|
||||
* @param plain 明文
|
||||
* @return 密文
|
||||
*/
|
||||
public static String encryptBase62(String plain) {
|
||||
return delegate.encryptBase62(plain);
|
||||
}
|
||||
|
||||
/**
|
||||
* base62 解码后解密
|
||||
*
|
||||
* @param text 密文
|
||||
* @return 明文
|
||||
*/
|
||||
public static String decryptBase62(String text) {
|
||||
return delegate.decryptBase62(text);
|
||||
}
|
||||
|
||||
public static void setDelegate(ValueCrypto delegate) {
|
||||
CryptoUtils.delegate = delegate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.orion.ops.framework.common.utils;
|
||||
|
||||
import com.orion.ext.location.Region;
|
||||
import com.orion.ext.location.region.LocationRegions;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
|
||||
/**
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/7/14 16:26
|
||||
*/
|
||||
public class IpUtils {
|
||||
|
||||
private IpUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 ip 位置
|
||||
*
|
||||
* @param ip ip
|
||||
* @return ip 位置
|
||||
*/
|
||||
public static String getLocation(String ip) {
|
||||
if (ip == null) {
|
||||
return Const.UNKNOWN;
|
||||
}
|
||||
Region region;
|
||||
try {
|
||||
region = LocationRegions.getRegion(ip, 3);
|
||||
} catch (Exception e) {
|
||||
return Const.UNKNOWN;
|
||||
}
|
||||
if (region != null) {
|
||||
String net = region.getNet();
|
||||
String province = region.getProvince();
|
||||
if (net.equals(Const.INTRANET_IP)) {
|
||||
return net;
|
||||
}
|
||||
if (province.equals(Const.UNKNOWN)) {
|
||||
return province;
|
||||
}
|
||||
StringBuilder location = new StringBuilder()
|
||||
.append(region.getCountry())
|
||||
.append(Const.DASHED)
|
||||
.append(province)
|
||||
.append(Const.DASHED)
|
||||
.append(region.getCity());
|
||||
location.append(" (").append(net).append(')');
|
||||
return location.toString();
|
||||
}
|
||||
return Const.UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.orion.ops.framework.common.utils;
|
||||
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
|
||||
/**
|
||||
* 工具类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/7/14 16:34
|
||||
*/
|
||||
public class Kits {
|
||||
|
||||
private Kits() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登陆凭证
|
||||
*
|
||||
* @param authorization authorization
|
||||
* @return token
|
||||
*/
|
||||
public static String getAuthorization(String authorization) {
|
||||
if (Strings.isEmpty(authorization)) {
|
||||
return null;
|
||||
}
|
||||
if (!authorization.contains(Const.BEARER) || authorization.length() <= Const.BEARER_PREFIX_LEN) {
|
||||
return null;
|
||||
}
|
||||
return authorization.substring(Const.BEARER_PREFIX_LEN).trim();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user