Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bill-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
bill-platform
Commits
cd51bbd0
Commit
cd51bbd0
authored
May 30, 2024
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
精简部分类
parent
8a450b7c
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
447 deletions
+37
-447
bill-manager/src/main/java/com/mortals/xhx/base/framework/interceptor/AuthTokenServiceImpl.java
.../xhx/base/framework/interceptor/AuthTokenServiceImpl.java
+32
-39
bill-manager/src/main/java/com/mortals/xhx/base/login/web/LoginController.java
.../java/com/mortals/xhx/base/login/web/LoginController.java
+1
-134
bill-manager/src/main/java/com/mortals/xhx/base/login/web/SecurityCodeController.java
...om/mortals/xhx/base/login/web/SecurityCodeController.java
+0
-7
bill-manager/src/main/java/com/mortals/xhx/base/login/web/StandaloneLoginController.java
...mortals/xhx/base/login/web/StandaloneLoginController.java
+0
-267
bill-manager/src/main/java/com/mortals/xhx/base/system/resource/service/impl/ResourceServiceImpl.java
...ase/system/resource/service/impl/ResourceServiceImpl.java
+2
-0
bill-manager/src/main/java/com/mortals/xhx/base/system/role/service/impl/RoleAuthServiceImpl.java
...hx/base/system/role/service/impl/RoleAuthServiceImpl.java
+2
-0
No files found.
bill-manager/src/main/java/com/mortals/xhx/base/framework/interceptor/AuthTokenServiceImpl.java
View file @
cd51bbd0
...
...
@@ -10,7 +10,6 @@ import com.mortals.framework.util.StringUtils;
import
com.mortals.xhx.base.system.resource.service.ResourceService
;
import
com.mortals.xhx.base.system.user.model.UserEntity
;
import
com.mortals.xhx.base.system.user.service.UserService
;
import
com.mortals.xhx.common.code.PlatformTypeEnum
;
import
com.mortals.xhx.common.key.RedisKey
;
import
com.mortals.xhx.common.utils.MenuEncodeUtil
;
import
io.jsonwebtoken.Claims
;
...
...
@@ -19,6 +18,7 @@ import io.jsonwebtoken.SignatureAlgorithm;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
...
...
@@ -35,11 +35,15 @@ import java.util.Set;
*
* @author zxfei
*/
@Primary
@Service
@Order
(
1
)
@Slf4j
public
class
AuthTokenServiceImpl
implements
IAuthTokenService
{
@Autowired
private
UserService
userService
;
// 令牌自定义标识
@Value
(
"${token.header:Authorization}"
)
private
String
header
;
...
...
@@ -62,15 +66,6 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
@Value
(
"${token.database:0}"
)
private
Integer
portalDb
;
@Value
(
"${platform.type:cloud}"
)
private
String
platFormType
;
//版本,默认云服务版本
@Autowired
private
ResourceService
resourceService
;
@Autowired
private
UserService
userService
;
protected
static
final
Long
SECOND
=
1
l
;
protected
static
final
Long
SECOND_MINUTE
=
60
*
SECOND
;
...
...
@@ -81,11 +76,15 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
protected
static
final
Long
SECOND_WEEK
=
7
*
SECOND_DAY
;
private
static
final
Long
SECOND_MINUTE_TEN
=
20
*
SECOND_MINUTE
;
private
static
final
Long
SECOND_MINUTE_TEN
=
1
*
SECOND_MINUTE
;
@Autowired
private
ICacheService
cacheService
;
@Autowired
private
ResourceService
resourceService
;
/**
* 获取信息
*
...
...
@@ -106,31 +105,18 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
Claims
claims
=
parseToken
(
token
);
String
uuid
=
(
String
)
claims
.
get
(
SysConstains
.
LOGIN_USER_KEY
);
String
userKey
=
getTokenKey
(
uuid
);
String
userStr
=
""
;
if
(
platFormType
.
equalsIgnoreCase
(
PlatformTypeEnum
.
CLOUD
.
getValue
()))
{
/* cacheService.select(portalDb);
userStr = cacheService.get(userKey);*/
RedisTemplate
<
String
,
String
>
redisTemplate
=
cacheService
.
selectDbRedisTemplate
(
portalDb
);
userStr
=
redisTemplate
.
opsForValue
().
get
(
userKey
);
//刷新token时间
UserEntity
userEntity
=
JSONObject
.
parseObject
(
userStr
,
UserEntity
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
userEntity
))
{
verifyToken
(
userEntity
);
}
// cacheService.select(db);
}
else
{
userStr
=
cacheService
.
get
(
userKey
);
//刷新token时间
UserEntity
userEntity
=
JSONObject
.
parseObject
(
userStr
,
UserEntity
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
userEntity
))
{
verifyToken
(
userEntity
);
}
//cacheService.select(portalDb);
// String userStr = cacheService.get(userKey);
RedisTemplate
<
String
,
String
>
redisTemplate
=
cacheService
.
selectDbRedisTemplate
(
portalDb
);
String
userStr
=
redisTemplate
.
opsForValue
().
get
(
userKey
);
//刷新token时间
UserEntity
userEntity
=
JSONObject
.
parseObject
(
userStr
,
UserEntity
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
userEntity
))
{
verifyToken
(
userEntity
);
}
if
(
StringUtils
.
isNotEmpty
(
userStr
))
{
UserEntity
userEntity
=
JSONObject
.
parseObject
(
userStr
,
UserEntity
.
class
);
userEntity
.
setToken
(
token
);
//更新portal 中的id 为 device中的id
// UserEntity temp = userService.selectOne(new UserQuery().loginName(userEntity.getLoginName()));
// cacheService.select(db);
if
(!
ObjectUtils
.
isEmpty
(
userEntity
))
{
UserEntity
temp
=
userService
.
getExtCache
(
userEntity
.
getLoginName
());
if
(!
ObjectUtils
.
isEmpty
(
temp
))
{
userEntity
.
setId
(
temp
.
getId
());
...
...
@@ -146,7 +132,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
return
userEntity
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"解析jwt token异常!
"
,
e
);
log
.
error
(
"解析jwt token异常!
,token:{}"
,
token
,
e
);
return
null
;
}
}
...
...
@@ -201,7 +187,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
long
expireTime
=
user
.
getExpireTime
();
long
currentTime
=
System
.
currentTimeMillis
();
if
(
expireTime
-
currentTime
<=
SECOND_MINUTE_TEN
*
1000
)
{
log
.
info
(
"不足十分钟,刷新过期时间"
);
log
.
info
(
"不足
二
十分钟,刷新过期时间"
);
refreshToken
(
user
);
}
}
...
...
@@ -213,7 +199,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
*/
public
void
refreshToken
(
IUser
user
)
{
//user.setLoginTime(System.currentTimeMillis());
user
.
setExpireTime
(
user
.
getLoginTime
()
==
null
?
System
.
currentTimeMillis
()
:
user
.
getLoginTime
()
+
expireTime
*
SECOND_MINUTE
);
user
.
setExpireTime
(
user
.
getLoginTime
()
==
null
?
System
.
currentTimeMillis
()
:
user
.
getLoginTime
()
+
expireTime
*
SECOND_MINUTE
*
1000
);
// 根据uuid将user缓存
String
userKey
=
getTokenKey
(
user
.
getToken
());
//设置有效时间 单位秒
...
...
@@ -280,4 +266,11 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
private
String
getTokenKey
(
String
uuid
)
{
return
SysConstains
.
LOGIN_TOKEN_KEY
+
uuid
;
}
public
static
void
main
(
String
[]
args
)
{
// boolean signed = Jwts.parser().isSigned("123");
boolean
signed
=
Jwts
.
parser
().
isSigned
(
"eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJuaW5naGFvLm5ldCIsImV4cCI6IjE0Mzg5NTU0NDUiLCJuYW1lIjoid2FuZ2hhbyIsImFkbWluIjp0cnVlfQ.SwyHTEx_RQppr97g4J5lKXtabJecpejuef8AqKYMAJc"
);
System
.
out
.
println
(
signed
);
}
}
bill-manager/src/main/java/com/mortals/xhx/base/login/web/LoginController.java
View file @
cd51bbd0
...
...
@@ -39,19 +39,12 @@ import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT;
@RestController
@Slf4j
@RequestMapping
(
"login"
)
@ConditionalOnExpression
(
"'${platform.type:null}'=='cloud'"
)
public
class
LoginController
extends
BaseCRUDJsonBodyMappingController
<
UserService
,
UserEntity
,
Long
>
implements
InitializingBean
{
@Autowired
private
UserService
userService
;
@Autowired
private
ValidCodeService
validCodeService
;
@Autowired
private
ResourceService
resourceService
;
@Autowired
private
MenuService
menuService
;
// @Autowired
// private ITokenService tokenService;
@Autowired
private
ICacheService
cacheService
;
@Autowired
...
...
@@ -61,11 +54,8 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
@RequestMapping
(
"login"
)
public
String
login
(
@RequestBody
LoginForm
loginForm
)
throws
Exception
{
JSONObject
ret
=
new
JSONObject
();
String
loginName
=
loginForm
.
getLoginName
();
String
password
=
loginForm
.
getPassword
();
UserPdu
userPdu
=
new
UserPdu
();
userPdu
.
setLoginName
(
loginName
);
userPdu
.
setPassword
(
password
);
...
...
@@ -73,77 +63,12 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
String
resp
=
userFeign
.
portalLogin
(
userPdu
);
return
resp
;
/* String securityCode = loginForm.getSecurityCode();
String ip = super.getRequestIP(request);
if (StringUtils.isEmpty(loginName) || StringUtils.isEmpty(password)) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, "未获取到用户信息,请重新登录");
return ret.toJSONString();
}
UserEntity userEntity = null;
try {
loginForm.validate();
// boolean result = validCodeService.doCheckImageValidCode(request.getSession().getId(), ip, securityCode);
// if ("8888".equals(securityCode)) {
// result = true;
// }
// if (!result) {
// recordSysLog(request, userEntity, "登录验证码不正确或已过期!");
// ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
// ret.put(KEY_RESULT_MSG, "登录验证码不正确或已过期!");
// return ret.toJSONString();
// }
userEntity = userService.doLogin(loginName, password, ip);
userEntity.setLastLoginAddress(ip);
recordSysLog(request, userEntity, "用户登录系统成功!");
// 返回拥有的菜单数据
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
List<MenuEntity> outlookBarList = menuService.findTreeMenu(userEntity, urls);
String currUserName = userEntity.getRealName();
if (currUserName == null || currUserName.trim().length() == 0) {
currUserName = "管理员";
}
JSONObject data = new JSONObject();
data.put("currUserName", currUserName);
data.put("barList", outlookBarList);
data.put("id", userEntity.getId());
data.put("userType", userEntity.getUserType());
userEntity.setLoginTime(System.currentTimeMillis());
userEntity.setToken(IdUtil.fastSimpleUUID());
userEntity.setExpireTime(DateUtils.addCurrDate(7).getTime());
userEntity.setMenuUrl(generateMenuUrlCode(urls));
String token = authTokenService.createToken(userEntity);
data.put("token", token);
//设置token 和过期时间
//data.put("expiresTime", DateUtils.addCurrDate(7).getTime());
generateMenuUrlCode(urls);
//this.generateBlackCookie(request, response, loginName, urls);
ret.put(KEY_RESULT_DATA, data);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户登录系统成功!");
ret.put("resources", urls);
return ret.toJSONString();
} catch (Exception e) {
log.error("login error ", e);
if (userEntity == null) {
userEntity = new UserEntity();
userEntity.setLoginName(loginName);
}
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}*/
}
@RequestMapping
(
"logout"
)
public
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
recordSysLog
(
request
,
"退出登录"
);
super
.
removeCurrUser
(
request
);
this
.
deleteBlackCookie
(
request
,
response
);
}
@RequestMapping
(
"index"
)
...
...
@@ -178,69 +103,11 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
}
@RequestMapping
(
"validcode"
)
public
String
validCode
(
HttpServletRequest
request
,
HttpServletResponse
response
,
LoginForm
loginForm
)
{
JSONObject
ret
=
new
JSONObject
();
String
loginName
=
loginForm
.
getLoginName
();
String
password
=
loginForm
.
getPassword
();
if
(
StringUtils
.
isEmpty
(
loginName
)
||
StringUtils
.
isEmpty
(
password
))
{
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_MSG
,
"登录名或密码为空"
);
}
UserEntity
user
=
null
;
try
{
user
=
userService
.
doCheckUser
(
loginName
,
password
);
if
(
user
==
null
)
{
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_MSG
,
"用户名或密码不正确"
);
}
else
if
(
StringUtils
.
isEmpty
(
user
.
getMobile
()))
{
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_MSG
,
"用户无正确的手机号"
);
}
else
{
String
mobile
=
StringUtils
.
trim
(
user
.
getMobile
());
String
sessionId
=
request
.
getSession
().
getId
();
String
ip
=
super
.
getRequestIP
(
request
);
boolean
result
=
validCodeService
.
createSmsValidCode
(
sessionId
,
ip
,
mobile
);
if
(
result
)
{
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
}
else
{
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_MSG
,
"验证码发送失败,请稍后在试!"
);
}
}
}
catch
(
Exception
e
)
{
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_MSG
,
"验证码发送失败:"
+
super
.
convertException
(
e
));
}
finally
{
if
(
user
==
null
)
{
user
=
new
UserEntity
();
user
.
setLoginName
(
loginName
);
}
recordSysLog
(
request
,
user
,
"用户获取短信验证码"
);
}
return
ret
.
toJSONString
();
}
protected
void
deleteBlackCookie
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
CookieService
.
deleteCookieForAuth
(
request
,
response
);
}
catch
(
Throwable
e
)
{
}
}
@RequestMapping
(
"parseToken"
)
public
IUser
parseToken
()
throws
Exception
{
IUser
userEntity
=
authTokenService
.
getLoginUser
(
request
);
if
(!
ObjectUtils
.
isEmpty
(
userEntity
))
{
authTokenService
.
verifyToken
(
userEntity
);
return
userEntity
;
}
return
null
;
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
log
.
info
(
"初始化加载
云服务版
登录。。。"
);
log
.
info
(
"初始化加载登录。。。"
);
}
}
bill-manager/src/main/java/com/mortals/xhx/base/login/web/SecurityCodeController.java
View file @
cd51bbd0
...
...
@@ -43,13 +43,6 @@ public class SecurityCodeController
doResponseGif
(
response
,
content
);
break
;
}
// // 获取默认难度和长度的验证码
// String securityCode =
// validCodeService.createImageValidCode(request.getSession().getId(),
// super.getRequestIP(request));
// BufferedImage image = SecurityImage.createImage(securityCode);
// super.doResponseImage(response, image);
}
protected
void
doResponseGif
(
HttpServletResponse
response
,
byte
[]
content
)
{
...
...
bill-manager/src/main/java/com/mortals/xhx/base/login/web/StandaloneLoginController.java
deleted
100644 → 0
View file @
8a450b7c
This diff is collapsed.
Click to expand it.
bill-manager/src/main/java/com/mortals/xhx/base/system/resource/service/impl/ResourceServiceImpl.java
View file @
cd51bbd0
...
...
@@ -26,6 +26,7 @@ import com.mortals.xhx.base.system.role.service.RoleAuthService;
import
com.mortals.xhx.common.key.RedisKey
;
import
com.mortals.xhx.common.utils.ControllerScanUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
...
...
@@ -50,6 +51,7 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
private
ICacheService
cacheService
;
@Autowired
@Lazy
private
RoleAuthService
roleAuthService
;
@Override
...
...
bill-manager/src/main/java/com/mortals/xhx/base/system/role/service/impl/RoleAuthServiceImpl.java
View file @
cd51bbd0
...
...
@@ -18,6 +18,7 @@ import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import
com.mortals.xhx.base.system.role.service.RoleAuthService
;
import
com.mortals.xhx.common.key.RedisKey
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
...
...
@@ -38,6 +39,7 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
@Autowired
private
ICacheService
cacheService
;
@Autowired
@Lazy
private
ResourceService
resourceService
;
@Override
...
...
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