public class AuHelper extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static Object |
authzModify(AuthzModifier authzModifier)
动态修改api权限和api的参数权限
更多操作看Dashboard
可使用
RequestBody获得,或者new AuthzModifier();
共的13个字段:1.operate 2.target 3.method, 4.api 5.value 6.index 7.range 8.resources 9.className 10.condition 11.argsMap 12.role 13.permission
operate 支持四种操作:
ADD
DELETE(DEL)
MODIFY(UPDATE)
GET(READ)
target 有3种类型 api,路径参数,请求参数 其中值一共有5钟: API PATH_VARIABLE_ROLE(PATH_VARIABLE_ROLE) PATH_VARIABLE_PERMISSION(PATH_VAR_PERMISSION) REQUEST_PARAM_ROLE(PARAM_ROLE) REQUEST_PARAM_PERMISSION(PARAM_PERMISSION) example 对于api的相关操作: 对于api的添加操作: { "operate": "add", "target": "api", "method": "get", "api": "/test/role-ada" "role": { "require": ["admin","zxc"], "exclude": ["small-black,dog", "cat","apple"] }, "permission": { ... } } 对于api的删除操作: { "operate": "del", "target": "api", "method": "get", "api": "/test/role-ada" } 对于api的修改操作:(缺失为不修改) { "operate": "modify", "target": "api", "method": "get", "api": "/test/role-ada", "role": { "require": ["admin","zxc"], "exclude": ["small-black,dog", "cat","apple"] }, "permission": { ... } } 对于api的查看操作: { "operate": "get", "target": "api", "method": "get", "api": "/test/role-ada" } example 对于参数的相关操作: 对于参数的添加操作: 1、在/test/role-ada接口上参数名为id添加限制权限限制。 |
static boolean |
checkUserIsActive(Object userId)
判断某个用户是否有设备【在线/活跃】(默认60秒内)
|
static boolean |
checkUserIsActive(Object userId,
long ms)
判断某个用户是否【在线/活跃】
|
static boolean |
checkUserIsActive(Object userId,
String time)
判断某个用户是否【在线/活跃】
|
static void |
closeAutoRefreshAndSetup(String publicKey,
String privateKey)
关闭自动刷新RSA,需要额外指定公钥私钥对
|
static String |
getRSAPrivateKey() |
static String |
getRSAPublicKey() |
static TokenPair |
login(Object userId,
String deviceType) |
static TokenPair |
login(Object userId,
String deviceType,
String deviceId) |
static void |
logout()
注销当前用户当前设备
|
static void |
logout(Object userId,
String deviceType)
注销指定用户所指定的类型的所有设备
|
static void |
logout(Object userId,
String deviceType,
String deviceId)
注销指定用户所指定的类型和id的设备
|
static void |
logout(String deviceType)
注销当前用户所指定的类型的所有设备
|
static void |
logout(String deviceType,
String deviceId)
注销当前用户所指定的类型和id的设备
|
static void |
logoutAll()
注销当前用户所有设备
|
static void |
logoutAll(Object userId)
注销指定用户所有设备,建议用于管理员,如果某用户想通过自己id注销自己,建议加上参数权限判断
|
static void |
openAutoRefresh()
打开自动刷新RSA,会将自定义的RSA关闭
|
static List<Object> |
queryActiveUsers()
所有【在线/活跃】(默认60秒内)用户Id数组
|
static List<Object> |
queryActiveUsers(long ms)
所有【在线/活跃】用户Id数组
|
static List<Object> |
queryActiveUsers(String time)
所有【在线/活跃】用户Id数组
|
static List<Device> |
queryAllDeviceByUserId(Object userId)
获得指定userId的所有设备信息
|
static List<Device> |
queryAllDeviceByUserIdAndDeviceType(Object userId,
String deviceType)
获得指定userId的所有设备信息
|
static List<Device> |
queryAllDeviceFromCurrentUser()
当前访问用户的所有设备
|
static List<Object> |
queryAllUserId() |
static Map<Object,List<Device>> |
queryAllUsersDevices()
查询所有用户信息,一个map userId->设备信息列表
|
static Device |
queryDeviceByUserIdAndDeviceTypeAndDeviceId(Object userId,
String deviceType,
String deviceId)
获得指定设备信息
|
static List<String> |
queryIpBlacklist()
获得只可观察的黑名单请求元信息
|
static Collection<RequestMeta> |
queryMetaOfIpBlacklist()
获得只可观察的黑名单请求元信息
|
static int |
queryNumberOfActiveUsers()
所有【在线/活跃】(默认60秒内)用户数量
|
static int |
queryNumberOfActiveUsers(long ms)
所有【在线/活跃】用户数量
|
static int |
queryNumberOfActiveUsers(String time)
所有【在线/活跃】用户数量
|
static TokenPair |
refreshToken(String refreshToken)
access过期刷新接口。
|
static void |
reloadCache()
重新加载所有缓存
|
static void |
reloadCache(Collection<String>... keys)
重新加载指定的缓存
|
static void |
reloadCache(String... keys)
重新加载所有缓存
|
@Nullable public static TokenPair login(@NonNull Object userId, @NonNull String deviceType)
userId - 用户id - 不为nulldeviceType - 设备系统类型 - 不为null@Nullable public static TokenPair login(@NonNull Object userId, @NonNull String deviceType, @Nullable String deviceId)
userId - 用户id - 不为nulldeviceType - 设备系统类型 - 不为nulldeviceId - 设备id - 可为null 且为 "" 时于 null等价public static void logout()
public static void logoutAll()
public static void logout(@NonNull
String deviceType)
deviceType - 指定设备类型public static void logout(@NonNull
String deviceType,
@Nullable
String deviceId)
deviceType - 指定设备类型deviceId - 指定设备idpublic static void logoutAll(@NonNull
Object userId)
userId - 用户idpublic static void logout(@NonNull
Object userId,
@NonNull
String deviceType)
userId - 用户iddeviceType - 指定设备类型public static void logout(@NonNull
Object userId,
@NonNull
String deviceType,
@Nullable
String deviceId)
userId - 用户iddeviceType - 指定设备类型deviceId - 指定设备id@Nullable public static TokenPair refreshToken(@NonNull String refreshToken)
如果使用单token,则直接使用accessToken即可,在accessToken过期时再重新登录。
使用双token时,accessToken过期时,可以利用refreshToken在此接口中刷新获得一个新的accessToken。
refreshToken - 与accessToken一起授予的refreshToken@NonNull public static Map<Object,List<Device>> queryAllUsersDevices()
@Nullable public static Device queryDeviceByUserIdAndDeviceTypeAndDeviceId(@NonNull Object userId, @NonNull String deviceType, @Nullable String deviceId)
userId - 指定userId@NonNull public static List<Device> queryAllDeviceFromCurrentUser()
@NonNull public static List<Object> queryAllUserId()
@NonNull public static List<Device> queryAllDeviceByUserId(@NonNull Object userId)
userId - 指定userId@NonNull public static List<Device> queryAllDeviceByUserIdAndDeviceType(@NonNull Object userId, @NonNull String deviceType)
userId - 指定userIdpublic static boolean checkUserIsActive(@NonNull
Object userId)
userId - 用户idpublic static boolean checkUserIsActive(@NonNull
Object userId,
@NonNull
String time)
userId - 用户idtime - 时间间隔public static boolean checkUserIsActive(@NonNull
Object userId,
long ms)
userId - 用户idms - 时间间隔(ms)public static int queryNumberOfActiveUsers()
public static int queryNumberOfActiveUsers(@NonNull
String time)
time - 时间间隔public static int queryNumberOfActiveUsers(long ms)
ms - 时间间隔(ms)@NonNull public static List<Object> queryActiveUsers()
@NonNull public static List<Object> queryActiveUsers(@NonNull String time)
time - 时间间隔@NonNull public static List<Object> queryActiveUsers(long ms)
ms - 时间间隔(ms)@NonNull public static Collection<RequestMeta> queryMetaOfIpBlacklist()
@NonNull public static List<String> queryIpBlacklist()
@Nullable public static Object authzModify(@NonNull AuthzModifier authzModifier)
RequestBody获得,或者new AuthzModifier();
共的13个字段:1.operate 2.target 3.method, 4.api 5.value 6.index 7.range 8.resources 9.className 10.condition 11.argsMap 12.role 13.permission
operate 支持四种操作:
example 对于api的相关操作:
对于api的添加操作:
{
"operate": "add",
"target": "api",
"method": "get",
"api": "/test/role-ada"
"role": {
"require": ["admin","zxc"],
"exclude": ["small-black,dog", "cat","apple"]
},
"permission": {
...
}
}
对于api的删除操作:
{
"operate": "del",
"target": "api",
"method": "get",
"api": "/test/role-ada"
}
对于api的修改操作:(缺失为不修改)
{
"operate": "modify",
"target": "api",
"method": "get",
"api": "/test/role-ada",
"role": {
"require": ["admin","zxc"],
"exclude": ["small-black,dog", "cat","apple"]
},
"permission": {
...
}
}
对于api的查看操作:
{
"operate": "get",
"target": "api",
"method": "get",
"api": "/test/role-ada"
}
example 对于参数的相关操作:
对于参数的添加操作:
1、在/test/role-ada接口上参数名为id添加限制权限限制。
user用户使用参数id访问接口时值只能在1-100内,否则权限错误
{
"operate": "add",
"target": "request_param_role",
"method": "get",
"api": "/test/role-ada",
"value": "id",
"role": {
"require":["user"]
},
"range": ["1-100"]
}
2、在/test/role-ada接口上参数名为id添加限制权限限制。
用户访问接口时如果id的值在1-200内,如果没有dog权限,将出现权限错误,被拦截
{
"operate": "add",
"target": "param_permission",
"method": "get",
"api": "/test/role-ada",
"value": "id",
"role: {
"require":["dog"]
},
"resources": ["1-100"]
}
3、在/test/role-ada/{name}接口上路径参数名为name添加限制权限限制。
用户'小学生'只能访问路径为/test/role-ada/apple或者/test/role-ada/good-apple,如果为/test/role-ada/bad-apple将报错
{
"operate": "add",
"target": "path_variable_role",
"method": "get",
"api": "/test/role-ada/{name}",
"value": "name",
"role: {
"require":["小学生"]
},
"range": ["apple","good-apple"]
}
对参数权限进行查看、修改、删除
1、删除/test/role-ada/{name}接口上路径参数名为name的限制。
用户'小学生'能够自由访问任意/test/role-ada/apple或者/test/role-ada/good-apple或者/test/role-ada/bad-apple
{
"operate": "del",
"target": "path_variable_role",
"method": "get",
"api": "/test/role-ada/{name}",
"value": "name"
}
2、如果在某个接口上添加了很多个限制条件,可以先查看,然后确认自己想具体删除哪个或者修改哪个,再附带index来指定修改的参数权限
查看
{
"operate": "get",
"target": "path_variable_role",
"method": "get",
"api": "/test/role-ada/{name}",
"value": "name"
}
3、删除第2个,index从0开始
{
"operate": "del",
"target": "path",
"method": "get",
"api": "/test/role-ada/{name}",
"value": "name",
"index": 1
}
3、修改第2个,index从0开始
让'小学生'可以查看坏苹果
{
"operate": "modify",
"target": "path_variable_role",
"method": "get",
"api": "/test/role-ada/{name}",
"value": "name",
"index": 1,
"role: {
"require":["小学生"]
},
"range": ["apple","bad-apple","good-apple"]
}
删除只能删除一整个,不能做到单独删除其中的requireRoles但是其他的保持不动,只能通过覆盖来操作
authzModifier - authzModifierPermRolesMeta \
ParamMetadata \
PermRolesMeta.Meta@NonNull public static String getRSAPublicKey()
@NonNull public static String getRSAPrivateKey()
public static void openAutoRefresh()
public static void closeAutoRefreshAndSetup(String publicKey, String privateKey)
public static void reloadCache()
public static void reloadCache(String... keys)
@SafeVarargs public static void reloadCache(Collection<String>... keys)
Copyright © 2022. All rights reserved.