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
3f54223f
Commit
3f54223f
authored
Mar 01, 2021
by
WeiCong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整日志记录
parent
75517185
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
23 deletions
+59
-23
DatabaseLoginContextForELCS.java
...com/brilliance/eibs/auth/DatabaseLoginContextForELCS.java
+59
-23
No files found.
src/main/java/cn/com/brilliance/eibs/auth/DatabaseLoginContextForELCS.java
View file @
3f54223f
...
...
@@ -4,11 +4,17 @@ import log.Log;
import
log.LogFactory
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.dbutils.DbUtils
;
import
org.hibernate.SQLQuery
;
import
org.hibernate.Session
;
import
org.hibernate.Transaction
;
import
org.hibernate.engine.spi.SessionImplementor
;
import
org.sss.common.impl.AbstractLoginContext
;
import
org.sss.common.impl.MenuItemImpl
;
import
org.sss.common.model.IContext.DataType
;
import
org.sss.common.model.IFilter
;
import
org.sss.common.model.IMenuItem
;
import
org.sss.module.hibernate.HibernateUtils
;
import
org.sss.module.pojo.DatabaseUtils
;
import
org.sss.presentation.noui.api.response.ErrorCode
;
import
org.sss.presentation.noui.util.NoUiUtils
;
import
org.sss.presentation.noui.util.StringUtil
;
...
...
@@ -22,6 +28,7 @@ import java.sql.*;
import
java.time.Duration
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.Date
;
/**
* LoginModule实现示例
...
...
@@ -56,7 +63,12 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
final
static
int
INDEX_IMG
=
7
;
final
static
int
INDEX_STL
=
8
;
final
static
int
INDEX_CLS
=
9
;
final
static
String
PWDERROR
=
"ESFEERROR1"
;
final
static
String
VCODEERROR
=
"ESFEERROR2"
;
final
static
String
REDISERROR
=
"ESFEERROR3"
;
final
static
String
INITERROR
=
"ESFEERROR4"
;
private
static
final
String
loginCheck
=
"loginCheck.properties"
;
private
static
final
String
privateKey
=
"MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALTHSCdzrBYyWReFrasVB+ehvfOg/34nTPPNSJsTlr0vqwvVohhqhnlBtIGE1g1//stMcAso8CevpCnN5/cOiwubzFhm1dRsyQmmkiMzH68sNx8+h87X/XeKpWIVSswc2Z3nMMV8zTDK8KhpPJwVRIQ5CqPdiYpQoDhBB5POiWPdAgMBAAECgYAxYCzI+cMK3P2QeyaQD9J05axoGpUt87YE8RDfql4Fljt1pAf9+zp3bAbNSWbdkRQamuoPYkMV09dWw7KTvBklwQe91llTF3eHXKXmI5M+NJtlfmk2aeJCwmb8LtFyIMb3ocgvni5es/jEd/UTzZvzZpbkR+aD5aiXEC/wFCNJUQJBANfQuCDO2d7MIfv36DKbGJ25oqX/e2B/GWDhNGb3F4BqN+3MkFw21MAP3OlW/nu0XgyRLVzw8pm6E6WlBR3GPGMCQQDWcHVWr7fIeQ9sLAKwhe+D4k/kPElaptxoqzMIWNcweG5fc2eMvJ5BHh081B0h4+KiLE6lgvitZU2c8aCm/TK/AkAuJ7U5TwPJYl7iRGKkcAcTtF/UoI8CVCxZS9CpNK8SB6VudhFpp1BYwwu7258RVcHHbkUFW4KG3gTVqDUv6PWBAkEAsuD6sMZB68Q4vkZ0M+Z2JzDI7h3wHuOkZtew6VyanT9I6uysy3SoGq/ROeXDK3samaeWL3DymkowFSRmnAYIpwJABliTTManT9rkQx+sahGwGKInAClxl3Po5XB8ST/75xkSobYAVaV8kgrxE4u4DJxbomBUWeT7oOOhX2vODMhuZg=="
;
public
static
int
defaultSessionTimeout
=
3600
;
public
static
String
defaultHomePageName
=
"/layout.zul"
;
public
static
String
defaultHomeTransaction
=
"office"
;
...
...
@@ -70,8 +82,6 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
//连续多次输入密码重置
private
static
int
maxfltcnt
=
5
;
private
static
final
String
privateKey
=
"MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALTHSCdzrBYyWReFrasVB+ehvfOg/34nTPPNSJsTlr0vqwvVohhqhnlBtIGE1g1//stMcAso8CevpCnN5/cOiwubzFhm1dRsyQmmkiMzH68sNx8+h87X/XeKpWIVSswc2Z3nMMV8zTDK8KhpPJwVRIQ5CqPdiYpQoDhBB5POiWPdAgMBAAECgYAxYCzI+cMK3P2QeyaQD9J05axoGpUt87YE8RDfql4Fljt1pAf9+zp3bAbNSWbdkRQamuoPYkMV09dWw7KTvBklwQe91llTF3eHXKXmI5M+NJtlfmk2aeJCwmb8LtFyIMb3ocgvni5es/jEd/UTzZvzZpbkR+aD5aiXEC/wFCNJUQJBANfQuCDO2d7MIfv36DKbGJ25oqX/e2B/GWDhNGb3F4BqN+3MkFw21MAP3OlW/nu0XgyRLVzw8pm6E6WlBR3GPGMCQQDWcHVWr7fIeQ9sLAKwhe+D4k/kPElaptxoqzMIWNcweG5fc2eMvJ5BHh081B0h4+KiLE6lgvitZU2c8aCm/TK/AkAuJ7U5TwPJYl7iRGKkcAcTtF/UoI8CVCxZS9CpNK8SB6VudhFpp1BYwwu7258RVcHHbkUFW4KG3gTVqDUv6PWBAkEAsuD6sMZB68Q4vkZ0M+Z2JzDI7h3wHuOkZtew6VyanT9I6uysy3SoGq/ROeXDK3samaeWL3DymkowFSRmnAYIpwJABliTTManT9rkQx+sahGwGKInAClxl3Po5XB8ST/75xkSobYAVaV8kgrxE4u4DJxbomBUWeT7oOOhX2vODMhuZg=="
;
static
{
init
();
}
...
...
@@ -93,33 +103,54 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
props
.
load
(
DatabaseLoginContextForELCS
.
class
.
getClassLoader
().
getResourceAsStream
(
loginCheck
));
pwdAmeInterval
=
Duration
.
ofDays
(
Integer
.
parseInt
(
props
.
getProperty
(
"pwdAmeInterval"
)));
maxfltcnt
=
Integer
.
parseInt
(
props
.
getProperty
(
"maxfltcnt"
));
}
catch
(
Exception
e
)
{
//load失败启用默认值
log
.
error
(
"load loginCheck.properties failed"
,
e
);
}
}
catch
(
Throwable
e
)
{
log
.
warn
(
"初始化异常"
,
e
);
recordException
(
INITERROR
,
"初始化异常:"
+
e
.
getMessage
(),
"ERROR"
);
}
}
public
static
void
recordException
(
String
srvcod
,
String
errormsg
,
String
lev
)
{
Session
session
=
HibernateUtils
.
openSession
(
null
);
long
count
=
DatabaseUtils
.
executeCounter
(((
SessionImplementor
)
session
).
connection
(),
"dealog"
);
String
inr
=
String
.
format
(
"%08d"
,
count
);
Transaction
transaction
=
session
.
beginTransaction
();
SQLQuery
sqlQuery
=
session
.
createSQLQuery
(
"insert into dealog(INR,CREDATTIM,SRVCOD,SRVNAM,INIFRM,RTNMSG,LOGLEV) values(?,?,?,?,?,?,?)"
);
sqlQuery
.
setString
((
Integer
)
0
,
inr
);
sqlQuery
.
setTimestamp
(
1
,
new
Date
());
sqlQuery
.
setString
(
2
,
srvcod
);
sqlQuery
.
setString
(
3
,
srvcod
);
sqlQuery
.
setString
(
4
,
"LOGIN"
);
sqlQuery
.
setString
(
5
,
errormsg
);
sqlQuery
.
setString
(
6
,
lev
);
sqlQuery
.
executeUpdate
();
transaction
.
commit
();
session
.
close
();
log
.
debug
(
"完成登陆相关异常日志记录"
);
}
/**
* 用户原文密码解密,先传统base64解密,然后对解密后的字符串的首位字符串进行偏移【头4 尾7】
*
* @param verifycode 验证码
* @param pwd 待解签串
* @return 解签后的字符串
*/
public
static
String
pwdDecode
(
String
verifycode
,
String
pwd
)
{
public
static
String
pwdDecode
(
String
verifycode
,
String
pwd
)
{
if
(
StringUtil
.
isEmpty
(
pwd
))
{
return
""
;
}
try
{
// pwd = AESUtil.decryptAES(pwd,verifycode);
pwd
=
decrypt
(
pwd
);
}
catch
(
Exception
e
)
{
log
.
warn
(
"密码解密失败,使用原密码"
);
}
catch
(
Throwable
e
)
{
log
.
warn
(
"密码解密异常:"
,
e
);
recordException
(
PWDERROR
,
"密码解密异常:"
+
e
.
getMessage
(),
"FATAL"
);
}
return
pwd
;
}
public
static
String
decrypt
(
String
pwd
)
throws
Exception
{
pwd
=
pwd
.
replaceAll
(
"%2B"
,
"+"
);
public
static
String
decrypt
(
String
pwd
)
throws
Exception
{
pwd
=
pwd
.
replaceAll
(
"%2B"
,
"+"
);
//64位解码加密后的字符串
byte
[]
inputByte
=
org
.
apache
.
commons
.
codec
.
binary
.
Base64
.
decodeBase64
(
pwd
.
getBytes
(
"UTF-8"
));
//base64编码的私钥
...
...
@@ -128,17 +159,17 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
//RSA解密
Cipher
cipher
=
Cipher
.
getInstance
(
"RSA"
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
priKey
);
String
outStr
=
new
String
(
cipher
.
doFinal
(
inputByte
),
"UTF-8"
);
String
outStr
=
new
String
(
cipher
.
doFinal
(
inputByte
),
"UTF-8"
);
return
outStr
;
}
//偏移 头4 尾7
private
static
String
convert
(
String
str
)
{
if
(
str
.
length
()==
1
)
{
if
(
str
.
length
()
==
1
)
{
return
change
(
str
.
charAt
(
0
),
4
);
}
else
if
(
str
.
length
()==
2
)
{
return
change
(
str
.
charAt
(
0
),
4
)
+
change
(
str
.
charAt
(
1
),
7
);
}
else
{
}
else
if
(
str
.
length
()
==
2
)
{
return
change
(
str
.
charAt
(
0
),
4
)
+
change
(
str
.
charAt
(
1
),
7
);
}
else
{
String
btw_str
=
str
.
substring
(
1
,
str
.
length
()
-
1
);
String
head
=
change
(
str
.
charAt
(
0
),
4
);
String
tail
=
change
(
str
.
charAt
(
str
.
length
()
-
1
),
7
);
...
...
@@ -234,11 +265,13 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
return
sessionTimeout
;
}
public
String
checkPassword
(
String
userName
,
String
verifycode
,
String
dbPassword
,
String
password
)
{
password
=
pwdDecode
(
verifycode
,
password
);
public
String
checkPassword
(
String
userName
,
String
verifycode
,
String
dbPassword
,
String
password
)
{
password
=
pwdDecode
(
verifycode
,
password
);
IFilter
passwordFilter
=
NoUiUtils
.
passwordFilter
;
if
(
NoUiUtils
.
passwordFilter
==
null
)
{
log
.
info
(
"请在eibs.xml为NoUiUtils配置passwordFilter项"
);
log
.
warn
(
"未在eibs.xml为NoUiUtils配置passwordFilter项"
);
recordException
(
PWDERROR
,
"密码校验异常:未在eibs.xml为NoUiUtils配置passwordFilter项"
,
"FATAL"
);
return
null
;
}
if
(
dbPassword
!=
null
)
{
dbPassword
=
dbPassword
.
trim
();
...
...
@@ -261,7 +294,7 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
String
sendcode
=
getParameter
(
parameterMap
,
"j_sendcode"
);
String
verifycode
=
getParameter
(
parameterMap
,
"j_verifycode"
);
String
dncode
=
getParameter
(
parameterMap
,
"j_dncode"
);
if
(
userName
==
null
||
password
==
null
||
dncode
==
null
)
{
if
(
userName
==
null
||
password
==
null
||
dncode
==
null
)
{
parameterMap
.
put
(
ERROR
,
ErrorCode
.
LOGIN_PARAMETER_CHECK
);
return
setLogon
(
false
,
userName
,
ERROR_USERNAME_PASSWORD
,
"用户名或密码为空."
,
null
,
null
);
}
...
...
@@ -269,6 +302,9 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
ResultSet
rs
=
null
;
PreparedStatement
stmt
=
null
;
try
{
if
(
verifycode
==
null
){
recordException
(
VCODEERROR
,
"验证码刷新异常"
,
"ERROR"
);
}
if
(
sendcode
==
null
||
verifycode
==
null
||
!
sendcode
.
equalsIgnoreCase
(
verifycode
))
{
log
.
info
(
"验证码验证失败,待校验:"
+
sendcode
+
",原始:"
+
verifycode
);
parameterMap
.
put
(
ERROR
,
ErrorCode
.
LOGIN_VERIFYCODE_ERROR
);
...
...
@@ -300,7 +336,7 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
ukey
=
rs
.
getString
(
8
);
DbUtils
.
closeQuietly
(
stmt
);
DbUtils
.
closeQuietly
(
rs
);
String
errorStr
=
checkPassword
(
userName
,
sendcode
,
dbPassword
,
password
);
String
errorStr
=
checkPassword
(
userName
,
sendcode
,
dbPassword
,
password
);
if
(
STATUS_LOCKED
.
equals
(
userState
))
{
parameterMap
.
put
(
ERROR
,
ErrorCode
.
LOGIN_LOCK_USR
);
return
setLogon
(
false
,
userName
,
ERROR_USER_LOCKED
,
"用户已被锁定."
,
stmt
,
rs
);
...
...
@@ -310,7 +346,7 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
}
else
if
(!
STATUS_NORMAL
.
equals
(
userState
))
{
//非0:正常;1:注销;2:锁定,不可登录,
parameterMap
.
put
(
ERROR
,
ErrorCode
.
LOGIN_STATE_ABNORMAL_ERROR
);
return
setLogon
(
false
,
userName
,
ErrorCode
.
LOGIN_STATE_ABNORMAL_ERROR
.
getCode
(),
ErrorCode
.
LOGIN_STATE_ABNORMAL_ERROR
.
getMessage
(),
stmt
,
rs
);
}
else
if
(!
Objects
.
equals
(
ukey
,
dncode
))
{
//dn码错误
}
else
if
(!
Objects
.
equals
(
ukey
,
dncode
))
{
//dn码错误
parameterMap
.
put
(
ERROR
,
ErrorCode
.
LOGIN_DN_ERROR
);
return
setLogon
(
false
,
userName
,
ErrorCode
.
LOGIN_DN_ERROR
.
getCode
(),
ErrorCode
.
LOGIN_DN_ERROR
.
getMessage
(),
stmt
,
rs
);
}
else
if
(
Objects
.
nonNull
(
errorStr
))
{
...
...
@@ -357,7 +393,7 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
homePageName
=
defaultHomePageName
;
homeTransaction
=
defaultHomeTransaction
;
sessionTimeout
=
defaultSessionTimeout
;
}
catch
(
Exception
e
)
{
}
catch
(
Throwable
e
)
{
log
.
error
(
"系统登录内部错误"
,
e
);
parameterMap
.
put
(
ERROR
,
ErrorCode
.
SYSTEM_ERROR
);
return
setLogon
(
false
,
userName
,
ERROR_SYSTEM_FAULT
,
"系统内部错误."
,
stmt
,
rs
);
...
...
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