Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
chnmuseum-party
Project
Project
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
liqin
chnmuseum-party
Commits
9f392bd3
Commit
9f392bd3
authored
Apr 28, 2021
by
liqin
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
35817894
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
20 deletions
+12
-20
JwtTokenUtil.java
src/main/java/cn/chnmuseum/party/auth/util/JwtTokenUtil.java
+7
-14
TUser.java
src/main/java/cn/chnmuseum/party/model/TUser.java
+2
-3
ChinaMobileRestApiController.java
...um/party/web/controller/ChinaMobileRestApiController.java
+2
-2
TUserMapper.xml
src/main/resources/mapper/TUserMapper.xml
+1
-1
No files found.
src/main/java/cn/chnmuseum/party/auth/util/JwtTokenUtil.java
View file @
9f392bd3
...
...
@@ -6,28 +6,20 @@ import com.auth0.jwt.JWTVerifier;
import
com.auth0.jwt.algorithms.Algorithm
;
import
com.auth0.jwt.exceptions.JWTDecodeException
;
import
com.auth0.jwt.interfaces.DecodedJWT
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.io.UnsupportedEncodingException
;
import
java.time.LocalDateTime
;
@Component
@Slf4j
public
class
JwtTokenUtil
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
JwtTokenUtil
.
class
);
private
static
String
jwtTokenSecret
;
private
static
String
jwtTokenIssuer
;
private
static
String
jwtTokenExpiration
;
@Resource
private
StringRedisTemplate
stringRedisTemplate
;
@Value
(
"${jwt.secret}"
)
public
void
setJwtTokenSecret
(
String
jwtTokenSecret
)
{
JwtTokenUtil
.
jwtTokenSecret
=
jwtTokenSecret
;
...
...
@@ -56,7 +48,7 @@ public class JwtTokenUtil {
DecodedJWT
jwt
=
verifier
.
verify
(
token
);
return
jwt
.
getClaim
(
"user_id"
).
asString
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
log
.
error
(
e
.
getMessage
());
return
null
;
}
}
...
...
@@ -95,13 +87,14 @@ public class JwtTokenUtil {
* @param username 用户名
* @return 加密的token
*/
public
static
String
sign
(
String
username
,
String
employeeId
)
throws
UnsupportedEncodingException
{
public
static
String
sign
(
String
username
,
String
employeeId
)
{
LocalDateTime
currentTime
=
DateUtil80
.
getDateTimeOfTimestamp
(
System
.
currentTimeMillis
());
Algorithm
algorithm
=
Algorithm
.
HMAC512
(
jwtTokenSecret
);
// 附带username信息
return
JWT
.
create
().
withIssuer
(
jwtTokenIssuer
)
// 创建时间
.
withIssuedAt
(
DateUtil80
.
getCurrDateTime
()).
withSubject
(
username
).
withClaim
(
"user_id"
,
employeeId
)
.
withIssuedAt
(
DateUtil80
.
getCurrDateTime
()).
withSubject
(
username
)
.
withClaim
(
"user_id"
,
employeeId
)
.
withExpiresAt
(
DateUtil80
.
asDate
(
currentTime
.
plusMinutes
(
240
))).
sign
(
algorithm
);
}
...
...
@@ -111,7 +104,7 @@ public class JwtTokenUtil {
* @param username 用户名
* @return 加密的token
*/
public
static
String
signByRememberMe
(
String
username
,
Integer
userId
)
throws
UnsupportedEncodingException
{
public
static
String
signByRememberMe
(
String
username
,
Integer
userId
)
{
LocalDateTime
currentTime
=
DateUtil80
.
getDateTimeOfTimestamp
(
System
.
currentTimeMillis
());
Algorithm
algorithm
=
Algorithm
.
HMAC512
(
jwtTokenSecret
);
// 附带username信息
...
...
src/main/java/cn/chnmuseum/party/model/TUser.java
View file @
9f392bd3
...
...
@@ -86,11 +86,11 @@ public class TUser implements Serializable {
private
Boolean
permanent
;
@ApiModelProperty
(
"生效日期"
)
@TableField
(
value
=
"effective_date"
,
updateStrategy
=
FieldStrategy
.
IGNORED
)
@TableField
(
value
=
"effective_date"
,
updateStrategy
=
FieldStrategy
.
IGNORED
)
private
LocalDate
effectiveDate
;
@ApiModelProperty
(
"失效日期"
)
@TableField
(
value
=
"exired_date"
,
updateStrategy
=
FieldStrategy
.
IGNORED
)
@TableField
(
value
=
"exired_date"
,
updateStrategy
=
FieldStrategy
.
IGNORED
)
private
LocalDate
exiredDate
;
@ApiModelProperty
(
value
=
"状态"
,
allowableValues
=
"启用 ENABLE, 禁用DISABLE"
)
...
...
@@ -137,7 +137,6 @@ public class TUser implements Serializable {
@TableField
(
exist
=
false
)
private
String
orgName
;
@ApiModelProperty
(
"机构编码"
)
@TableField
(
exist
=
false
)
private
String
orgCode
;
...
...
src/main/java/cn/chnmuseum/party/web/controller/ChinaMobileRestApiController.java
View file @
9f392bd3
...
...
@@ -178,7 +178,6 @@ public class ChinaMobileRestApiController extends BaseController {
JSONObject
resultMap
=
new
JSONObject
(
true
);
TUser
user
;
if
(
StringUtils
.
isNoneBlank
(
username
))
{
try
{
//访问一次,计数一次
// ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
...
...
@@ -241,7 +240,8 @@ public class ChinaMobileRestApiController extends BaseController {
jsonObject
.
put
(
"userName"
,
user
.
getUserName
());
jsonObject
.
put
(
"expire"
,
TimeUtils
.
format
(
LocalDateTime
.
now
().
plusMinutes
(
240
),
TimeUtils
.
FORMAT_ONE
));
jsonObject
.
put
(
"expireDate"
,
user
.
getExiredDate
());
jsonObject
.
put
(
"orgCode"
,
user
.
getOrgId
());
jsonObject
.
put
(
"orgId"
,
user
.
getOrgId
());
jsonObject
.
put
(
"orgCode"
,
user
.
getOrgCode
());
jsonObject
.
put
(
"orgName"
,
user
.
getOrgName
());
resultMap
.
put
(
"resultCode"
,
"200"
);
...
...
src/main/resources/mapper/TUserMapper.xml
View file @
9f392bd3
...
...
@@ -45,7 +45,7 @@
</sql>
<select
id=
"selectByUsername"
resultMap=
"BaseResultMap"
>
select u.*,
o.name org_name,a.full_name area_name,o.code org_cod
e
select u.*,
o.name org_name, o.code org_code, a.full_name area_nam
e
from t_user u
left join t_organ o on o.id = u.org_id
left join t_area a on u.area_id = a.id
...
...
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