Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mqttsnet
thinglinks
提交
6f717b7b
thinglinks
项目概览
mqttsnet
/
thinglinks
通知
1
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
thinglinks
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6f717b7b
编写于
11月 22, 2021
作者:
xiaonannet
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/release/1.0.0' into release/1.0.0
# Conflicts: # mqtts-ui/src/main.js
上级
d3b8e623
14cd558b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
23 deletion
+27
-23
mqtts-common/mqtts-common-core/src/main/java/net/mqtts/common/core/constant/UserConstants.java
...in/java/net/mqtts/common/core/constant/UserConstants.java
+10
-0
mqtts-common/mqtts-common-core/src/main/java/net/mqtts/common/core/utils/SecurityUtils.java
.../main/java/net/mqtts/common/core/utils/SecurityUtils.java
+17
-23
未找到文件。
mqtts-common/mqtts-common-core/src/main/java/net/mqtts/common/core/constant/UserConstants.java
浏览文件 @
6f717b7b
...
...
@@ -7,6 +7,16 @@ package net.mqtts.common.core.constant;
*/
public
class
UserConstants
{
/**
* 平台默认超级管理员
*/
public
static
final
String
ADMIN
=
"admin"
;
/**
* 平台默认管理员
*/
public
static
final
String
MQTTS
=
"mqtts"
;
/**
* 平台内系统用户的唯一标志
*/
...
...
mqtts-common/mqtts-common-core/src/main/java/net/mqtts/common/core/utils/SecurityUtils.java
浏览文件 @
6f717b7b
...
...
@@ -2,47 +2,46 @@ package net.mqtts.common.core.utils;
import
javax.servlet.http.HttpServletRequest
;
import
net.mqtts.common.core.constant.UserConstants
;
import
net.mqtts.common.core.text.Convert
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
net.mqtts.common.core.constant.SecurityConstants
;
/**
* 权限获取工具类
*
*
* @author mqtts
*/
public
class
SecurityUtils
{
public
class
SecurityUtils
{
/**
* 获取用户
*/
public
static
String
getUsername
()
{
public
static
String
getUsername
()
{
String
username
=
ServletUtils
.
getRequest
().
getHeader
(
SecurityConstants
.
DETAILS_USERNAME
);
if
(
StringUtils
.
isEmpty
(
username
))
{
return
UserConstants
.
MQTTS
;
}
return
ServletUtils
.
urlDecode
(
username
);
}
/**
* 获取用户ID
*/
public
static
Long
getUserId
()
{
public
static
Long
getUserId
()
{
return
Convert
.
toLong
(
ServletUtils
.
getRequest
().
getHeader
(
SecurityConstants
.
DETAILS_USER_ID
));
}
/**
* 获取请求token
*/
public
static
String
getToken
()
{
public
static
String
getToken
()
{
return
getToken
(
ServletUtils
.
getRequest
());
}
/**
* 根据request获取请求token
*/
public
static
String
getToken
(
HttpServletRequest
request
)
{
public
static
String
getToken
(
HttpServletRequest
request
)
{
String
token
=
request
.
getHeader
(
SecurityConstants
.
TOKEN_AUTHENTICATION
);
return
replaceTokenPrefix
(
token
);
}
...
...
@@ -50,10 +49,8 @@ public class SecurityUtils
/**
* 替换token前缀
*/
public
static
String
replaceTokenPrefix
(
String
token
)
{
if
(
StringUtils
.
isNotEmpty
(
token
)
&&
token
.
startsWith
(
SecurityConstants
.
TOKEN_PREFIX
))
{
public
static
String
replaceTokenPrefix
(
String
token
)
{
if
(
StringUtils
.
isNotEmpty
(
token
)
&&
token
.
startsWith
(
SecurityConstants
.
TOKEN_PREFIX
))
{
token
=
token
.
replace
(
SecurityConstants
.
TOKEN_PREFIX
,
""
);
}
return
token
;
...
...
@@ -61,12 +58,11 @@ public class SecurityUtils
/**
* 是否为管理员
*
*
* @param userId 用户ID
* @return 结果
*/
public
static
boolean
isAdmin
(
Long
userId
)
{
public
static
boolean
isAdmin
(
Long
userId
)
{
return
userId
!=
null
&&
1L
==
userId
;
}
...
...
@@ -76,8 +72,7 @@ public class SecurityUtils
* @param password 密码
* @return 加密字符串
*/
public
static
String
encryptPassword
(
String
password
)
{
public
static
String
encryptPassword
(
String
password
)
{
BCryptPasswordEncoder
passwordEncoder
=
new
BCryptPasswordEncoder
();
return
passwordEncoder
.
encode
(
password
);
}
...
...
@@ -85,12 +80,11 @@ public class SecurityUtils
/**
* 判断密码是否相同
*
* @param rawPassword 真实密码
* @param rawPassword
真实密码
* @param encodedPassword 加密后字符
* @return 结果
*/
public
static
boolean
matchesPassword
(
String
rawPassword
,
String
encodedPassword
)
{
public
static
boolean
matchesPassword
(
String
rawPassword
,
String
encodedPassword
)
{
BCryptPasswordEncoder
passwordEncoder
=
new
BCryptPasswordEncoder
();
return
passwordEncoder
.
matches
(
rawPassword
,
encodedPassword
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录