Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hp-smart
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
platform
hp-smart
Commits
6a1981bb
Commit
6a1981bb
authored
Apr 11, 2024
by
宋祥
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.移动端登录验证接口支持手机号
parent
427c3f48
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
ServiceXSUserJwt.java
...a/com/baosight/xservices/xs/service/ServiceXSUserJwt.java
+92
-0
No files found.
src/main/java/com/baosight/xservices/xs/service/ServiceXSUserJwt.java
0 → 100644
View file @
6a1981bb
package
com
.
baosight
.
xservices
.
xs
.
service
;
import
com.baosight.iplat4j.core.FrameworkInfo
;
import
com.baosight.iplat4j.core.ei.EiInfo
;
import
com.baosight.iplat4j.core.log.Logger
;
import
com.baosight.iplat4j.core.log.LoggerFactory
;
import
com.baosight.iplat4j.core.security.base.SecurityFactory
;
import
com.baosight.iplat4j.core.security.user.IUserManager
;
import
com.baosight.iplat4j.core.security.user.User
;
import
com.baosight.iplat4j.core.service.impl.ServiceBase
;
import
com.baosight.iplat4j.core.util.StringUtils
;
import
com.baosight.iplat4j.core.web.threadlocal.UserSession
;
import
com.baosight.xservices.xs.jwt.JwtTokenValidator
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
/**
* 重写
*
* @author:songx
* @date:2024/4/11,15:28
*/
public
class
ServiceXSUserJwt
extends
ServiceBase
{
Logger
logger
=
LoggerFactory
.
getLogger
(
ServiceXSUserJwt
.
class
);
@Autowired
JwtTokenValidator
jwtTokenValidator
;
public
ServiceXSUserJwt
()
{
}
public
EiInfo
generateJwt
(
EiInfo
inInfo
)
{
String
username
=
inInfo
.
getString
(
"loginName"
);
String
password
=
inInfo
.
getString
(
"password"
);
String
audience
=
inInfo
.
getString
(
"audience"
);
EiInfo
outInfo
;
try
{
if
(!
StringUtils
.
isNotEmpty
(
audience
))
{
audience
=
FrameworkInfo
.
getProjectEname
().
toUpperCase
();
}
IUserManager
um
=
SecurityFactory
.
getUserManager
();
User
user
=
um
.
getUser
(
username
);
if
(
user
==
null
)
{
throw
new
UsernameNotFoundException
(
"Can't find user!"
);
}
outInfo
=
um
.
checkIdentity
(
user
.
getLoginName
(),
password
);
if
(
outInfo
.
getStatus
()
>
0
)
{
Map
tokenMap
=
new
HashMap
();
tokenMap
.
put
(
"sub"
,
user
.
getLoginName
());
tokenMap
.
put
(
"uid"
,
user
.
getUserId
());
Object
userCname
=
user
.
get
(
"userName"
);
if
(
userCname
!=
null
)
{
tokenMap
.
put
(
"ucn"
,
userCname
.
toString
());
}
if
(!
StringUtils
.
isNotEmpty
(
audience
))
{
audience
=
FrameworkInfo
.
getProjectEname
().
toUpperCase
();
}
String
token
=
this
.
jwtTokenValidator
.
generateToken
(
tokenMap
,
audience
);
outInfo
.
set
(
"token"
,
token
);
outInfo
.
set
(
"x-token"
,
token
);
outInfo
.
getAttr
().
put
(
"x-token"
,
token
);
}
}
catch
(
Exception
var11
)
{
outInfo
=
new
EiInfo
();
this
.
logger
.
error
(
var11
.
getMessage
(),
var11
);
outInfo
.
setStatus
(-
1
);
outInfo
.
setMsg
(
var11
.
getMessage
());
}
return
outInfo
;
}
public
EiInfo
validateTest
(
EiInfo
inInfo
)
{
new
HashMap
();
inInfo
.
set
(
"userSessionData"
,
new
HashMap
(
UserSession
.
getData
()));
inInfo
.
set
(
"loginName"
,
UserSession
.
getLoginName
());
return
inInfo
;
}
public
EiInfo
validateTokenTest
(
EiInfo
inInfo
)
{
String
token
=
inInfo
.
getString
(
"token"
);
Map
result
=
this
.
jwtTokenValidator
.
validateToken
(
token
);
inInfo
.
set
(
"result"
,
result
);
return
inInfo
;
}
}
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