Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
aserver
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
15所TongWeb
aserver
Commits
cc0c82c6
Commit
cc0c82c6
authored
Nov 08, 2020
by
胡文斌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改消息跳转
parent
94e0a86f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
3 deletions
+82
-3
IndexController.java
.../java/com/archser/aserver/controller/IndexController.java
+1
-1
SystemController.java
...java/com/archser/aserver/controller/SystemController.java
+14
-2
JwtUtils.java
src/main/java/com/archser/aserver/util/JwtUtils.java
+67
-0
No files found.
src/main/java/com/archser/aserver/controller/IndexController.java
View file @
cc0c82c6
...
...
@@ -59,7 +59,7 @@ public class IndexController extends Controller {
/**
* 超期时间:24小时,即:24 * 60 * 60 * 1000
*/
p
rivate
static
int
EXPIRATION
=
24
*
60
*
60
*
1000
;
p
ublic
static
final
int
EXPIRATION
=
24
*
60
*
60
*
1000
;
private
static
int
permitLoginTimes
=
5
;
// 允许登陆次数
private
static
int
hour
=
2
;
// 两小时内不可登录
@Inject
...
...
src/main/java/com/archser/aserver/controller/SystemController.java
View file @
cc0c82c6
package
com
.
archser
.
aserver
.
controller
;
import
java.util.List
;
import
com.archser.aserver.interceptor.JwtInterceptor
;
import
com.archser.aserver.model.System
;
import
com.archser.aserver.service.LogService
;
import
com.archser.aserver.service.SystemService
;
import
com.archser.aserver.util.JwtUtils
;
import
com.jfinal.aop.Before
;
import
com.jfinal.aop.Clear
;
import
com.jfinal.aop.Inject
;
...
...
@@ -14,6 +13,8 @@ import com.jfinal.kit.Ret;
import
com.jfinal.kit.StrKit
;
import
com.jfinal.plugin.activerecord.tx.Tx
;
import
java.util.List
;
/**
* 应用相关
*
...
...
@@ -150,4 +151,15 @@ public class SystemController extends Controller {
this
.
renderJson
(
Ret
.
ok
(
"system"
,
system
));
}
/**
* 获取系统url和生成用户token
*/
public
void
getTokenAndUrl
()
{
Integer
systemId
=
this
.
getParaToInt
(
"systemId"
);
String
username
=
this
.
getAttrForStr
(
"username"
);
System
system
=
System
.
dao
.
findById
(
systemId
);
String
token
=
JwtUtils
.
generateToken
(
system
,
username
);
this
.
renderJson
(
Ret
.
ok
(
"token"
,
token
).
set
(
"url"
,
system
.
getUrl
()));
}
}
src/main/java/com/archser/aserver/util/JwtUtils.java
0 → 100644
View file @
cc0c82c6
package
com
.
archser
.
aserver
.
util
;
import
com.archser.aserver.controller.IndexController
;
import
com.archser.aserver.interceptor.JwtInterceptor
;
import
com.archser.aserver.model.System
;
import
com.sun.deploy.util.URLUtil
;
import
io.jsonwebtoken.JwsHeader
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
io.undertow.util.URLUtils
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.Date
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* @Auther: huwenbin
* @Date: 2020/11/6 18:16
*/
public
class
JwtUtils
{
public
static
String
generateToken
(
System
system
,
String
username
)
{
URL
url
=
null
;
try
{
url
=
new
URL
(
system
.
getUrl
());
String
host
=
url
.
getHost
();
return
generateToken
(
system
.
getKeyid
(),
system
.
getPrivatekey
(),
system
.
getName
(),
username
,
host
);
}
catch
(
MalformedURLException
ignored
)
{
}
return
null
;
}
public
static
void
main
(
String
[]
args
)
throws
MalformedURLException
{
URL
url
=
new
URL
(
"http://39.104.28.145:11028"
);
String
host
=
url
.
getHost
();
java
.
lang
.
System
.
out
.
println
(
host
);
}
/**
* 生成Token
* @param keyId 系统keyid
* @param privateKey 系统私钥
* @param app 系统名称
* @param username 用户名
* @param ip ip地址
* @return token
*/
public
static
String
generateToken
(
String
keyId
,
String
privateKey
,
String
app
,
String
username
,
String
ip
)
{
return
Jwts
.
builder
()
// 设置密匙ID
.
setHeaderParam
(
JwsHeader
.
KEY_ID
,
keyId
)
// 赋予应用
.
setSubject
(
app
)
// 签发时间
.
setIssuedAt
(
new
Date
())
// 超期时间
.
setExpiration
(
new
Date
(
java
.
lang
.
System
.
currentTimeMillis
()
+
IndexController
.
EXPIRATION
))
// 用户名
.
claim
(
"name"
,
username
).
claim
(
"ip"
,
ip
)
// 签名
.
signWith
(
KeysUtil
.
privatekey
(
privateKey
),
SignatureAlgorithm
.
RS256
).
compact
();
}
}
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