Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nouiWithSpringMVC
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
gechengyang
nouiWithSpringMVC
Commits
a46253ca
Commit
a46253ca
authored
Sep 27, 2020
by
fukai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持objtyp和objinr加入过滤
parent
ab4d1bed
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
13 deletions
+90
-13
LoginController.java
...org/sss/presentation/noui/controller/LoginController.java
+4
-5
RedisKeyExpirationListener.java
...s/presentation/noui/redis/RedisKeyExpirationListener.java
+9
-0
NoUiPresentationUtil.java
.../org/sss/presentation/noui/util/NoUiPresentationUtil.java
+51
-8
NoUiUtils.java
src/main/java/org/sss/presentation/noui/util/NoUiUtils.java
+5
-0
RedisUtil.java
src/main/java/org/sss/presentation/noui/util/RedisUtil.java
+21
-0
No files found.
src/main/java/org/sss/presentation/noui/controller/LoginController.java
View file @
a46253ca
...
...
@@ -20,10 +20,7 @@ import org.sss.presentation.noui.context.NoUiContextManager;
import
org.sss.presentation.noui.jwt.JWT
;
import
org.sss.presentation.noui.jwt.JwtLogin
;
import
org.sss.presentation.noui.jwt.RedisLoginInfo
;
import
org.sss.presentation.noui.util.NoUiPresentationUtil
;
import
org.sss.presentation.noui.util.NumericUtil
;
import
org.sss.presentation.noui.util.RedisUtil
;
import
org.sss.presentation.noui.util.StringUtil
;
import
org.sss.presentation.noui.util.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
...
...
@@ -95,6 +92,8 @@ public class LoginController {
RedisLoginInfo
redisLoginInfo
=
new
RedisLoginInfo
(
userId
,
token
,
NumericUtil
.
sessionTimeOut
(),
sysmodBytes
,
noUiRequest
.
getTerminalType
());
redisLoginInfo
.
setUserInr
((
String
)
inridf
.
getValue
());
//设置当前用户主键
NoUiUtils
.
logout
(
userId
,
"*"
);
//清理可能存在的历史缓存
RedisUtil
.
set
(
StringUtil
.
userUniqueId
(
noUiRequest
),
redisLoginInfo
);
//解决初次登陆,超期限登陆
...
...
@@ -156,7 +155,7 @@ public class LoginController {
try
{
NoUiRequest
noUiRequest
=
new
NoUiRequest
(
request
,
""
,
null
);
RedisUtil
.
delete
(
StringUtil
.
userUniqueId
(
noUiRequest
));
NoUiUtils
.
logout
(
noUiRequest
.
getUserId
(),
"*"
);
//清理可能存在的历史缓存
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
"退出成功"
,
null
);
}
catch
(
Exception
e
)
{
...
...
src/main/java/org/sss/presentation/noui/redis/RedisKeyExpirationListener.java
View file @
a46253ca
...
...
@@ -11,6 +11,8 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import
org.springframework.stereotype.Service
;
import
org.sss.module.hibernate.HibernateUtils
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.util.NoUiPresentationUtil
;
import
org.sss.presentation.noui.util.RedisUtil
;
@Service
public
class
RedisKeyExpirationListener
extends
KeyExpirationEventMessageListener
{
...
...
@@ -37,6 +39,13 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
transaction
.
commit
();
session
.
close
();
log
.
info
(
"clear expire user "
+
userId
+
" session success"
);
//清理缓存set
try
{
RedisUtil
.
delete
(
NoUiPresentationUtil
.
getCacheSetKey
(
userId
));
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
}
}
}
...
...
src/main/java/org/sss/presentation/noui/util/NoUiPresentationUtil.java
View file @
a46253ca
...
...
@@ -239,29 +239,30 @@ public class NoUiPresentationUtil {
if
(
val
instanceof
IModuleList
<?>)
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
IModuleList
<?>
moduleList
=
(
IModuleList
<?>)
val
;
List
<
String
>
cacheRecord
=
new
ArrayList
<>();
String
paramsKey
[]
=
getParamKeys
(
moduleList
);
for
(
int
index
=
0
;
index
<
moduleList
.
size
();
index
++)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
IModule
module
=
moduleList
.
get
(
index
);
Collection
<
IDatafield
>
datafields
=
module
.
getDatafields
();
String
[]
paramsKey
=
(
String
[])
moduleList
.
getAttribute
(
"KEY_PARAMS"
);
if
(
paramsKey
!=
null
)
paramsKey
=
new
String
[]{
"inr"
,
"$objtyp"
};
for
(
IDatafield
<
Object
>
datafield
:
datafields
)
{
map
.
put
(
changeForELCS
(
datafield
.
getName
()),
handle
(
datafield
.
getValue
(),
datafield
));
}
String
[]
keyParams
=
new
String
[
paramsKey
.
length
];
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
paramsKey
.
length
;
i
++)
{
if
(
"$objtyp"
.
equals
(
paramsKey
[
i
]))
keyParams
[
i
]
=
module
.
getClass
().
getSimpleName
().
toLowerCase
(
);
//module type
sb
.
append
(
module
.
getClass
().
getSimpleName
().
toLowerCase
()
);
//module type
else
keyParams
[
i
]
=
map
.
get
(
paramsKey
[
i
]).
toString
(
);
sb
.
append
(
map
.
get
(
paramsKey
[
i
]).
toString
()
);
}
String
safeCode
=
NoUiUtils
.
genSafeCode
(
keyParams
);
map
.
put
(
"safeCode"
,
safeCode
);
cacheRecord
.
add
(
sb
.
toString
());
list
.
add
(
map
);
}
//记录缓存列表进入数据
cacheDataKeys
(
cacheRecord
.
toArray
(
new
String
[
0
]));
return
list
;
}
else
if
(
val
instanceof
IModule
)
{
val
=
context
.
getSession
().
getBaseObject
(
context
.
getRoot
(),
path
);
...
...
@@ -393,4 +394,46 @@ public class NoUiPresentationUtil {
return
String
.
valueOf
(
ch
);
}
public
static
String
getCacheSetKey
()
{
String
setKey
=
Constants
.
SESSION
+
"."
+
NoUiUtils
.
getUserId
()+
".CACHE_SET"
;
return
setKey
;
}
public
static
String
getCacheSetKey
(
String
userId
)
{
String
setKey
=
Constants
.
SESSION
+
"."
+
userId
+
".CACHE_SET"
;
return
setKey
;
}
public
static
void
cacheDataKeys
(
String
[]
keys
)
{
String
setKey
=
getCacheSetKey
();
try
{
RedisUtil
.
addMembers
(
setKey
,
keys
);
}
catch
(
Exception
e
){
log
.
error
(
e
.
getMessage
());
}
}
public
static
String
[]
getParamKeys
(
IModuleList
moduleList
)
{
String
[]
paramsKey
=
(
String
[])
moduleList
.
getAttribute
(
"KEY_PARAMS"
);
//TODO 考虑后续读取配置文件
if
(
paramsKey
!=
null
)
paramsKey
=
new
String
[]{
"inr"
,
"$objtyp"
};
return
paramsKey
;
}
//检查key是否在set中存在
public
static
boolean
isKeyAllowed
(
String
key
)
{
try
{
return
RedisUtil
.
isMembers
(
getCacheSetKey
(),
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
return
false
;
}
}
}
src/main/java/org/sss/presentation/noui/util/NoUiUtils.java
View file @
a46253ca
...
...
@@ -134,6 +134,11 @@ public class NoUiUtils {
tl
.
remove
();
}
public
static
String
getUserId
()
{
return
tl
.
get
().
getUserId
();
}
public
static
String
getToken
()
{
return
tl
.
get
().
getToken
();
...
...
src/main/java/org/sss/presentation/noui/util/RedisUtil.java
View file @
a46253ca
...
...
@@ -145,4 +145,24 @@ public class RedisUtil {
}
return
new
HashSet
();
}
public
static
boolean
isMembers
(
String
setKey
,
String
key
)
throws
Exception
{
try
{
return
masterNode
.
opsForSet
().
isMember
(
setKey
,
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
checkRedisNodeAvailable
();
}
return
false
;
}
public
static
void
addMembers
(
String
setKey
,
Object
...
args
)
throws
Exception
{
try
{
masterNode
.
opsForSet
().
add
(
setKey
,
args
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
checkRedisNodeAvailable
();
}
}
}
\ No newline at end of file
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