Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 1e55b1ef
由
LN
编写于
2021-07-30 09:04:14 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
登录增加启用码验证。token过期时间改为30分钟。
1 个父辈
e0aa4f81
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
51 行增加
和
8 行删除
src/main/java/com/neotel/smfcore/common/utils/DateUtil.java
src/main/java/com/neotel/smfcore/security/rest/AuthorizationController.java
src/main/java/com/neotel/smfcore/security/rest/bean/dto/OnlineUserDto.java
src/main/java/com/neotel/smfcore/security/service/OnlineUserService.java
src/main/java/com/neotel/smfcore/security/service/UserDetailsServiceImpl.java
src/main/resources/config/application-dev.yml
src/main/java/com/neotel/smfcore/common/utils/DateUtil.java
查看文件 @
1e55b1e
...
@@ -147,6 +147,18 @@ public class DateUtil {
...
@@ -147,6 +147,18 @@ public class DateUtil {
c
.
add
(
Calendar
.
DAY_OF_YEAR
,
days
);
c
.
add
(
Calendar
.
DAY_OF_YEAR
,
days
);
return
c
.
getTime
();
return
c
.
getTime
();
}
}
/**
* 日期+天数
* @param date
* @param seconds
* @return
*/
public
static
Date
addSeconds
(
Date
date
,
int
seconds
){
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
c
.
add
(
Calendar
.
SECOND
,
seconds
);
return
c
.
getTime
();
}
public
static
Date
getMinDate
(
Date
date0
,
Date
date1
){
public
static
Date
getMinDate
(
Date
date0
,
Date
date1
){
return
date0
.
before
(
date1
)?
date0
:
date1
;
return
date0
.
before
(
date1
)?
date0
:
date1
;
...
...
src/main/java/com/neotel/smfcore/security/rest/AuthorizationController.java
查看文件 @
1e55b1e
...
@@ -15,11 +15,10 @@
...
@@ -15,11 +15,10 @@
*/
*/
package
com
.
neotel
.
smfcore
.
security
.
rest
;
package
com
.
neotel
.
smfcore
.
security
.
rest
;
import
com.neotel.smfcore.common.utils.*
;
import
com.neotel.smfcore.security.annotation.AnonymousDeleteMapping
;
import
com.neotel.smfcore.security.annotation.AnonymousDeleteMapping
;
import
com.neotel.smfcore.security.annotation.AnonymousGetMapping
;
import
com.neotel.smfcore.security.annotation.AnonymousGetMapping
;
import
com.neotel.smfcore.security.annotation.AnonymousPostMapping
;
import
com.neotel.smfcore.security.annotation.AnonymousPostMapping
;
import
com.neotel.smfcore.common.utils.EncryptUtils
;
import
com.neotel.smfcore.common.utils.StringUtils
;
import
com.neotel.smfcore.security.bean.RsaProperties
;
import
com.neotel.smfcore.security.bean.RsaProperties
;
import
com.neotel.smfcore.security.TokenProvider
;
import
com.neotel.smfcore.security.TokenProvider
;
import
com.neotel.smfcore.security.bean.LoginProperties
;
import
com.neotel.smfcore.security.bean.LoginProperties
;
...
@@ -28,8 +27,6 @@ import com.neotel.smfcore.security.rest.bean.dto.OnlineUserDto;
...
@@ -28,8 +27,6 @@ import com.neotel.smfcore.security.rest.bean.dto.OnlineUserDto;
import
com.neotel.smfcore.security.service.OnlineUserService
;
import
com.neotel.smfcore.security.service.OnlineUserService
;
import
com.neotel.smfcore.security.rest.bean.dto.AuthUserDto
;
import
com.neotel.smfcore.security.rest.bean.dto.AuthUserDto
;
import
com.neotel.smfcore.security.rest.bean.dto.JwtUserDto
;
import
com.neotel.smfcore.security.rest.bean.dto.JwtUserDto
;
import
com.neotel.smfcore.common.utils.RsaUtils
;
import
com.neotel.smfcore.common.utils.SecurityUtils
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
...
@@ -103,7 +100,8 @@ public class AuthorizationController {
...
@@ -103,7 +100,8 @@ public class AuthorizationController {
OnlineUserDto
onlineUserDto
=
null
;
OnlineUserDto
onlineUserDto
=
null
;
try
{
try
{
long
seconds
=
onlineUserService
.
properties
.
getTokenValidityInSeconds
()
/
1000
;
long
seconds
=
onlineUserService
.
properties
.
getTokenValidityInSeconds
()
/
1000
;
onlineUserDto
=
new
OnlineUserDto
(
jwtUserDto
.
getUsername
(),
browser
,
ip
,
address
,
EncryptUtils
.
desEncrypt
(
token
),
new
Date
());
Date
exTime
=
DateUtil
.
addSeconds
(
new
Date
(),
new
Long
(
seconds
).
intValue
());
onlineUserDto
=
new
OnlineUserDto
(
jwtUserDto
.
getUsername
(),
browser
,
ip
,
address
,
EncryptUtils
.
desEncrypt
(
token
),
new
Date
(),
exTime
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
}
}
...
...
src/main/java/com/neotel/smfcore/security/rest/bean/dto/OnlineUserDto.java
查看文件 @
1e55b1e
...
@@ -59,6 +59,10 @@ public class OnlineUserDto {
...
@@ -59,6 +59,10 @@ public class OnlineUserDto {
* 登录时间
* 登录时间
*/
*/
private
Date
loginTime
;
private
Date
loginTime
;
/**
* 过期时间
*/
private
Date
expiresTime
;
}
}
src/main/java/com/neotel/smfcore/security/service/OnlineUserService.java
查看文件 @
1e55b1e
...
@@ -23,6 +23,8 @@ import com.neotel.smfcore.security.rest.bean.dto.OnlineUserDto;
...
@@ -23,6 +23,8 @@ import com.neotel.smfcore.security.rest.bean.dto.OnlineUserDto;
import
com.neotel.smfcore.common.utils.EncryptUtils
;
import
com.neotel.smfcore.common.utils.EncryptUtils
;
import
com.neotel.smfcore.common.utils.FileUtil
;
import
com.neotel.smfcore.common.utils.FileUtil
;
import
com.neotel.smfcore.common.utils.StringUtils
;
import
com.neotel.smfcore.common.utils.StringUtils
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.ExpiredJwtException
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.Async
;
...
@@ -128,7 +130,23 @@ public class OnlineUserService {
...
@@ -128,7 +130,23 @@ public class OnlineUserService {
* @return /
* @return /
*/
*/
public
OnlineUserDto
getOne
(
String
key
)
{
public
OnlineUserDto
getOne
(
String
key
)
{
return
(
OnlineUserDto
)
onlineUserMap
.
get
(
key
);
OnlineUserDto
dto
=
null
;
dto
=
(
OnlineUserDto
)
onlineUserMap
.
get
(
key
);
Date
currTime
=
new
Date
();
int
result
=
dto
.
getExpiresTime
().
compareTo
(
new
Date
());
if
(
result
>
0
)
{
//更新过期时间
long
seconds
=
properties
.
getTokenValidityInSeconds
()
/
1000
;
Date
exTime
=
DateUtil
.
addSeconds
(
new
Date
(),
new
Long
(
seconds
).
intValue
());
dto
.
setExpiresTime
(
exTime
);
}
else
if
(
result
<
0
)
{
this
.
kickOut
(
key
);
//已过期抛异常
throw
new
ExpiredJwtException
(
null
,
null
,
"token 已过期"
);
}
return
dto
;
}
}
/**
/**
...
...
src/main/java/com/neotel/smfcore/security/service/UserDetailsServiceImpl.java
查看文件 @
1e55b1e
...
@@ -17,6 +17,8 @@ package com.neotel.smfcore.security.service;
...
@@ -17,6 +17,8 @@ package com.neotel.smfcore.security.service;
import
com.neotel.smfcore.common.exception.BadRequestException
;
import
com.neotel.smfcore.common.exception.BadRequestException
;
import
com.neotel.smfcore.common.exception.EntityNotFoundException
;
import
com.neotel.smfcore.common.exception.EntityNotFoundException
;
import
com.neotel.smfcore.common.utils.Constants
;
import
com.neotel.smfcore.common.utils.Md5Utls
;
import
com.neotel.smfcore.security.bean.LoginProperties
;
import
com.neotel.smfcore.security.bean.LoginProperties
;
import
com.neotel.smfcore.security.rest.bean.dto.JwtUserDto
;
import
com.neotel.smfcore.security.rest.bean.dto.JwtUserDto
;
import
com.neotel.smfcore.security.service.manager.IMenuManager
;
import
com.neotel.smfcore.security.service.manager.IMenuManager
;
...
@@ -85,6 +87,15 @@ public class UserDetailsServiceImpl implements UserDetailsService {
...
@@ -85,6 +87,15 @@ public class UserDetailsServiceImpl implements UserDetailsService {
if
(!
user
.
getEnabled
())
{
if
(!
user
.
getEnabled
())
{
throw
new
BadRequestException
(
"账号未激活!"
);
throw
new
BadRequestException
(
"账号未激活!"
);
}
}
if
(
user
.
getUsername
().
equals
(
Constants
.
SUPER_USERNAME
)){
}
else
{
//判断激活码是否正确
String
code
=
Md5Utls
.
getMd5
(
user
.
getId
(),
user
.
getCreateDate
());
if
(!
code
.
equals
(
user
.
getCheckCode
()))
{
throw
new
BadRequestException
(
"账号未激活!"
);
}
}
List
<
Long
>
dataScopes
=
new
ArrayList
<>();
List
<
Long
>
dataScopes
=
new
ArrayList
<>();
jwtUserDto
=
new
JwtUserDto
(
jwtUserDto
=
new
JwtUserDto
(
user
,
user
,
...
...
src/main/resources/config/application-dev.yml
查看文件 @
1e55b1e
...
@@ -36,8 +36,8 @@ jwt:
...
@@ -36,8 +36,8 @@ jwt:
token-start-with
:
Bearer
token-start-with
:
Bearer
# 必须使用最少88位的Base64对该令牌进行编码
# 必须使用最少88位的Base64对该令牌进行编码
base64-secret
:
ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
base64-secret
:
ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
# 令牌过期时间 此处单位/毫秒 ,默认
4小时
,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
# 令牌过期时间 此处单位/毫秒 ,默认
30分钟
,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
token-validity-in-seconds
:
1
44
00000
token-validity-in-seconds
:
1
8
00000
# 在线用户key
# 在线用户key
online-key
:
online-token-
online-key
:
online-token-
# 验证码
# 验证码
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论