public class AuHelper extends BaseHelper
| 限定符和类型 | 类和说明 |
|---|---|
static class |
AuHelper.Cache
1、在开启Redis时为L2Cache(二级缓存),默认情况下为普通的带时间策略的缓存
2、缓存策略:
2.1、若没有指定时间,默认为永久
2.2、在指定时间后,过期会删除key
2.3、若指定时间,L2环境下,本地时间会小于redis所存留的时间,在每次访问时,本地时间会重新计时,且成为热点key,加载速度更快
2.4、若指定时间,则会在redis里存一份,本地存一份,若其他实例修改,则会同步修改(默认实现为redis的消息队列)
3.L2Cache开启时会默认创建缓存消息通道,在修改其中
|
static class |
AuHelper.Callback |
static class |
AuHelper.OpenAuth
1.注册客户端
AuHelper.OpenAuth.clientRegister(String, String) -> 返回客户端信息(客户端id,客户端name,客户端密钥,重定向url)
2.获取授权码 AuHelper.OpenAuth.createAuthorizationCode(String, String, String) -> 客户端id+登录用户+权限范围 、获得登录用户的授权码
3.验证授权码 AuHelper.OpenAuth.authorizeByCode(String, String, String)-> 利用授权码去获得IssueToken
or 3.登录授权 AuHelper.OpenAuth.authorizeByPassword(String, String, String)-> 登录即可获得IssueToken |
static class |
AuHelper.RSA |
cache, ctx, openAuthLibrary, permLibrary, properties, userDevicesDict| 限定符和类型 | 方法和说明 |
|---|---|
static void |
addDeviceTypesTotalLimit(Collection<String> types,
int total)
每[一种、多种]设备类型设置[共同]的最大登录数(最小为1),超出会挤出最长时间未访问的设备。
|
static void |
addDeviceTypesTotalLimitAt(Object userId,
Collection<String> types,
int total)
每[一种、多种]设备类型设置[共同]的最大登录数(最小为1),超出会挤出最长时间未访问的设备。
|
static Object |
authzModify(AuthzModifier authzModifier) |
static void |
changeMaximumDeviceTotal(int total)
登录设备总数默不做限制【total为-1不做限制,最小为1】,超出会挤出最长时间未访问的设备。
|
static void |
changeMaximumTotalDeviceAt(Object userId,
int total)
登录设备总数默不做限制【total为-1不做限制,最小为1】,超出会挤出最长时间未访问的设备。
|
static void |
changeMaximumTotalSameTypeDevice(int total)
同类型设备最多登录数 默认 1个【count最小为1】,超出会挤出最长时间未访问的设备。
|
static void |
changeMaximumTotalSameTypeDeviceAt(Object userId,
int count)
同类型设备最多登录数 默认 1个【count最小为1】,超出会挤出最长时间未访问的设备。
|
static boolean |
checkUserIsActive(Object userId)
判断某个用户是否有设备【在线/活跃】(默认60秒内)
|
static boolean |
checkUserIsActive(Object userId,
long ms)
判断某个用户是否【在线/活跃】
|
static boolean |
checkUserIsActive(Object userId,
String time)
判断某个用户是否【在线/活跃】
|
static void |
denyDevice(Object userId,
String deviceType,
Date endDate)
【添加、修改】封禁 封禁 time时间
|
static void |
denyDevice(Object userId,
String deviceType,
long ms)
【添加、修改】封禁 封禁 time时间
|
static void |
denyDevice(Object userId,
String deviceType,
String deviceId,
Date endDate)
【添加、修改】封禁 设备 time时间
|
static void |
denyDevice(Object userId,
String deviceType,
String deviceId,
long ms)
【添加、修改】封禁 设备 time时间
|
static void |
denyIP(String ip,
Date endDate)
【添加、修改】封禁 ip time时间
|
static void |
denyIP(String ip,
long ms)
【添加、修改】封禁 ip time时间
|
static void |
denyIPRange(String ipRange,
Date endDate)
【添加、修改】封禁 ipRange网段 time时间
|
static void |
denyIPRange(String ipRange,
long ms)
【添加、修改】封禁 ipRange网段 time时间
|
static void |
denyUser(Object userId,
Date endDate)
【添加、修改】封禁 device time时间
|
static void |
denyUser(Object userId,
long ms)
【添加、修改】封禁 device time时间
|
static List<DeviceDetails> |
getActiveDevices()
所有【在线/活跃】用户详细设备信息 (默认60秒内)
|
static List<DeviceDetails> |
getActiveDevices(long ms)
所有【在线/活跃】用户详细设备信息
|
static List<DeviceDetails> |
getActiveDevices(String time)
所有【在线/活跃】用户详细设备信息
|
static List<Object> |
getActiveUserIdList()
所有【在线/活跃】(默认60秒内)用户Id数组
|
static List<Object> |
getActiveUserIdList(long ms)
所有【在线/活跃】用户Id列表
|
static List<Object> |
getActiveUserIdList(String time)
所有【在线/活跃】用户Id列表
|
static Set<Blacklist.IP> |
getAllDenyIPInfo()
得到所有的 封禁的ip信息
|
static Set<Blacklist.IPRangeDeny> |
getAllDenyIPRangeInfo() |
static Set<Blacklist.User> |
getAllDenyUserInfo() |
static Map<Object,List<DeviceDetails>> |
getAllUserDevices()
查询所有用户信息,一个map userId->设备信息列表
|
static List<Object> |
getAllUserId() |
static String |
getClientId() |
static Blacklist.User |
getDenyDeviceInfo(Object userId,
String deviceType,
String deviceId) |
static Blacklist.IP |
getDenyIPInfo(String ip) |
static Set<Blacklist.User> |
getDenyUserAndDeviceInfo(Object userId) |
static Blacklist.User |
getDenyUserInfo(Object userId) |
static DeviceDetails |
getDevice()
当前访问用户的设备
|
static DeviceDetails |
getDeviceAt(Object userId,
String deviceType,
String deviceId)
获得指定设备信息
|
static String |
getDeviceId() |
static List<DeviceDetails> |
getDevices()
当前访问用户的所有设备
|
static List<DeviceDetails> |
getDevices(String deviceType)
当前访问用户的指定类型的所有设备
|
static List<DeviceDetails> |
getDevicesAt(Object userId)
指定用户的所有设备
|
static List<DeviceDetails> |
getDevicesAt(Object userId,
String deviceType)
指定用户的指定类型的所有设备
|
static String |
getDeviceType() |
static HttpMeta |
getHttpMeta()
若当前线程未绑定HttpRequest。
|
static int |
getNumberOfActiveUser()
所有【在线/活跃】(默认60秒内)用户数量
|
static int |
getNumberOfActiveUser(long ms)
所有【在线/活跃】用户数量
|
static int |
getNumberOfActiveUser(String time)
所有【在线/活跃】用户数量
|
static List<DeviceCountInfo> |
getOrUpdateDeviceTypesTotalLimit()
获得当前用户 可修改的 DeviceTypesTotalLimit list
count >= 1 or count = -1
|
static List<DeviceCountInfo> |
getOrUpdateDeviceTypesTotalLimitAt(Object userId)
获得任意用户 可修改的 DeviceTypesTotalLimit list
count >= 1 or count = -1
|
static OS |
getOS() |
static Platform |
getPlatform() |
static AccessToken |
getToken() |
static UserAgent |
getUserAgent() |
static Object |
getUserId() |
static boolean |
hasPermission(String... permission) |
static boolean |
hasPermissions(List<String> permissions) |
static boolean |
hasRole(String... role) |
static boolean |
hasRoles(List<String> roles) |
static boolean |
hasScope(List<String> scope) |
static boolean |
hasScope(String... scope) |
static boolean |
isLogin() |
static boolean |
isLoginById(Object userId,
String id) |
static boolean |
isLoginById(String id) |
static IssueToken |
login(Object userId)
用户登录
若线程绑定了Request,则登录成功之后会默认给请求返回Cookie 过期时间为AccessToken的过期时间,若不需要,请自行删除 |
static IssueToken |
login(Object userId,
String deviceType)
用户登录
若线程绑定了Request,则登录成功之后会默认给请求返回Cookie 过期时间为AccessToken的过期时间,若不需要,请自行删除 |
static IssueToken |
login(Object userId,
String deviceType,
String deviceId)
用户登录
若线程绑定了Request,则登录成功之后会默认给请求返回Cookie 过期时间为AccessToken的过期时间,若不需要,请自行删除 |
static void |
logout()
注销当前用户当前设备
|
static void |
logout(String deviceType)
注销当前用户所指定的类型的所有设备
|
static void |
logout(String deviceType,
String deviceId)
注销当前用户所指定的类型和id的设备
|
static void |
logoutAll()
注销当前用户所有设备
|
static void |
logoutAllAt(Object userId)
注销指定用户所有设备,建议用于管理员,如果某用户想通过自己id注销自己,建议加上参数权限判断
|
static void |
logoutAt(Object userId,
String deviceType)
注销指定用户所指定的类型的所有设备
|
static void |
logoutAt(Object userId,
String deviceType,
String deviceId)
注销指定用户所指定的类型和id的设备
|
static void |
logoutById(Object userId,
String id)
退出指定用户指定登录标识的设备
|
static void |
logoutById(String id)
退出当前用户指定登录标识的设备
|
static IssueToken |
refreshToken(String refreshToken)
access过期刷新接口。
|
static void |
removeDenyDevice(Object userId,
String deviceType)
移除封禁
|
static void |
removeDenyDevice(Object userId,
String deviceType,
String deviceId)
移除封禁
|
static void |
removeDenyIP(String ip)
移除封禁
|
static void |
removeDenyIPRange(String ipRange)
移除封禁
|
static void |
removeDenyUser(Object userId)
移除封禁
|
@NonNull public static IssueToken login(@NonNull Object userId)
若线程绑定了Request,则登录成功之后会默认给请求返回Cookie
过期时间为AccessToken的过期时间,若不需要,请自行删除
userId - 用户id - 不为空@NonNull public static IssueToken login(@NonNull Object userId, @NonNull String deviceType)
若线程绑定了Request,则登录成功之后会默认给请求返回Cookie
过期时间为AccessToken的过期时间,若不需要,请自行删除
userId - 用户id - 不为空deviceType - 设备系统类型 - 不为null 默认为user-agnet,若没有则为unknown@NonNull public static IssueToken login(@NonNull Object userId, @NonNull String deviceType, @Nullable String deviceId)
若线程绑定了Request,则登录成功之后会默认给请求返回Cookie
过期时间为AccessToken的过期时间,若不需要,请自行删除
userId - 用户id - 不为空deviceType - 设备系统类型 - 不为空 默认为user-agnet,若没有则为unknowndeviceId - 设备id - 可为null@NonNull public static IssueToken refreshToken(@NonNull String refreshToken) throws RefreshTokenExpiredException, TokenException
如果使用单token,则直接使用accessToken即可,在accessToken过期时再重新登录。
使用双token时,accessToken过期时,可以利用refreshToken在此接口中刷新获得一个新的accessToken。
refreshToken - 与accessToken一起授予的refreshTokenRefreshTokenExpiredException - refreshToken过期 RefreshTokenExpiredExceptionTokenException - refreshToken异常 TokenExceptionpublic static void logout()
throws NotLoginException
public static void logout(@NonNull
String deviceType)
throws NotLoginException
deviceType - 指定设备类型NotLoginException - 若未登录,抛出 NotLoginExceptionpublic static void logout(@NonNull
String deviceType,
@Nullable
String deviceId)
throws NotLoginException
deviceType - 指定设备类型deviceId - 指定设备idNotLoginException - 若未登录,抛出 NotLoginExceptionpublic static void logoutAll()
throws NotLoginException
NotLoginException - 若未登录,抛出 NotLoginExceptionpublic static void logoutAllAt(@NonNull
Object userId)
userId - 用户idpublic static void logoutAt(@NonNull
Object userId,
@NonNull
String deviceType)
userId - 用户iddeviceType - 指定设备类型public static void logoutAt(@NonNull
Object userId,
@NonNull
String deviceType,
@Nullable
String deviceId)
userId - 用户iddeviceType - 指定设备类型deviceId - 指定设备idpublic static void logoutById(String id) throws NotLoginException
id - 登录标识NotLoginException - 若未登录,抛出 NotLoginExceptionpublic static void logoutById(Object userId, String id)
userId - 用户idid - 登录标识@NonNull public static Map<Object,List<DeviceDetails>> getAllUserDevices()
@NonNull public static List<DeviceDetails> getDevices(@NonNull String deviceType) throws NotLoginException
NotLoginException - 若未登录,抛出 NotLoginException@NonNull public static List<DeviceDetails> getDevices() throws NotLoginException
NotLoginException - 若未登录,抛出 NotLoginException@Nullable public static DeviceDetails getDevice() throws NotLoginException
NotLoginException - 若未登录,抛出 NotLoginException@NonNull public static List<DeviceDetails> getDevicesAt(@NonNull Object userId)
@NonNull public static List<DeviceDetails> getDevicesAt(@NonNull Object userId, @NonNull String deviceType)
@Nullable public static DeviceDetails getDeviceAt(@NonNull Object userId, @NonNull String deviceType, @Nullable String deviceId)
userId - 指定userIdpublic static void addDeviceTypesTotalLimit(@NonNull
Collection<String> types,
int total)
throws NotLoginException
types - deviceTypetotal - 数量NotLoginExceptionpublic static void addDeviceTypesTotalLimitAt(@NonNull
Object userId,
@NonNull
Collection<String> types,
int total)
userId - 用户idtypes - deviceTypetotal - 数量public static List<DeviceCountInfo> getOrUpdateDeviceTypesTotalLimit() throws NotLoginException
public static List<DeviceCountInfo> getOrUpdateDeviceTypesTotalLimitAt(@NonNull Object userId)
userId - 用户idpublic static void changeMaximumDeviceTotal(int total)
throws NotLoginException
total - 总数NotLoginExceptionpublic static void changeMaximumTotalDeviceAt(@NonNull
Object userId,
int total)
userId - 用户idtotal - 总数public static void changeMaximumTotalSameTypeDevice(int total)
throws NotLoginException
total - 总数NotLoginExceptionpublic static void changeMaximumTotalSameTypeDeviceAt(@NonNull
Object userId,
int count)
userId - 用户idcount - 数量public static boolean isLogin()
public static boolean isLoginById(@NonNull
String id)
id - 登录标识public static boolean isLoginById(@NonNull
Object userId,
@NonNull
String id)
id - 登录标识@NonNull public static HttpMeta getHttpMeta() throws ThreadWebEnvironmentException
ThreadWebEnvironmentExceptionThreadWebEnvironmentException - 线程Web环境异常@NonNull public static UserAgent getUserAgent() throws ThreadWebEnvironmentException
ThreadWebEnvironmentException@NonNull public static Platform getPlatform() throws ThreadWebEnvironmentException
ThreadWebEnvironmentException@NonNull public static OS getOS() throws ThreadWebEnvironmentException
ThreadWebEnvironmentException@NonNull public static AccessToken getToken() throws NotLoginException
NotLoginException - 若未登录,抛出 NotLoginException@NonNull public static Object getUserId() throws NotLoginException
NotLoginException - 若未登录,抛出 NotLoginException@NonNull public static String getDeviceType() throws NotLoginException
NotLoginException - 若未登录,抛出 NotLoginException@Nullable public static String getDeviceId() throws NotLoginException
NotLoginException - 若未登录,抛出 NotLoginException@Nullable public static String getClientId() throws NotLoginException
NotLoginException - 若未登录,抛出 NotLoginExceptionpublic static boolean hasRole(@NonNull
String... role)
role - 所指定的角色public static boolean hasRoles(@NonNull
List<String> roles)
roles - 所指定的角色public static boolean hasPermission(@NonNull
String... permission)
permission - 所指定的权限public static boolean hasPermissions(@NonNull
List<String> permissions)
permissions - 所指定的权限public static boolean hasScope(@NonNull
String... scope)
scope - 所指定的访问范围public static boolean hasScope(@NonNull
List<String> scope)
scope - 所指定的访问范围public 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 getNumberOfActiveUser()
public static int getNumberOfActiveUser(@NonNull
String time)
time - 时间间隔public static int getNumberOfActiveUser(long ms)
ms - 时间间隔(ms)@NonNull public static List<Object> getActiveUserIdList()
@NonNull public static List<Object> getActiveUserIdList(@NonNull String time)
time - 时间间隔@NonNull public static List<Object> getActiveUserIdList(long ms)
ms - 时间间隔(ms)@NonNull public static List<DeviceDetails> getActiveDevices()
@NonNull public static List<DeviceDetails> getActiveDevices(long ms)
ms - 时间间隔(ms)@NonNull public static List<DeviceDetails> getActiveDevices(@NonNull String time)
time - 时间字符串 "2d 3h 4m 5s 100ms"-> 2天3小时4分钟5秒100毫秒public static void denyIP(@NonNull
String ip,
@NonNull
long ms)
ip - 封禁的ipms - 毫秒public static void denyIP(@NonNull
String ip,
@NonNull
Date endDate)
ip - 封禁的ipendDate - 过期日期public static void denyIPRange(@NonNull
String ipRange,
@NonNull
long ms)
ipRange - 封禁的ip范围 xx.xx.xx.xx/xxms - 毫秒public static void denyIPRange(@NonNull
String ipRange,
@NonNull
Date endDate)
ipRange - 封禁的ip范围 xx.xx.xx.xx/xxendDate - 过期日期public static void denyUser(@NonNull
Object userId,
@NonNull
long ms)
userId - 封禁的userIdms - 毫秒public static void denyUser(@NonNull
Object userId,
@NonNull
Date endDate)
userId - 封禁的userIdendDate - 过期日期public static void denyDevice(@NonNull
Object userId,
@NonNull
String deviceType,
@NonNull
long ms)
userId - 封禁的userIddeviceType - 封禁的设备类型ms - 毫秒public static void denyDevice(@NonNull
Object userId,
@NonNull
String deviceType,
@NonNull
Date endDate)
userId - 封禁的userIddeviceType - 封禁的设备类型endDate - 过期日期public static void denyDevice(@NonNull
Object userId,
@NonNull
String deviceType,
@Nullable
String deviceId,
@NonNull
long ms)
userId - 封禁的userIddeviceType - 封禁的设备类型deviceId - 封禁的设备idms - 毫秒public static void denyDevice(@NonNull
Object userId,
@NonNull
String deviceType,
@Nullable
String deviceId,
@NonNull
Date endDate)
userId - 封禁的userIddeviceType - 封禁的设备类型deviceId - 封禁的设备idendDate - 过期日期@NonNull public static Set<Blacklist.IP> getAllDenyIPInfo()
@Nullable public static Blacklist.IP getDenyIPInfo(String ip)
@NonNull public static Set<Blacklist.IPRangeDeny> getAllDenyIPRangeInfo()
@NonNull public static Set<Blacklist.User> getAllDenyUserInfo()
@NonNull public static Set<Blacklist.User> getDenyUserAndDeviceInfo(@NonNull Object userId)
userId - 指定用户id@Nullable public static Blacklist.User getDenyUserInfo(@NonNull Object userId)
userId - 指定用户id@Nullable public static Blacklist.User getDenyDeviceInfo(@NonNull Object userId, @NonNull String deviceType, @Nullable String deviceId)
userId - 指定用户iddeviceType - 指定设备deviceTypedeviceId - 指定设备deviceIdpublic static void removeDenyIP(@NonNull
String ip)
ip - ippublic static void removeDenyIPRange(@NonNull
String ipRange)
ipRange - ip范围public static void removeDenyUser(@NonNull
Object userId)
userId - 指定用户public static void removeDenyDevice(@NonNull
Object userId,
@NonNull
String deviceType)
userId - 指定用户deviceType - 指定设备类型public static void removeDenyDevice(@NonNull
Object userId,
@NonNull
String deviceType,
@NonNull
String deviceId)
userId - 指定用户deviceType - 指定设备类型deviceId - 指定设备id@Nullable public static Object authzModify(@NonNull AuthzModifier authzModifier)
Copyright © 2022. All rights reserved.