Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
base-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
赵啸非
base-platform
Commits
aca13562
Commit
aca13562
authored
Feb 15, 2022
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改文档与添加登录返回token和过期时间
parent
101b89cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
71 deletions
+8
-71
base-manager/src/main/java/com/mortals/xhx/base/login/web/LoginController.java
.../java/com/mortals/xhx/base/login/web/LoginController.java
+8
-71
No files found.
base-manager/src/main/java/com/mortals/xhx/base/login/web/LoginController.java
View file @
aca13562
...
...
@@ -8,6 +8,8 @@ import java.util.Set;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
cn.hutool.core.lang.UUID
;
import
com.mortals.framework.util.*
;
import
com.mortals.xhx.base.system.menu.model.MenuEntity
;
import
com.mortals.xhx.base.system.menu.service.MenuService
;
import
com.mortals.xhx.base.system.resource.service.ResourceService
;
...
...
@@ -32,11 +34,6 @@ import com.mortals.framework.model.CookieInfo;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.service.ITokenService
;
import
com.mortals.framework.service.IUser
;
import
com.mortals.framework.util.AESUtil
;
import
com.mortals.framework.util.DataUtil
;
import
com.mortals.framework.util.HttpUtil
;
import
com.mortals.framework.util.MD5Util
;
import
com.mortals.framework.util.StringUtils
;
import
com.mortals.framework.web.BaseCRUDJsonController
;
import
static
com
.
mortals
.
framework
.
ap
.
SysConstains
.
PROP_COOKIE_DOMAIN
;
...
...
@@ -106,11 +103,12 @@ public class LoginController extends BaseCRUDJsonController<UserService, UserFor
data
.
put
(
"userType"
,
userEntity
.
getUserType
());
//设置token 和过期时间
CookieInfo
loginCookie
=
CookieService
.
getLoginCookie
(
request
);
if
(!
ObjectUtils
.
isEmpty
(
loginCookie
)){
data
.
put
(
"token"
,
loginCookie
.
getToken
());
data
.
put
(
"expiresTime"
,
loginCookie
.
getExpiresTime
().
getTime
());
}
// CookieInfo loginCookie = CookieService.getLoginCookie(request);
// if(!ObjectUtils.isEmpty(loginCookie)){
//
// }
data
.
put
(
"token"
,
UUID
.
fastUUID
().
toString
());
data
.
put
(
"expiresTime"
,
DateUtils
.
addCurrDate
(
7
).
getTime
());
// this.generateBlackCookie(request, response, loginName, urls);
ret
.
put
(
KEY_RESULT_DATA
,
data
);
...
...
@@ -236,68 +234,7 @@ public class LoginController extends BaseCRUDJsonController<UserService, UserFor
}
}
//重写登录cook设置
private
static
CookieInfo
setLoginCookie
(
HttpServletResponse
response
,
IUser
user
,
String
securityKey
,
String
cookieDomain
,
int
cookieMaxAge
)
{
try
{
//设置cookie有效串,防篡改 LTPA版本号+创建时间+过期时间+用户名+LTPA密钥
// SHA-1=LTPA版本号+创建时间+过期时间+用户名+Domino LTPA 密钥
// LTPA Cookie= Base64(LTPA版本号+创建时间+过期时间+用户名+SHA-1)
Calendar
cal
=
Calendar
.
getInstance
();
long
currTime
=
cal
.
getTime
().
getTime
()
/
1000
;
cal
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
long
expiresTime
=
cal
.
getTime
().
getTime
()
/
1000
;
Long
userId
=
user
.
getId
();
int
userType
=
user
.
getUserType
();
String
loginName
=
user
.
getLoginName
();
String
userName
=
user
.
getRealName
();
Long
customerId
=
user
.
getCustomerId
();
Long
customerJoinId
=
user
.
getCustomerJoinId
();
String
customerNum
=
user
.
getCustomerNum
();
String
customerJson
=
""
;
Long
deptId
=
user
.
getDeptId
();
Long
roleId
=
0L
;
Long
siteId
=
user
.
getSiteId
();
String
deptName
=
user
.
getDeptName
();
int
deptManager
=
user
.
isManager
()
?
1
:
0
;
if
(
customerId
!=
null
||
customerJoinId
!=
null
||
StringUtils
.
isNotEmpty
(
customerNum
))
{
try
{
customerJson
=
DataUtil
.
conver2Long
(
customerId
)
+
CookieService
.
COOKIE_STORE_SPLIT
+
DataUtil
.
conver2Long
(
customerJoinId
)
+
CookieService
.
COOKIE_STORE_SPLIT
+
StringUtils
.
trim
(
customerNum
)
+
CookieService
.
COOKIE_STORE_SPLIT
+
DataUtil
.
conver2Int
(
deptId
)
+
CookieService
.
COOKIE_STORE_SPLIT
+
StringUtils
.
trim
(
deptName
)
+
CookieService
.
COOKIE_STORE_SPLIT
+
deptManager
+
CookieService
.
COOKIE_STORE_SPLIT
+
roleId
+
CookieService
.
COOKIE_STORE_SPLIT
;
customerJson
=
AESUtil
.
encrypt
(
customerJson
,
securityKey
);
}
catch
(
Exception
e
)
{
logger
.
debug
(
"用户的关联信息加密异常-->"
+
e
.
getMessage
());
}
}
customerJson
=
StringUtils
.
trim
(
customerJson
);
String
cookieStroe
=
CookieService
.
COOKIE_STORE_VERSION
+
CookieService
.
COOKIE_STORE_SPLIT
+
currTime
+
CookieService
.
COOKIE_STORE_SPLIT
+
expiresTime
;
String
pinId
=
AESUtil
.
encrypt
(
userId
.
toString
()
+
CookieService
.
COOKIE_STORE_SPLIT
+
userType
+
CookieService
.
COOKIE_STORE_SPLIT
+
siteId
,
securityKey
);
String
trackId
=
MD5Util
.
getSignAndMD5
(
cookieStroe
,
pinId
,
loginName
,
userName
,
customerJson
,
securityKey
);
HttpUtil
.
setCookieValue
(
response
,
SysConstains
.
COOKIE_PIN
,
loginName
,
cookieDomain
,
cookieMaxAge
);
HttpUtil
.
setCookieValue
(
response
,
SysConstains
.
COOKIE_PIN_ID
,
pinId
,
cookieDomain
,
cookieMaxAge
);
HttpUtil
.
setCookieValue
(
response
,
SysConstains
.
COOKIE_UNICK
,
userName
,
cookieDomain
,
cookieMaxAge
);
HttpUtil
.
setCookieValue
(
response
,
SysConstains
.
COOKIE_STORE
,
cookieStroe
,
cookieDomain
,
cookieMaxAge
);
HttpUtil
.
setCookieValue
(
response
,
SysConstains
.
COOKIE_STORE_TOKEN
,
trackId
,
cookieDomain
,
cookieMaxAge
);
if
(
StringUtils
.
isNotEmpty
(
customerJson
))
{
HttpUtil
.
setCookieValue
(
response
,
SysConstains
.
COOKIE_UNION
,
customerJson
,
cookieDomain
,
cookieMaxAge
);
}
CookieInfo
info
=
new
CookieInfo
(
trackId
,
new
Date
(
currTime
),
new
Date
(
expiresTime
),
user
);
return
info
;
}
catch
(
Throwable
e
)
{
logger
.
warn
(
"设置用户的cookie异常-->"
+
e
.
getMessage
());
return
null
;
}
}
//
// @Override
// protected void saveCurrUser(HttpServletRequest request, HttpServletResponse response, IUser user, int maxAge) {
// String securityKey = GlobalSysInfo.getPropertyValue(PROP_COOKIE_SECURITY_KEY);
...
...
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