Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
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
s_guodong
gjjs-bd-common
Commits
02b792f5
Commit
02b792f5
authored
Jul 06, 2023
by
gechengyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化登录存储用户信息
parent
fa73fd67
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
188 additions
and
59 deletions
+188
-59
LoginConstants.java
...src/main/java/com/ceb/gjjs/mda/global/LoginConstants.java
+29
-0
Platform.java
...iness/src/main/java/com/ceb/gjjs/mda/global/Platform.java
+12
-4
AuthInterceptor.java
...s/src/main/java/com/ceb/gjjs/mda/web/AuthInterceptor.java
+43
-28
AuthorizationRequestFilter.java
...java/com/ceb/gjjs/mda/web/AuthorizationRequestFilter.java
+51
-13
logback.xml
gjjs-bd-business/src/main/resources/logback.xml
+1
-1
Test.java
gjjs-bd-business/src/test/java/com/brilliance/test/Test.java
+16
-0
Constants.java
...c/main/java/com/brilliance/mda/runtime/mda/Constants.java
+2
-0
IAuthInfo.java
...c/main/java/com/brilliance/mda/runtime/mda/IAuthInfo.java
+7
-1
MdaEnv.java
...in/java/com/brilliance/mda/runtime/mda/driver/MdaEnv.java
+3
-3
BaseVO.java
.../main/java/com/brilliance/mda/runtime/request/BaseVO.java
+2
-2
BDAuthInfo.java
...c/main/java/com/brilliance/mda/support/td/BDAuthInfo.java
+22
-7
No files found.
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/global/LoginConstants.java
0 → 100644
View file @
02b792f5
package
com
.
ceb
.
gjjs
.
mda
.
global
;
/**
* 登录使用的静态参数
*/
public
class
LoginConstants
{
//核心编号
public
static
final
String
cid
=
"cid"
;
//企业操作员编号
public
static
final
String
oid
=
"oid"
;
//网银编号
public
static
final
String
ncid
=
"ncid"
;
public
static
final
String
token
=
"__token"
;
//用户ID
public
static
final
String
usrinr
=
"usrinr"
;
public
static
final
String
ptyinr
=
"ptyinr"
;
public
static
final
String
errorText
=
"errorText"
;
public
static
final
String
CN
=
"CN"
;
public
static
final
String
needSign
=
"needSign"
;
public
static
final
String
__terminalType
=
"__terminalType"
;
}
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/global/Platform.java
View file @
02b792f5
...
...
@@ -8,8 +8,13 @@ import com.brilliance.mda.runtime.mda.driver.MdaDriver;
import
com.brilliance.mda.runtime.mda.driver.MdaEnv
;
import
com.brilliance.mda.runtime.mda.impl.Argument
;
import
com.brilliance.mda.runtime.mda.util.MdaUtils
;
import
com.brilliance.mda.runtime.request.BaseVO
;
import
com.brilliance.mda.support.cache.ICache
;
import
com.brilliance.mda.support.cache.impl.RedisCache
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
java.util.*
;
...
...
@@ -791,10 +796,13 @@ public class Platform {
return
null
;
}
public
static
Object
getLoginData
(
Object
param
)
{
if
(
"usrinr"
.
equals
(
param
))
{
return
"00000970"
;
}
public
static
Object
getLoginData
(
String
param
)
{
if
(
LoginConstants
.
usrinr
.
equals
(
param
))
return
MdaEnv
.
getAuthInfo
().
getUsrInr
();
else
if
(
LoginConstants
.
errorText
.
equals
(
param
))
return
MdaEnv
.
getAuthInfo
().
getErrorText
();
else
if
(
LoginConstants
.
ncid
.
equals
(
param
))
return
MdaEnv
.
getAuthInfo
().
getPtyInr
();
return
null
;
}
...
...
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/web/AuthInterceptor.java
View file @
02b792f5
...
...
@@ -3,14 +3,11 @@ package com.ceb.gjjs.mda.web;
import
com.brilliance.mda.runtime.mda.IAuthInfo
;
import
com.brilliance.mda.runtime.mda.IContext
;
import
com.brilliance.mda.runtime.mda.driver.MdaEnv
;
import
com.brilliance.mda.runtime.mda.util.Systems
;
import
com.brilliance.mda.runtime.request.BaseVO
;
import
com.brilliance.mda.support.cache.ICache
;
import
com.brilliance.mda.support.mybatis.DynamicDataSourceContextHolder
;
import
com.brilliance.mda.support.td.TDAuthInfo
;
import
com.ceb.gjjs.mda.dao.EtgMapper
;
import
com.ceb.gjjs.mda.dao.EtyMapper
;
import
com.ceb.gjjs.mda.dao.UsrMapper
;
import
com.brilliance.mda.support.td.BDAuthInfo
;
import
com.ceb.gjjs.mda.global.LoginConstants
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
...
@@ -19,21 +16,22 @@ import org.springframework.web.servlet.ModelAndView;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
static
com
.
brilliance
.
mda
.
runtime
.
mda
.
Constants
.
tdContextLASTUSERACTIONTIME
;
import
java.util.Map
;
public
class
AuthInterceptor
implements
HandlerInterceptor
{
@Autowired
/*
@Autowired
private UsrMapper usrMapper;
@Autowired
private PtyMapper ptyMapper;
@Autowired
private EtyMapper etyMapper;
@Autowired
private
EtgMapper
etgMapper
;
private EtgMapper etgMapper;
*/
@Qualifier
(
ICache
.
CTX_CACHE
)
@Autowired
...
...
@@ -43,22 +41,16 @@ public class AuthInterceptor implements HandlerInterceptor {
@Autowired
private
ICache
<
String
,
IAuthInfo
>
authInfoICache
;
//简单生成Token Key
private
String
getTokenKey
(
HttpServletRequest
request
)
{
String
logName
=
request
.
getHeader
(
"token"
);
if
(
logName
==
null
||
"undefined"
.
equals
(
logName
))
logName
=
"test"
;
//现在仅仅以userId这个来实现
return
logName
;
}
private
IAuthInfo
getOrCreateAuthInfo
(
String
tokenKey
,
String
userId
)
{
private
IAuthInfo
getOrCreateAuthInfo
(
String
tokenKey
,
Map
<
String
,
Object
>
headMap
)
{
IAuthInfo
authInfo
=
authInfoICache
.
get
(
tokenKey
);
if
(
authInfo
==
null
)
{
synchronized
(
authInfoICache
)
{
authInfo
=
authInfoICache
.
get
(
tokenKey
);
if
(
authInfo
==
null
)
{
TDAuthInfo
tdAuthInfo
=
new
TDAuthInfo
(
userId
);
String
cid
=
headMap
.
get
(
LoginConstants
.
cid
).
toString
();
String
ncid
=
headMap
.
get
(
LoginConstants
.
ncid
).
toString
();
BDAuthInfo
tdAuthInfo
=
new
BDAuthInfo
(
cid
,
ncid
,
""
);
authInfo
=
tdAuthInfo
;
authInfoICache
.
store
(
tokenKey
,
authInfo
);
//构造authInfo,本该在登录里面做
...
...
@@ -96,22 +88,45 @@ public class AuthInterceptor implements HandlerInterceptor {
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
/*
//客户核心编号
String cid = request.getHeader(LoginConstants.cid);
//这里需要通过cid查询usr表,项目组实现相关逻辑 TODO
//逻辑补充在这里.....
Map<String,Object> argsMap = new HashMap<>();
argsMap.put("sql","select * from usr where cid='"+cid+"'");
List<Usr> usrList = usrMapper.dyncRead(argsMap);
if(usrList.size()==0)
{
return false;
//throw new RuntimeException("通过 "+cid+" 查找用户信息表,返回为空");
}
String userId=usrList.get(0).getInr();
//网银编号
String ncid= request.getHeader(LoginConstants.ncid);
//这里需要通过ncid查询pty表,项目组实现相关逻辑 TODO
//.........
String
logName
=
request
.
getHeader
(
"userId"
);
if
(
logName
==
null
||
"undefined"
.
equals
(
logName
))
logName
=
"test"
;
String
token
=
getTokenKey
(
request
);
if (cid == null || "undefined".equals(cid))
cid = "test";
String token =request.getHeader(LoginConstants.token);
Map<String,Object> headMap=new HashMap<>();
headMap.put(LoginConstants.cid,cid);
headMap.put(LoginConstants.ncid,ncid);
headMap.put(LoginConstants.token,token);
//目前采用自动登录模式认证
getOrCreateAuthInfo
(
token
,
logName
);
getOrCreateAuthInfo(token,
headMap
);
//设置一些系统参数
String actionTime = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
Systems
.
setContext
(
tdContextLASTUSERACTIONTIME
,
actionTime
);
Systems.setContext(tdContextLASTUSERACTIONTIME, actionTime);
*/
return
true
;
}
@Override
public
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
ModelAndView
modelAndView
)
throws
Exception
{
}
@Override
...
...
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/web/AuthorizationRequestFilter.java
View file @
02b792f5
...
...
@@ -5,7 +5,11 @@ import com.brilliance.mda.runtime.mda.IContext;
import
com.brilliance.mda.runtime.mda.driver.MdaEnv
;
import
com.brilliance.mda.runtime.mda.util.Systems
;
import
com.brilliance.mda.support.cache.ICache
;
import
com.brilliance.mda.support.td.TDAuthInfo
;
import
com.brilliance.mda.support.td.BDAuthInfo
;
import
com.ceb.gjjs.mda.bo.Usr
;
import
com.ceb.gjjs.mda.dao.PtyMapper
;
import
com.ceb.gjjs.mda.dao.UsrMapper
;
import
com.ceb.gjjs.mda.global.LoginConstants
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
...
@@ -13,7 +17,7 @@ import javax.ws.rs.container.ContainerRequestContext;
import
javax.ws.rs.container.ContainerRequestFilter
;
import
javax.ws.rs.ext.Provider
;
import
java.text.SimpleDateFormat
;
import
java.util.
Date
;
import
java.util.
*
;
import
static
com
.
brilliance
.
mda
.
runtime
.
mda
.
Constants
.
tdContextLASTUSERACTIONTIME
;
...
...
@@ -33,37 +37,71 @@ public class AuthorizationRequestFilter implements ContainerRequestFilter {
@Autowired
private
ICache
<
String
,
IAuthInfo
>
authInfoICache
;
@Autowired
private
UsrMapper
usrMapper
;
@Autowired
private
PtyMapper
ptyMapper
;
/****
*
* @param request
* 这里可以获取网银传递的uid、cid、ocid等各种信息
*/
@Override
public
void
filter
(
ContainerRequestContext
request
)
{
//String logName = request.getHeaderString("userId");
//客户核心编号
String
cid
=
request
.
getHeaderString
(
LoginConstants
.
cid
);
//逻辑修改补充在这里.....
Map
<
String
,
Object
>
argsMap
=
new
HashMap
<>();
argsMap
.
put
(
"sql"
,
"select * from usr where cid='"
+
cid
+
"'"
);
List
<
Usr
>
usrList
=
usrMapper
.
dyncRead
(
argsMap
);
if
(
usrList
.
size
()==
0
)
{
return
;
}
String
userId
=
usrList
.
get
(
0
).
getInr
();
//网银编号
String
ncid
=
request
.
getHeaderString
(
LoginConstants
.
ncid
);
//errorText
String
errorText
=
request
.
getHeaderString
(
LoginConstants
.
errorText
);
Map
<
String
,
Object
>
headMap
=
new
HashMap
<>();
headMap
.
put
(
LoginConstants
.
usrinr
,
userId
);
headMap
.
put
(
LoginConstants
.
ncid
,
ncid
);
headMap
.
put
(
LoginConstants
.
errorText
,
errorText
);
String
logName
=
request
.
getHeaderString
(
"userId"
);
if
(
logName
==
null
||
"undefined"
.
equals
(
logName
))
logName
=
"test"
;
String
token
=
getTokenKey
(
request
);
//目前采用自动登录模式认证
getOrCreateAuthInfo
(
token
,
logName
);
getOrCreateAuthInfo
(
token
,
headMap
);
//设置一些系统参数
String
actionTime
=
new
SimpleDateFormat
(
"yyyyMMddHHmmssSSS"
).
format
(
new
Date
());
Systems
.
setContext
(
tdContextLASTUSERACTIONTIME
,
actionTime
);
}
private
String
getTokenKey
(
ContainerRequestContext
request
)
{
String
logName
=
request
.
getHeaderString
(
"token"
);
if
(
logName
==
null
||
"undefined"
.
equals
(
logName
))
logName
=
"test"
;
//现在仅仅以userId这个来实现
return
logName
;
/*String token = request.getHeaderString(LoginConstants.token
);
if (
token == null || "undefined".equals(token
))
token
= "test";
return token;*/
return
UUID
.
randomUUID
().
toString
()
;
}
private
IAuthInfo
getOrCreateAuthInfo
(
String
tokenKey
,
String
userId
)
{
private
IAuthInfo
getOrCreateAuthInfo
(
String
tokenKey
,
Map
<
String
,
Object
>
headMap
)
{
IAuthInfo
authInfo
=
authInfoICache
.
get
(
tokenKey
);
if
(
authInfo
==
null
)
{
synchronized
(
authInfoICache
)
{
authInfo
=
authInfoICache
.
get
(
tokenKey
);
if
(
authInfo
==
null
)
{
TDAuthInfo
tdAuthInfo
=
new
TDAuthInfo
(
userId
);
String
usrinr
=
headMap
.
get
(
LoginConstants
.
usrinr
).
toString
();
String
ptyinr
=
headMap
.
get
(
LoginConstants
.
ncid
).
toString
();
String
errorText
=
headMap
.
get
(
LoginConstants
.
errorText
)==
null
?
""
:
headMap
.
get
(
LoginConstants
.
errorText
).
toString
();
BDAuthInfo
tdAuthInfo
=
new
BDAuthInfo
(
usrinr
,
ptyinr
,
errorText
);
authInfo
=
tdAuthInfo
;
authInfoICache
.
store
(
tokenKey
,
authInfo
);
//构造authInfo,本该在登录里面做
...
...
gjjs-bd-business/src/main/resources/logback.xml
View file @
02b792f5
...
...
@@ -7,7 +7,7 @@
<property
name=
"charset"
value=
"UTF-8"
></property>
<property
name=
"immediateFlush"
value=
"true"
></property>
<property
name=
"pattern"
value=
"%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-6level) --- [%15.15(%thread)] %cyan(%-
40.40(%logger{4
0})) : %msg%n"
></property>
value=
"%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-6level) --- [%15.15(%thread)] %cyan(%-
60.60(%logger{10
0})) : %msg%n"
></property>
<appender
name=
"STDOUT"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
...
...
gjjs-bd-business/src/test/java/com/brilliance/test/Test.java
0 → 100644
View file @
02b792f5
package
com
.
brilliance
.
test
;
import
java.util.HashSet
;
public
class
Test
{
@org
.
junit
.
jupiter
.
api
.
Test
public
void
test
(){
HashSet
set
=
new
HashSet
();
set
.
add
(
"com"
);
set
.
add
(
"com1"
);
set
.
add
(
"com"
);
System
.
out
.
println
(
set
.
size
());
System
.
out
.
println
(
set
);
}
}
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/Constants.java
View file @
02b792f5
...
...
@@ -107,4 +107,6 @@ public class Constants {
public
static
final
String
ATTR_CODE_VALUES
=
"ATTR_CODE_VALUES"
;
public
static
final
EventType
onChange
=
EventType
.
ON_CHANGE
;;
public
static
final
EventType
onClick
=
EventType
.
ON_CLICK
;
}
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/IAuthInfo.java
View file @
02b792f5
...
...
@@ -2,7 +2,13 @@ package com.brilliance.mda.runtime.mda;
public
interface
IAuthInfo
{
//获取当前用户登录ID
String
getUserId
();
String
getUsrInr
();
//获取当前用户的机构ID
String
getPtyInr
();
//获取errorText
String
getErrorText
();
IStream
getSysStream
();
...
...
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaEnv.java
View file @
02b792f5
...
...
@@ -116,7 +116,7 @@ public class MdaEnv {
public
static
String
getLoginUser
()
{
//结合具体环境,从tl_infos中获取
return
tl_infos
.
get
().
getUs
erId
();
return
tl_infos
.
get
().
getUs
rInr
();
}
public
static
String
getEncoding
()
{
...
...
@@ -133,7 +133,7 @@ public class MdaEnv {
}
public
static
<
T
>
T
getSessionContextValue
(
String
key
)
{
String
uid
=
MdaEnv
.
getAuthInfo
().
getUs
erId
();
String
uid
=
MdaEnv
.
getAuthInfo
().
getUs
rInr
();
if
(!
sessionContext
.
containsKey
(
uid
))
{
return
null
;
}
...
...
@@ -146,7 +146,7 @@ public class MdaEnv {
public
static
void
setSessionContext
(
String
key
,
Object
...
obj
)
{
if
(
key
==
null
)
return
;
String
uid
=
MdaEnv
.
getAuthInfo
().
getUs
erId
();
String
uid
=
MdaEnv
.
getAuthInfo
().
getUs
rInr
();
if
(!
sessionContext
.
containsKey
(
uid
))
{
sessionContext
.
put
(
uid
,
new
ConcurrentHashMap
<
String
,
List
<
Object
>>());
}
...
...
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/request/BaseVO.java
View file @
02b792f5
...
...
@@ -9,9 +9,9 @@ public class BaseVO {
protected
List
<
Map
<
String
,
Object
>>
changes
;
protected
int
pageNum
;
protected
int
pageNum
;
//第几页,从1开始,比如1,2,3,4,5......
protected
int
pageSize
;
protected
int
pageSize
;
//分页每页大小
public
Map
<
String
,
Object
>
getParams
()
{
return
params
;
...
...
gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/td/
T
DAuthInfo.java
→
gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/td/
B
DAuthInfo.java
View file @
02b792f5
...
...
@@ -6,27 +6,42 @@ import com.brilliance.mda.runtime.mda.impl.StreamImpl;
import
java.util.List
;
public
class
TDAuthInfo
implements
IAuthInfo
{
private
String
userId
;
public
class
BDAuthInfo
implements
IAuthInfo
{
private
String
usrInr
;
private
String
ptyInr
;
private
String
errorText
;
private
IStream
sysStream
;
private
IStream
ddsStream
;
private
IStream
keepAuthInfo
;
public
T
DAuthInfo
(){}
public
B
DAuthInfo
(){}
public
TDAuthInfo
(
String
userId
)
{
this
.
userId
=
userId
;
public
BDAuthInfo
(
String
usrInr
,
String
ptyInr
,
String
errorText
)
{
this
.
usrInr
=
usrInr
;
this
.
ptyInr
=
ptyInr
;
this
.
errorText
=
errorText
;
sysStream
=
new
StreamImpl
();
ddsStream
=
new
StreamImpl
();
keepAuthInfo
=
new
StreamImpl
();
}
@Override
public
String
getUs
erId
()
{
return
us
erId
;
public
String
getUs
rInr
()
{
return
us
rInr
;
}
@Override
public
String
getPtyInr
()
{
return
ptyInr
;
}
@Override
public
String
getErrorText
()
{
return
null
;
}
@Override
public
IStream
getSysStream
()
{
return
sysStream
;
}
...
...
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