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
b4e8040c
Commit
b4e8040c
authored
Jul 28, 2022
by
WeiCong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
在交易初始化前增加预处理机制
parent
a5f78102
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
194 additions
and
72 deletions
+194
-72
PreHandle.java
src/main/java/org/sss/module/pojo/PreHandle.java
+97
-0
NoUiContext.java
...n/java/org/sss/presentation/noui/context/NoUiContext.java
+11
-2
NoUiContextManager.java
...org/sss/presentation/noui/context/NoUiContextManager.java
+60
-60
AbstractCommonController.java
...resentation/noui/controller/AbstractCommonController.java
+4
-0
TokenInterceptor.java
.../java/org/sss/presentation/noui/jwt/TokenInterceptor.java
+3
-10
prehandle.properties
src/main/resources/prehandle.properties
+19
-0
No files found.
src/main/java/org/sss/module/pojo/PreHandle.java
0 → 100644
View file @
b4e8040c
package
org
.
sss
.
module
.
pojo
;
import
com.brilliance.eibs.etrade.module.Sysmod
;
import
log.Log
;
import
log.LogFactory
;
import
org.apache.commons.beanutils.ConstructorUtils
;
import
org.apache.commons.beanutils.MethodUtils
;
import
org.sss.common.model.Argument
;
import
org.sss.common.model.IModule
;
import
org.sss.common.model.IModuleRoot
;
import
org.sss.presentation.noui.context.NoUiContext
;
import
org.sss.presentation.noui.util.PropertyUtil
;
import
org.sss.presentation.noui.util.StringUtil
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 针对光大e结算(或许还能针对所有执行具体交易前的预处理场景)
*/
public
class
PreHandle
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
PreHandle
.
class
);
private
static
HashMap
<
String
,
String
[]>
config
=
new
HashMap
<
String
,
String
[]>();
static
{
try
{
Map
<
String
,
String
>
tmp
=
new
HashMap
<
String
,
String
>((
Map
)
PropertyUtil
.
load
(
"prehandle.properties"
));
for
(
Map
.
Entry
<
String
,
String
>
entry
:
tmp
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
val
=
entry
.
getValue
();
if
(
config
.
containsKey
(
key
))
{
log
.
warn
(
"忽略重复的安全信息:"
+
key
);
continue
;
}
if
(
StringUtil
.
isEmpty
(
val
))
{
log
.
warn
(
"忽略值为空的安全信息:"
+
key
);
continue
;
}
config
.
put
(
key
,
val
.
split
(
";"
));
}
}
catch
(
Exception
e
)
{
//降级处理
config
=
new
HashMap
<
String
,
String
[]>();
log
.
warn
(
"加载安全配置文件失败:"
+
e
.
getMessage
());
}
}
public
static
boolean
needPreHandle
(
String
mappingUrl
)
{
return
config
.
containsKey
(
mappingUrl
);
}
public
static
void
preHandle
(
String
trnName
,
Map
<
String
,
?>
paramsMap
,
NoUiContext
context
)
throws
NoSuchMethodException
,
IllegalAccessException
,
InvocationTargetException
{
String
[]
handles
=
config
.
get
(
trnName
);
for
(
String
handle
:
handles
)
{
if
(
StringUtil
.
isEmpty
(
handle
))
{
continue
;
}
String
[]
items
=
handle
.
split
(
","
);
if
(
items
.
length
==
0
||
StringUtil
.
isEmpty
(
items
[
0
]))
{
log
.
warn
(
trnName
+
"关联的预处理不符合配置规则:至少需要配置预处理方法"
);
continue
;
}
String
method
=
items
[
0
];
String
[]
args
=
new
String
[
items
.
length
-
1
];
if
(
args
.
length
>
0
)
{
System
.
arraycopy
(
items
,
1
,
args
,
0
,
args
.
length
);
}
MethodUtils
.
invokeStaticMethod
(
PreHandle
.
class
,
method
,
new
Object
[]{
context
,
paramsMap
,
args
});
}
}
public
static
void
sureBtn
(
NoUiContext
ctx
,
Map
<
String
,
?>
paramsMap
,
Object
...
otherParams
)
throws
Exception
{
if
(
otherParams
.
length
!=
2
)
{
log
.
warn
(
"执行sureBtn预处理方法,需要两个参数:'Module名称'和'待跳转的交易名称'"
);
return
;
}
if
(
paramsMap
.
get
(
"__inr"
)==
null
){
log
.
warn
(
"执行sureBtn预处理方法,params中需要__inr关键字对应的模型inr"
);
return
;
}
String
grpNam
=
(
String
)
otherParams
[
0
];
String
toTrs
=
(
String
)
otherParams
[
1
];
String
packageName
=
((
AbstractPOJOImpl
)
ctx
.
getSupport
()).
getPackageName
(
toTrs
);
String
className
=
packageName
+
"."
+
toTrs
.
substring
(
0
,
1
).
toUpperCase
()
+
toTrs
.
substring
(
1
);
IModuleRoot
root
=
(
IModuleRoot
)
ConstructorUtils
.
invokeConstructor
(
Class
.
forName
(
className
),
new
Object
[]{
toTrs
,
new
Sysmod
()}
,
new
Class
[]{
String
.
class
,
IModule
.
class
});
IModule
grp
=
(
IModule
)
ctx
.
getSession
().
getBaseObject
(
root
,
grpNam
+
"\\rec"
);
ctx
.
getSupport
().
get
(
grp
,
new
Argument
[]{
new
Argument
(
"inr"
,
paramsMap
.
get
(
"__inr"
))});
ctx
.
getError
();
ctx
.
getSession
().
storeData
(
"com.brilliance."
+
toTrs
+
".ref"
,
grp
);
}
}
src/main/java/org/sss/presentation/noui/context/NoUiContext.java
View file @
b4e8040c
...
...
@@ -3,12 +3,15 @@ package org.sss.presentation.noui.context;
import
log.Log
;
import
log.LogFactory
;
import
org.sss.common.impl.AbstractContext
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.jwt.LoginInfo
;
import
org.sss.presentation.noui.util.NoUiUtils
;
public
class
NoUiContext
extends
AbstractContext
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
NoUiContext
.
class
);
private
LoginInfo
loginInfo
;
NoUiRequest
noUiRequest
;
@Override
public
void
logout
()
{
...
...
@@ -28,8 +31,6 @@ public class NoUiContext extends AbstractContext {
return
null
;
}
private
LoginInfo
loginInfo
;
public
LoginInfo
getLoginInfo
()
{
return
this
.
loginInfo
;
...
...
@@ -38,4 +39,12 @@ public class NoUiContext extends AbstractContext {
{
this
.
loginInfo
=
loginInfo
;
}
public
NoUiRequest
getNoUiRequest
()
{
return
noUiRequest
;
}
public
void
setNoUiRequest
(
NoUiRequest
noUiRequest
)
{
this
.
noUiRequest
=
noUiRequest
;
}
}
src/main/java/org/sss/presentation/noui/context/NoUiContextManager.java
View file @
b4e8040c
package
org
.
sss
.
presentation
.
noui
.
context
;
import
cn.com.brilliance.eibs.auth.EmptyLoginContext
;
import
log.Log
;
import
log.LogFactory
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.reflect.ConstructorUtils
;
import
org.sss.common.model.ILoginContext
;
import
org.sss.common.model.IModuleSession
;
import
org.sss.presentation.noui.api.exception.NoUiException
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.util.NoUiUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
public
class
NoUiContextManager
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
NoUiContextManager
.
class
);
public
static
String
dbType
=
"hibernate"
;
public
static
String
loginContextName
=
"cn.com.brilliance.eibs.auth.DatabaseLoginContext"
;
public
static
String
openSourcePrefix
=
"openservice"
;
public
static
String
everybody
=
"#Everybody#"
;
public
static
List
<
String
>
openTransactions
=
new
ArrayList
<
String
>();
public
static
NoUiContext
createNoUiContext
(
NoUiRequest
noUiRequest
)
{
NoUiContext
noUiContext
=
new
NoUiContext
();
ILoginContext
loginContext
=
null
;
if
(
noUiRequest
.
isOpenSource
())
{
loginContext
=
new
EmptyLoginContext
(
everybody
);
}
else
if
(
StringUtils
.
isEmpty
(
noUiRequest
.
getToken
()))
{
try
{
loginContext
=
(
ILoginContext
)
Class
.
forName
(
loginContextName
).
newInstance
();
}
catch
(
InstantiationException
|
IllegalAccessException
|
ClassNotFoundException
e
)
{
throw
new
NoUiException
(
"loingConextName class is not found"
,
loginContextName
);
}
}
else
loginContext
=
new
EmptyLoginContext
(
noUiRequest
.
getUserId
());
loginContext
.
setContext
(
noUiContext
);
noUiContext
.
setAuth
(
loginContext
);
noUiContext
.
setSessionId
(
UUID
.
randomUUID
().
toString
());
IModuleSession
session
=
null
;
try
{
Class
<?>
clazz
=
Class
.
forName
(
"org.sss.module."
+
dbType
+
".ModuleSessionImpl"
);
session
=
(
IModuleSession
)
ConstructorUtils
.
invokeConstructor
(
clazz
,
new
Object
[]
{
noUiContext
,
NoUiUtils
.
connectKeeped
});
}
catch
(
Exception
e
)
{
log
.
error
(
"Constructs NoUiContext error"
,
e
);
throw
new
NoUiException
(
"Constructs NoUiContext error"
,
e
);
}
noUiContext
.
setGui
(
new
NoUiPresentation
(
noUiContext
,
noUiRequest
));
noUiContext
.
setSession
(
session
);
log
.
debug
(
"Build context finished"
);
return
noUiContext
;
}
}
package
org
.
sss
.
presentation
.
noui
.
context
;
import
cn.com.brilliance.eibs.auth.EmptyLoginContext
;
import
log.Log
;
import
log.LogFactory
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.reflect.ConstructorUtils
;
import
org.sss.common.model.ILoginContext
;
import
org.sss.common.model.IModuleSession
;
import
org.sss.presentation.noui.api.exception.NoUiException
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.util.NoUiUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
public
class
NoUiContextManager
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
NoUiContextManager
.
class
);
public
static
String
dbType
=
"hibernate"
;
public
static
String
loginContextName
=
"cn.com.brilliance.eibs.auth.DatabaseLoginContext"
;
public
static
String
openSourcePrefix
=
"openservice"
;
public
static
String
everybody
=
"#Everybody#"
;
public
static
List
<
String
>
openTransactions
=
new
ArrayList
<
String
>();
public
static
NoUiContext
createNoUiContext
(
NoUiRequest
noUiRequest
)
{
NoUiContext
noUiContext
=
new
NoUiContext
();
ILoginContext
loginContext
=
null
;
if
(
noUiRequest
.
isOpenSource
())
{
loginContext
=
new
EmptyLoginContext
(
everybody
);
}
else
if
(
StringUtils
.
isEmpty
(
noUiRequest
.
getToken
()))
{
try
{
loginContext
=
(
ILoginContext
)
Class
.
forName
(
loginContextName
).
newInstance
();
}
catch
(
InstantiationException
|
IllegalAccessException
|
ClassNotFoundException
e
)
{
throw
new
NoUiException
(
"loingConextName class is not found"
,
loginContextName
);
}
}
else
loginContext
=
new
EmptyLoginContext
(
noUiRequest
.
getUserId
());
loginContext
.
setContext
(
noUiContext
);
noUiContext
.
setAuth
(
loginContext
);
noUiContext
.
setSessionId
(
UUID
.
randomUUID
().
toString
());
IModuleSession
session
=
null
;
try
{
Class
<?>
clazz
=
Class
.
forName
(
"org.sss.module."
+
dbType
+
".ModuleSessionImpl"
);
session
=
(
IModuleSession
)
ConstructorUtils
.
invokeConstructor
(
clazz
,
new
Object
[]
{
noUiContext
,
NoUiUtils
.
connectKeeped
});
}
catch
(
Exception
e
)
{
log
.
error
(
"Constructs NoUiContext error"
,
e
);
throw
new
NoUiException
(
"Constructs NoUiContext error"
,
e
);
}
noUiContext
.
setGui
(
new
NoUiPresentation
(
noUiContext
,
noUiRequest
));
noUiContext
.
setSession
(
session
);
noUiContext
.
setNoUiRequest
(
noUiRequest
);
log
.
debug
(
"Build context finished"
);
return
noUiContext
;
}
}
src/main/java/org/sss/presentation/noui/controller/AbstractCommonController.java
View file @
b4e8040c
...
...
@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.multipart.MultipartFile
;
import
org.sss.common.impl.RuleUtils
;
import
org.sss.common.model.*
;
import
org.sss.module.pojo.PreHandle
;
import
org.sss.presentation.noui.api.exception.ExitTransactionException
;
import
org.sss.presentation.noui.api.exception.NoUiException
;
import
org.sss.presentation.noui.api.model.Alias
;
...
...
@@ -69,6 +70,9 @@ public abstract class AbstractCommonController {
context
=
NoUiContextManager
.
createNoUiContext
(
noUiRequest
);
// 交易参数赋值
if
(
PreHandle
.
needPreHandle
(
trnName
)){
PreHandle
.
preHandle
(
trnName
,
paramsMap
,
context
);
}
for
(
String
key
:
paramsMap
.
keySet
())
{
context
.
getSession
().
storeData
(
key
,
paramsMap
.
get
(
key
));
}
...
...
src/main/java/org/sss/presentation/noui/jwt/TokenInterceptor.java
View file @
b4e8040c
...
...
@@ -32,12 +32,11 @@ public class TokenInterceptor implements HandlerInterceptor {
NoUiRequest
noUiRequest
=
new
NoUiRequest
(
request
,
""
,
null
);
String
token
=
noUiRequest
.
getToken
();
String
userId
=
noUiRequest
.
getUserId
();
String
terminalType
=
noUiRequest
.
getTerminalType
();
// APP WEB
// token不存在
if
(
StringUtil
.
isEmpty
(
token
))
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_ISNULL
,
"登录token不能为空"
,
null
,
noUiVersion
.
getVersion
());
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
fals
e
;
//
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_ISNULL, "登录token不能为空", null, noUiVersion.getVersion());
//
responseMessage(response, response.getWriter(), rt);
return
tru
e
;
}
// userId不存在
...
...
@@ -47,12 +46,6 @@ public class TokenInterceptor implements HandlerInterceptor {
return
false
;
}
//服务调用
if
(
token
.
startsWith
(
Constants
.
APP_FLAG
))
{
return
true
;
}
JwtLogin
login
=
JWT
.
unsign
(
token
,
JwtLogin
.
class
);
if
(
login
==
null
||
(!
userId
.
equals
((
login
.
getUserId
()))))
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_CHECKERROR
,
"用户token或ID验证不通过"
,
null
,
noUiVersion
.
getVersion
());
...
...
src/main/resources/prehandle.properties
0 → 100644
View file @
b4e8040c
cptfre
=
sureBtn,cpdgrp,cptfre
bctacp
=
sureBtn,bcdgrp,bctacp
bctfre
=
sureBtn,bcdgrp,bctfre
bdtfrc
=
sureBtn,didgrp,bdtfrc
bdtfrd
=
sureBtn,bddgrp,bdtfrd
bdtdfr
=
sureBtn,didgrp,bdtdfr
bdtdfd
=
sureBtn,bddgrp,bdtdfd
bdtsnd
=
sureBtn,bddgrp,bdtsnd
bdtdsn
=
sureBtn,didgrp,bdtdsn
botfre
=
sureBtn,didgrp,bodgrp
bptapn
=
sureBtn,bodgrp,bptapn
bptapl
=
sureBtn,bedgrp,bptapl
bptopl
=
sureBtn,bedgrp,bptopl
bptopc
=
sureBtn,bodgrp,bptopc
bptrpn
=
sureBtn,bpdgrp,bptrpn
brtfrc
=
sureBtn,lidgrp,brtfrc
brtfrd
=
sureBtn,brdgrp,brtfrd
brtsnd
=
sureBtn,brdgrp,brtsnd
\ 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