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
67328186
Commit
67328186
authored
Jul 06, 2020
by
李德才
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加Redis 配置
将用户信息保存到Redis
parent
70921a95
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
58 deletions
+79
-58
pom.xml
pom.xml
+13
-3
MainConfig.java
...in/java/com/archser/aserver/common/config/MainConfig.java
+5
-0
IndexController.java
.../java/com/archser/aserver/controller/IndexController.java
+45
-37
config-pro.properties
src/main/resources/config-pro.properties
+10
-10
config.properties
src/main/resources/config.properties
+6
-8
No files found.
pom.xml
View file @
67328186
...
...
@@ -27,7 +27,7 @@
</properties>
<!-- 使用阿里 maven 库 -->
<repositories>
<repositories>
<repository>
<id>
nexus
</id>
<url>
http://nexus.archser.com:8081/repository/maven-public/
</url>
...
...
@@ -88,7 +88,17 @@
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<version>
2.9.0
</version>
</dependency>
<dependency>
<groupId>
de.ruedigermoeller
</groupId>
<artifactId>
fst
</artifactId>
<version>
2.50
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
...
...
@@ -123,7 +133,7 @@
</dependency>
<!-- webSocket 开始-->
<!-- webSocket 开始
-->
<dependency>
<groupId>
javax.websocket
</groupId>
...
...
@@ -144,7 +154,7 @@
<scope>
provided
</scope>
</dependency>
<!-- webSocket 结束-->
<!-- webSocket 结束
-->
<dependency>
<groupId>
org.apache.dubbo
</groupId>
...
...
src/main/java/com/archser/aserver/common/config/MainConfig.java
View file @
67328186
...
...
@@ -29,6 +29,7 @@ import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import
com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory
;
import
com.jfinal.plugin.activerecord.dialect.OracleDialect
;
import
com.jfinal.plugin.druid.DruidPlugin
;
import
com.jfinal.plugin.redis.RedisPlugin
;
import
com.jfinal.render.ViewType
;
import
com.jfinal.server.undertow.UndertowServer
;
import
com.jfinal.server.undertow.WebBuilder
;
...
...
@@ -130,6 +131,10 @@ public class MainConfig extends JFinalConfig {
me
.
add
(
dbPlugin
);
me
.
add
(
arp
);
// 添加Redis 配置
RedisPlugin
redis
=
new
RedisPlugin
(
"redis"
,
PropKit
.
get
(
"redis.url"
),
PropKit
.
get
(
"redis.password"
));
me
.
add
(
redis
);
}
...
...
src/main/java/com/archser/aserver/controller/IndexController.java
View file @
67328186
...
...
@@ -2,24 +2,22 @@ package com.archser.aserver.controller;
import
java.math.BigInteger
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Optional
;
import
org.bouncycastle.crypto.InvalidCipherTextException
;
import
org.bouncycastle.crypto.params.ECPrivateKeyParameters
;
import
org.bouncycastle.pqc.math.linearalgebra.ByteUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.archser.aserver.interceptor.JwtInterceptor
;
import
com.archser.aserver.model.System
;
import
com.archser.aserver.model.User
;
import
com.archser.aserver.service.LogService
;
import
com.archser.aserver.service.UserService
;
import
com.archser.aserver.util.CollectionUtil
;
import
com.archser.aserver.util.HttpRequestUtil
;
import
com.archser.aserver.util.KeysUtil
;
import
com.archser.aserver.util.gm.BCECUtil
;
...
...
@@ -35,6 +33,7 @@ import com.jfinal.kit.StrKit;
import
com.jfinal.log.Log
;
import
com.jfinal.plugin.activerecord.Db
;
import
com.jfinal.plugin.activerecord.Record
;
import
com.jfinal.plugin.redis.Redis
;
import
com.spbportal.sso.SsoToken
;
import
io.jsonwebtoken.JwsHeader
;
...
...
@@ -68,7 +67,6 @@ public class IndexController extends Controller {
@Inject
private
UserService
userService
;
/**
* 首页Action
*/
...
...
@@ -103,13 +101,12 @@ public class IndexController extends Controller {
* 登录验证
*/
@Clear
(
JwtInterceptor
.
class
)
// @Before(LoginValidator.class)
// @Before(LoginValidator.class)
public
void
login
()
{
String
app
=
this
.
getPara
(
"app"
);
String
username
=
this
.
getPara
(
"username"
);
String
password
=
this
.
getPara
(
"password"
);
String
callback
=
this
.
getPara
(
"callback"
);
// 解密用户名和密码
try
{
username
=
decrypt
(
username
);
...
...
@@ -119,10 +116,7 @@ public class IndexController extends Controller {
username
=
this
.
getPara
(
"username"
);
password
=
this
.
getPara
(
"password"
);
}
password
=
HashKit
.
sha256
(
password
);
java
.
lang
.
System
.
out
.
println
(
"Login: "
+
username
);
User
user
=
User
.
dao
.
template
(
"getUser"
,
username
).
findFirst
();
if
(
user
==
null
)
{
this
.
renderJson
(
Ret
.
fail
(
"msg"
,
"用户名或密码不存在: "
+
username
));
...
...
@@ -205,21 +199,21 @@ public class IndexController extends Controller {
}
//查询用户是否有该系统的权限
// boolean homeAuth = userService.checkUserSystemPermission(user.getId(), app);
// if (!homeAuth) {
// this.renderJson(Ret.fail("msg", "您没有权限登录" + system.getTitle() + "系统"));
// logService.saveAsLog("login", username, JwtInterceptor.getIpAddr(getRequest()), "登录失败,原因:您没有权限登录此系统" + app,
// app);
// return;
// }
// boolean homeAuth = userService.checkUserSystemPermission(user.getId(), app);
// if (!homeAuth) {
// this.renderJson(Ret.fail("msg", "您没有权限登录" + system.getTitle() + "系统"));
// logService.saveAsLog("login", username, JwtInterceptor.getIpAddr(getRequest()), "登录失败,原因:您没有权限登录此系统" + app,
// app);
// return;
// }
List
<
System
>
systemList
=
userService
.
findSystemWithUserPermission
(
user
.
getId
());
/** 修改如果登陆用户为admin用户则直接登陆 huwenbin 2020/5/20 start*/
/** 修改如果登陆用户为admin用户则直接登陆 huwenbin 2020/5/20 start
*/
if
(!
"admin"
.
equals
(
user
.
getUsername
()))
{
if
((
systemList
==
null
||
systemList
.
isEmpty
()))
{
this
.
renderJson
(
Ret
.
fail
(
"msg"
,
"您没有权限登录"
+
system
.
getTitle
()
+
"系统"
));
logService
.
saveAsLog
(
"login"
,
username
,
JwtInterceptor
.
getIpAddr
(
getRequest
()),
"登录失败,原因:您没有权限登录此系统"
+
app
,
app
);
logService
.
saveAsLog
(
"login"
,
username
,
JwtInterceptor
.
getIpAddr
(
getRequest
()),
"登录失败,原因:您没有权限登录此系统"
+
app
,
app
);
return
;
}
...
...
@@ -249,6 +243,18 @@ public class IndexController extends Controller {
if
(
errorcount
!=
null
&&
errorcount
!=
0
)
{
this
.
setErrZero
(
user
);
}
/**
* 20200706 lidecai 将用户信息保存到Redis start
*/
Map
<
String
,
Object
>
columns
=
Db
.
findById
(
"AS_USER"
,
"USERNAME"
,
username
).
getColumns
();
Map
<
Object
,
Object
>
userInfo
=
new
HashMap
<>();
userInfo
.
putAll
(
columns
);
Redis
.
use
().
hmset
(
username
+
"_INFO"
,
userInfo
);
// 设置过期时间
Redis
.
use
().
expire
(
username
,
60
*
60
*
24
);
/**
* 20200706 lidecai 将用户信息保存到Redis end
*/
this
.
renderJson
(
Ret
.
ok
(
"token"
,
jws
).
set
(
"callback"
,
callback
));
logService
.
saveAsLog
(
"login"
,
username
,
JwtInterceptor
.
getIpAddr
(
getRequest
()),
username
+
"登录"
+
app
+
"成功"
,
app
);
...
...
@@ -266,23 +272,25 @@ public class IndexController extends Controller {
//密码错误时判断错误次数是否为5次
private
boolean
checkErrorCount
(
User
user
)
{
Kv
cond
=
Kv
.
by
(
"id"
,
user
.
getId
()).
set
(
"hour"
,
hour
).
set
(
"permitLoginTimes"
,
permitLoginTimes
);
List
<
Record
>
currentList
=
Db
.
find
(
Db
.
getSqlPara
(
"getErrorCount"
,
cond
));
Kv
cond
=
Kv
.
by
(
"id"
,
user
.
getId
()).
set
(
"hour"
,
hour
).
set
(
"permitLoginTimes"
,
permitLoginTimes
);
List
<
Record
>
currentList
=
Db
.
find
(
Db
.
getSqlPara
(
"getErrorCount"
,
cond
));
int
currentNum
=
0
;
for
(
Record
record
:
currentList
)
{
currentNum
=
Integer
.
parseInt
(
record
.
get
(
"flag"
).
toString
());
}
if
(
currentNum
>=
permitLoginTimes
)
{
return
true
;
}
else
{
}
else
{
//执行+1或=1的操作
Db
.
update
(
Db
.
getSqlPara
(
"updateForErr"
,
cond
));
Db
.
update
(
Db
.
getSqlPara
(
"updateForErr"
,
cond
));
return
false
;
}
}
//密码正确时判断次数和锁定时间是否在指定范围内
private
boolean
checkWhenPwdOk
(
User
user
)
{
List
<
Record
>
currentList
=
Db
.
find
(
Db
.
getSqlPara
(
"checkWhenPwdOk"
,
Kv
.
by
(
"id"
,
user
.
getId
()).
set
(
"hour"
,
hour
).
set
(
"permitLoginTimes"
,
permitLoginTimes
)));
List
<
Record
>
currentList
=
Db
.
find
(
Db
.
getSqlPara
(
"checkWhenPwdOk"
,
Kv
.
by
(
"id"
,
user
.
getId
()).
set
(
"hour"
,
hour
).
set
(
"permitLoginTimes"
,
permitLoginTimes
)));
int
currentNum
=
0
;
if
(
currentList
==
null
||
currentList
.
size
()
==
0
)
{
return
true
;
...
...
@@ -290,9 +298,9 @@ public class IndexController extends Controller {
for
(
Record
record
:
currentList
)
{
currentNum
=
Integer
.
parseInt
(
record
.
get
(
"flag"
).
toString
());
}
if
(
currentNum
>=
permitLoginTimes
)
{
if
(
currentNum
>=
permitLoginTimes
)
{
return
false
;
}
else
{
}
else
{
return
true
;
}
}
...
...
@@ -306,10 +314,10 @@ public class IndexController extends Controller {
public
void
ssoByPortalSystem
()
{
try
{
//获取app
String
app
=
getPara
(
"app"
,
null
);
if
(
app
==
null
)
{
renderJson
(
Ret
.
fail
(
"msg"
,
"获取服务信息失败"
));
return
;
String
app
=
getPara
(
"app"
,
null
);
if
(
app
==
null
)
{
renderJson
(
Ret
.
fail
(
"msg"
,
"获取服务信息失败"
));
return
;
}
//获取到门户系统的Token
String
ssotoken
=
getPara
(
"ssotoken"
);
...
...
@@ -320,12 +328,12 @@ public class IndexController extends Controller {
//获取用户
Record
user
=
userService
.
getUserInfoByPersonCode
(
personCode
);
System
system
=
System
.
dao
.
template
(
"getSystemPrivatekey"
,
app
).
findFirst
();
if
(
system
==
null
)
{
renderJson
(
Ret
.
fail
(
"msg"
,
"获取服务信息失败"
));
return
;
if
(
system
==
null
)
{
renderJson
(
Ret
.
fail
(
"msg"
,
"获取服务信息失败"
));
return
;
}
//判断用户是否存在
if
(
user
!=
null
&&
user
.
getStr
(
"username"
)
!=
null
)
{
if
(
user
!=
null
&&
user
.
getStr
(
"username"
)
!=
null
)
{
String
jws
=
Jwts
.
builder
()
// 设置密匙ID
.
setHeaderParam
(
JwsHeader
.
KEY_ID
,
system
.
getKeyid
())
...
...
@@ -341,14 +349,14 @@ public class IndexController extends Controller {
.
signWith
(
KeysUtil
.
privatekey
(
system
.
getPrivatekey
()),
SignatureAlgorithm
.
RS256
).
compact
();
this
.
renderJson
(
Ret
.
ok
(
"token"
,
jws
));
return
;
}
else
{
this
.
renderJson
(
Ret
.
fail
(
"msg"
,
"没有找到当前用户"
));
}
else
{
this
.
renderJson
(
Ret
.
fail
(
"msg"
,
"没有找到当前用户"
));
return
;
}
}
catch
(
Exception
e
)
{
// TODO: handle exception
e
.
printStackTrace
();
this
.
renderJson
(
Ret
.
fail
(
"msg"
,
"登录出错!"
));
this
.
renderJson
(
Ret
.
fail
(
"msg"
,
"登录出错!"
));
}
}
...
...
src/main/resources/config-pro.properties
View file @
67328186
dbType
=
DM
jdbcUrl
=
jdbc:dm://
39.104.28.145
:5236
jdbcUrl
=
jdbc:dm://
192.168.31.18
:5236
jdbc.driver
=
dm.jdbc.driver.DmDriver
user
=
archser
_yz
password
=
archser_
yz
basic.url
=
http://
39.104.28.145
:11028
user
=
archser
password
=
archser_
123
basic.url
=
http://
192.168.31.18
:11028
devMode
=
true
engineDevMode
=
true
authUrl
=
http://125.77.26.133:7001/auth/token
userInfoUrl
=
http://125.77.26.133:7001/api/info/user_info
redi
rect_uri
=
http://192.168.31.17:8080/
redis.url
=
192.168.31.18
redi
s.password
=
archser_redis
# --- 消息中心websocket配置 ---
## 定时发送消息的周期 单位毫秒
messageWsDelay
=
5000
messageWsDelay
=
5000
0
## 延期,第二次发送消息的延期时间,第一次发送在开始连接时就会发送 单位毫秒
messageWsPeriod
=
5000
messageWsPeriod
=
5000
0
## 消息发送成功后,等待客户端反馈时间,超出此时间表示连接已经断开,会关闭连接 单位毫秒
messageWsTimeout
=
30000
## 是否开启消息中心的websocket
openMessageWebSocket
=
true
MyIpAddress
=
127.0.0.1,
39.104.28.145
MyIpAddress
=
127.0.0.1,
192.168.31.18
src/main/resources/config.properties
View file @
67328186
...
...
@@ -9,23 +9,21 @@ dbType=DM
jdbcUrl
=
jdbc:dm://192.168.31.119:5236
jdbc.driver
=
dm.jdbc.driver.DmDriver
user
=
archser
_yz
password
=
archser_
yz
user
=
archser
password
=
archser_
123
basic.url
=
http://192.168.31.119:11028
devMode
=
true
engineDevMode
=
true
authUrl
=
http://125.77.26.133:7001/auth/token
userInfoUrl
=
http://125.77.26.133:7001/api/info/user_info
redirect_uri
=
http://192.168.31.17:8080/
redis.url
=
192.168.31.18
redis.password
=
archser_redis
# --- \u6D88\u606F\u4E2D\u5FC3websocket\u914D\u7F6E ---
## \u5B9A\u65F6\u53D1\u9001\u6D88\u606F\u7684\u5468\u671F \u5355\u4F4D\u6BEB\u79D2
messageWsDelay
=
5000
messageWsDelay
=
5000
0
## \u5EF6\u671F\uFF0C\u7B2C\u4E8C\u6B21\u53D1\u9001\u6D88\u606F\u7684\u5EF6\u671F\u65F6\u95F4\uFF0C\u7B2C\u4E00\u6B21\u53D1\u9001\u5728\u5F00\u59CB\u8FDE\u63A5\u65F6\u5C31\u4F1A\u53D1\u9001 \u5355\u4F4D\u6BEB\u79D2
messageWsPeriod
=
5000
messageWsPeriod
=
5000
0
## \u6D88\u606F\u53D1\u9001\u6210\u529F\u540E\uFF0C\u7B49\u5F85\u5BA2\u6237\u7AEF\u53CD\u9988\u65F6\u95F4\uFF0C\u8D85\u51FA\u6B64\u65F6\u95F4\u8868\u793A\u8FDE\u63A5\u5DF2\u7ECF\u65AD\u5F00\uFF0C\u4F1A\u5173\u95ED\u8FDE\u63A5 \u5355\u4F4D\u6BEB\u79D2
messageWsTimeout
=
30000
## \u662F\u5426\u5F00\u542F\u6D88\u606F\u4E2D\u5FC3\u7684websocket
...
...
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