feat(sip):提供给NEX的接口调试
parent
cc29006013
commit
b3e5568216
|
|
@ -37,21 +37,6 @@ public class ShiroUtils {
|
||||||
|
|
||||||
// 检查是否是API Key认证
|
// 检查是否是API Key认证
|
||||||
Object principal = subject.getPrincipal();
|
Object principal = subject.getPrincipal();
|
||||||
if (principal instanceof SysUser) {
|
|
||||||
// 正常登录用户
|
|
||||||
return (SysUser) principal;
|
|
||||||
} else if (principal == null) {
|
|
||||||
// 检查是否是API Key请求
|
|
||||||
HttpServletRequest request = ServletUtils.getRequest();
|
|
||||||
String apiKey = request.getHeader("X-API-Key");
|
|
||||||
if (StringUtils.isNotEmpty(apiKey) && NEX_API_KEY.equals(apiKey)) {
|
|
||||||
Long userId = validateApiKey(apiKey); // 验证API Key并获取用户ID
|
|
||||||
if (userId != null) {
|
|
||||||
SysUser user = loadUserById(userId);
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 传统方式获取用户
|
// 传统方式获取用户
|
||||||
SysUser user = null;
|
SysUser user = null;
|
||||||
|
|
@ -63,11 +48,8 @@ public class ShiroUtils {
|
||||||
// 检查是否是API Key请求
|
// 检查是否是API Key请求
|
||||||
HttpServletRequest request = ServletUtils.getRequest();
|
HttpServletRequest request = ServletUtils.getRequest();
|
||||||
String apiKey = request.getHeader("X-API-Key");
|
String apiKey = request.getHeader("X-API-Key");
|
||||||
if (StringUtils.isNotEmpty(apiKey)) {
|
if (StringUtils.isNotEmpty(apiKey)&& NEX_API_KEY.equals(apiKey)) {
|
||||||
Long userId = validateApiKey(apiKey); // 验证API Key并获取用户ID
|
return loadUserById();
|
||||||
user = loadUserById(userId);
|
|
||||||
setSysUser(user);
|
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
@ -79,18 +61,19 @@ public class ShiroUtils {
|
||||||
// 查询数据库验证API Key,并返回对应的用户ID
|
// 查询数据库验证API Key,并返回对应的用户ID
|
||||||
// 这里应该查询API Key表,获取关联的用户ID
|
// 这里应该查询API Key表,获取关联的用户ID
|
||||||
// 例如: select user_id from sys_api_key where api_key = ? and status = 'A'
|
// 例如: select user_id from sys_api_key where api_key = ? and status = 'A'
|
||||||
return 1L;
|
return 101L;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户ID加载用户信息
|
* 根据用户ID加载用户信息
|
||||||
*/
|
*/
|
||||||
private static SysUser loadUserById(Long userId) {
|
private static SysUser loadUserById() {
|
||||||
// 从数据库加载用户信息
|
// 从数据库加载用户信息
|
||||||
// 例如: select * from sys_user where user_id = ?
|
// 例如: select * from sys_user where user_id = ?
|
||||||
SysUser user = new SysUser();
|
SysUser user = new SysUser();
|
||||||
user.setUserId(1L);
|
user.setUserId(101L);
|
||||||
user.setUserName("admin");
|
user.setUserName("乐喽ch");
|
||||||
|
user.setLoginName("leoloch");
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue