Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jeecg-boot
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
jeecg-boot
Commits
b92bec3e
Commit
b92bec3e
authored
Oct 12, 2020
by
zhangdaiscott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登入生成token的小bug issues/I1XOVS
parent
72f32e47
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
2 deletions
+7
-2
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/config/shiro/ShiroRealm.java
+3
-0
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java
+4
-2
No files found.
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/config/shiro/ShiroRealm.java
View file @
b92bec3e
package
org
.
jeecg
.
config
.
shiro
;
package
org
.
jeecg
.
config
.
shiro
;
import
cn.hutool.crypto.SecureUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.AuthenticationInfo
;
import
org.apache.shiro.authc.AuthenticationInfo
;
...
@@ -118,6 +119,8 @@ public class ShiroRealm extends AuthorizingRealm {
...
@@ -118,6 +119,8 @@ public class ShiroRealm extends AuthorizingRealm {
//如果redis缓存用户信息为空,则通过接口获取用户信息,避免超过两个小时操作中token过期
//如果redis缓存用户信息为空,则通过接口获取用户信息,避免超过两个小时操作中token过期
if
(
loginUser
==
null
){
if
(
loginUser
==
null
){
loginUser
=
commonAPI
.
getUserByName
(
username
);
loginUser
=
commonAPI
.
getUserByName
(
username
);
//密码二次加密,因为存于redis会泄露
loginUser
.
setPassword
(
SecureUtil
.
md5
(
loginUser
.
getPassword
()));
}
}
if
(
loginUser
==
null
)
{
if
(
loginUser
==
null
)
{
throw
new
AuthenticationException
(
"用户不存在!"
);
throw
new
AuthenticationException
(
"用户不存在!"
);
...
...
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java
View file @
b92bec3e
...
@@ -81,7 +81,8 @@ public class LoginController {
...
@@ -81,7 +81,8 @@ public class LoginController {
String
lowerCaseCaptcha
=
captcha
.
toLowerCase
();
String
lowerCaseCaptcha
=
captcha
.
toLowerCase
();
String
realKey
=
MD5Util
.
MD5Encode
(
lowerCaseCaptcha
+
sysLoginModel
.
getCheckKey
(),
"utf-8"
);
String
realKey
=
MD5Util
.
MD5Encode
(
lowerCaseCaptcha
+
sysLoginModel
.
getCheckKey
(),
"utf-8"
);
Object
checkCode
=
redisUtil
.
get
(
realKey
);
Object
checkCode
=
redisUtil
.
get
(
realKey
);
if
(
checkCode
==
null
||
!
checkCode
.
equals
(
lowerCaseCaptcha
))
{
//当进入登录页时,有一定几率出现验证码错误 #1714
if
(
checkCode
==
null
||
!
checkCode
.
toString
().
equals
(
lowerCaseCaptcha
))
{
result
.
error500
(
"验证码错误"
);
result
.
error500
(
"验证码错误"
);
return
result
;
return
result
;
}
}
...
@@ -355,7 +356,7 @@ public class LoginController {
...
@@ -355,7 +356,7 @@ public class LoginController {
String
syspassword
=
sysUser
.
getPassword
();
String
syspassword
=
sysUser
.
getPassword
();
String
username
=
sysUser
.
getUsername
();
String
username
=
sysUser
.
getUsername
();
// 生成token
// 生成token
String
token
=
JwtUtil
.
sign
(
username
,
syspassword
);
String
token
=
JwtUtil
.
sign
(
username
,
SecureUtil
.
md5
(
syspassword
)
);
// 设置token缓存有效时间
// 设置token缓存有效时间
redisUtil
.
set
(
CommonConstant
.
PREFIX_USER_TOKEN
+
token
,
token
);
redisUtil
.
set
(
CommonConstant
.
PREFIX_USER_TOKEN
+
token
,
token
);
redisUtil
.
expire
(
CommonConstant
.
PREFIX_USER_TOKEN
+
token
,
JwtUtil
.
EXPIRE_TIME
*
2
/
1000
);
redisUtil
.
expire
(
CommonConstant
.
PREFIX_USER_TOKEN
+
token
,
JwtUtil
.
EXPIRE_TIME
*
2
/
1000
);
...
@@ -363,6 +364,7 @@ public class LoginController {
...
@@ -363,6 +364,7 @@ public class LoginController {
//update-begin-author:taoyan date:20200812 for:登录缓存用户信息
//update-begin-author:taoyan date:20200812 for:登录缓存用户信息
LoginUser
vo
=
new
LoginUser
();
LoginUser
vo
=
new
LoginUser
();
BeanUtils
.
copyProperties
(
sysUser
,
vo
);
BeanUtils
.
copyProperties
(
sysUser
,
vo
);
//密码二次加密,因为存于redis会泄露
vo
.
setPassword
(
SecureUtil
.
md5
(
sysUser
.
getPassword
()));
vo
.
setPassword
(
SecureUtil
.
md5
(
sysUser
.
getPassword
()));
redisUtil
.
set
(
CacheConstant
.
SYS_USERS_CACHE_JWT
+
":"
+
token
,
vo
);
redisUtil
.
set
(
CacheConstant
.
SYS_USERS_CACHE_JWT
+
":"
+
token
,
vo
);
redisUtil
.
expire
(
CacheConstant
.
SYS_USERS_CACHE_JWT
+
":"
+
token
,
JwtUtil
.
EXPIRE_TIME
*
2
/
1000
);
redisUtil
.
expire
(
CacheConstant
.
SYS_USERS_CACHE_JWT
+
":"
+
token
,
JwtUtil
.
EXPIRE_TIME
*
2
/
1000
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment