Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
京
京能客户端
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王亚宁
京能客户端
Commits
d9745b92
Commit
d9745b92
authored
1 year ago
by
realize1020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
远程登录二次校验,修复漏洞
远程登录二次校验,修复漏洞
parent
34152210
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
259 additions
and
2 deletions
+259
-2
OBE-BUSINESS/src/com/gx/obe/business/UserLogin.java
OBE-BUSINESS/src/com/gx/obe/business/UserLogin.java
+32
-2
OBE-BUSINESS/src/com/gx/obe/web/platform/service/PlatformUserService.java
.../com/gx/obe/web/platform/service/PlatformUserService.java
+26
-0
OBE-BUSINESS/src/com/gx/obe/web/utils/DESUtils.java
OBE-BUSINESS/src/com/gx/obe/web/utils/DESUtils.java
+177
-0
OBE-COMPONENTS-CORE/src/com/gx/obe/enttiytdo/LoginUserDTO.java
...OMPONENTS-CORE/src/com/gx/obe/enttiytdo/LoginUserDTO.java
+24
-0
No files found.
OBE-BUSINESS/src/com/gx/obe/business/UserLogin.java
View file @
d9745b92
package
com
.
gx
.
obe
.
business
;
package
com
.
gx
.
obe
.
business
;
import
java.util.Map
;
import
com.gx.obe.components.core.Constants
;
import
com.gx.obe.components.core.Constants
;
import
com.gx.obe.components.core.enumeration.CommonEnum
;
import
com.gx.obe.components.core.enumeration.CommonEnum
;
import
com.gx.obe.components.core.enumeration.UserEnum
;
import
com.gx.obe.components.core.enumeration.UserEnum
;
...
@@ -7,6 +9,7 @@ import com.gx.obe.components.core.vo.AuthUserVo;
...
@@ -7,6 +9,7 @@ import com.gx.obe.components.core.vo.AuthUserVo;
import
com.gx.obe.enttiytdo.BooleanResultDO
;
import
com.gx.obe.enttiytdo.BooleanResultDO
;
import
com.gx.obe.enttiytdo.LoginUserDTO
;
import
com.gx.obe.enttiytdo.LoginUserDTO
;
import
com.gx.obe.enttiytdo.PlatformResult
;
import
com.gx.obe.enttiytdo.PlatformResult
;
import
com.gx.obe.http.json.JsonUtil
;
import
com.gx.obe.http.util.ObjectUtil
;
import
com.gx.obe.http.util.ObjectUtil
;
import
com.gx.obe.util.utils.MD5Utils
;
import
com.gx.obe.util.utils.MD5Utils
;
import
com.gx.obe.util.utils.UuidUtils
;
import
com.gx.obe.util.utils.UuidUtils
;
...
@@ -14,6 +17,7 @@ import com.gx.obe.web.entity.Result.ResultEntity;
...
@@ -14,6 +17,7 @@ import com.gx.obe.web.entity.Result.ResultEntity;
import
com.gx.obe.web.entity.auth.AuthUser
;
import
com.gx.obe.web.entity.auth.AuthUser
;
import
com.gx.obe.web.platform.service.PlatformUserService
;
import
com.gx.obe.web.platform.service.PlatformUserService
;
import
com.gx.obe.web.service.UserService
;
import
com.gx.obe.web.service.UserService
;
import
com.gx.obe.web.utils.DESUtils
;
/**
/**
...
@@ -26,6 +30,8 @@ public class UserLogin {
...
@@ -26,6 +30,8 @@ public class UserLogin {
private
PlatformUserService
platformUserService
=
new
PlatformUserService
();
private
PlatformUserService
platformUserService
=
new
PlatformUserService
();
private
boolean
isRemote
;
public
BooleanResultDO
loginUser
(
String
userName
,
String
password
)
{
public
BooleanResultDO
loginUser
(
String
userName
,
String
password
)
{
BooleanResultDO
result
=
null
;
BooleanResultDO
result
=
null
;
//验证本地用户信息(登录成功状态 用户信息)
//验证本地用户信息(登录成功状态 用户信息)
...
@@ -37,9 +43,11 @@ public class UserLogin {
...
@@ -37,9 +43,11 @@ public class UserLogin {
//登录成功
//登录成功
if
(
ResultEntity
.
SUCCESS
==
resultUser
.
getCode
())
{
if
(
ResultEntity
.
SUCCESS
==
resultUser
.
getCode
())
{
if
(
UserEnum
.
USER_SOURCE_REMOTE
.
equals
(
user
.
getSource
()))
{
if
(
UserEnum
.
USER_SOURCE_REMOTE
.
equals
(
user
.
getSource
()))
{
isRemote
=
true
;
//平台验证
//平台验证
result
=
platformVerification
(
userName
,
password
);
result
=
platformVerification
(
userName
,
password
);
if
(
result
.
isStatus
())
{
if
(
result
.
isStatus
())
{
//if(result.)
Constants
.
USER
=
user
;
Constants
.
USER
=
user
;
Constants
.
TOKEN
=
resultUser
.
getData
().
getAtuokthen
();
Constants
.
TOKEN
=
resultUser
.
getData
().
getAtuokthen
();
}
}
...
@@ -156,11 +164,33 @@ public class UserLogin {
...
@@ -156,11 +164,33 @@ public class UserLogin {
*/
*/
private
BooleanResultDO
platformVerification
(
String
userName
,
String
password
){
private
BooleanResultDO
platformVerification
(
String
userName
,
String
password
){
PlatformResult
<
LoginUserDTO
>
platformResult
=
platformUserService
.
userNameLogin
(
userName
,
password
);
PlatformResult
<
LoginUserDTO
>
platformResult
=
platformUserService
.
userNameLogin
(
userName
,
password
);
if
(
null
==
platformResult
)
{
if
(
null
==
platformResult
)
{
return
new
BooleanResultDO
(
false
,
"登录异常"
);
return
new
BooleanResultDO
(
false
,
"登录异常"
);
}
}
if
(
Constants
.
PLATFOR_STATUS_OK
.
equals
((
String
)
platformResult
.
getHeader
().
getRet
()))
{
if
(
Constants
.
PLATFOR_STATUS_OK
.
equals
((
String
)
platformResult
.
getHeader
().
getRet
()))
{
return
new
BooleanResultDO
(
true
,
""
);
LoginUserDTO
loginUserDTO
=
platformResult
.
getData
();
if
(
isRemote
){
String
checkUserLogin
=
loginUserDTO
.
getCheckUserLogin
();
String
result
=
platformUserService
.
verify
(
checkUserLogin
);
if
(
null
==
result
)
{
return
new
BooleanResultDO
(
false
,
"登录异常"
);
}
try
{
String
decrypt
=
DESUtils
.
decrypt
(
result
,
"utf-8"
);
Map
<
String
,
String
>
resultMap
=
JsonUtil
.
strToMap
(
decrypt
);
if
(
resultMap
.
get
(
"ret"
).
equals
(
Constants
.
PLATFOR_STATUS_OK
))
{
return
new
BooleanResultDO
(
true
,
""
);
}
return
new
BooleanResultDO
(
false
,(
String
)
platformResult
.
getHeader
().
getMsg
());
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
return
new
BooleanResultDO
(
false
,
"登录异常"
);
}
// Map<String, Object> resultMap = JSONHelperTwo.toHashMap(decrypt);
// resultMap.get("ret");
}
return
new
BooleanResultDO
(
false
,
"登录异常"
);
}
else
{
}
else
{
return
new
BooleanResultDO
(
false
,(
String
)
platformResult
.
getHeader
().
getMsg
());
return
new
BooleanResultDO
(
false
,(
String
)
platformResult
.
getHeader
().
getMsg
());
}
}
...
...
This diff is collapsed.
Click to expand it.
OBE-BUSINESS/src/com/gx/obe/web/platform/service/PlatformUserService.java
View file @
d9745b92
...
@@ -5,6 +5,9 @@ import java.util.Map;
...
@@ -5,6 +5,9 @@ import java.util.Map;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
com.gx.obe.WebserviceConstants
;
import
com.gx.obe.WebserviceConstants
;
import
com.gx.obe.components.core.Constants
;
import
com.gx.obe.components.core.Constants
;
import
com.gx.obe.config.utils.PropertiesUtils
;
import
com.gx.obe.config.utils.PropertiesUtils
;
...
@@ -48,4 +51,27 @@ public class PlatformUserService {
...
@@ -48,4 +51,27 @@ public class PlatformUserService {
return
null
;
return
null
;
}
}
}
}
/**
* 二次验证
* @param checkUserLogin
*/
public
String
verify
(
String
checkUserLogin
)
{
// TODO Auto-generated method stub
String
method
=
PropertiesUtils
.
getWebserviceProperty
(
"userHS.do?checkEncryptionInfo"
,
"userHS.do?checkEncryptionInfo"
);
String
stPlatformUrl
=
Constants
.
getPlatformUrl
(
method
);
Map
<
String
,
Object
>
param
=
new
HashMap
<
String
,
Object
>();
param
.
put
(
"checkUserLogin"
,
checkUserLogin
);
HttpResponse
httpResponse
=
NetworkRequest
.
postHttpResponse
(
stPlatformUrl
,
param
);
if
(
HttpStatus
.
HTTP_OK
==
httpResponse
.
getStatus
())
{
String
bodyJson
=
httpResponse
.
body
();
JsonParser
jsonParser
=
new
JsonParser
();
JsonObject
bodyObject
=
jsonParser
.
parse
(
bodyJson
).
getAsJsonObject
();
JsonObject
dataObject
=
bodyObject
.
getAsJsonObject
(
"data"
);
String
data
=
dataObject
.
get
(
"data"
).
getAsString
();
return
data
;
}
return
null
;
}
}
}
This diff is collapsed.
Click to expand it.
OBE-BUSINESS/src/com/gx/obe/web/utils/DESUtils.java
0 → 100644
View file @
d9745b92
package
com
.
gx
.
obe
.
web
.
utils
;
import
javax.crypto.Cipher
;
import
javax.crypto.SecretKey
;
import
javax.crypto.SecretKeyFactory
;
import
javax.crypto.spec.DESKeySpec
;
import
java.security.SecureRandom
;
/**
* DES加密工具
*/
public
class
DESUtils
{
private
final
static
String
DES
=
"DES"
;
public
final
static
String
key
=
"HLJ$@&!^%$ZJK"
;
/**
* 加密
*
* @param src 数据源
* @param key 密钥,长度必须是8的倍数
* @return 返回加密后的数据
* @throws Exception
*/
public
static
byte
[]
encrypt
(
byte
[]
src
,
byte
[]
key
)
throws
RuntimeException
{
// DES算法要求有一个可信任的随机数源
try
{
SecureRandom
sr
=
new
SecureRandom
();
// 从原始密匙数据创建DESKeySpec对象
DESKeySpec
dks
=
new
DESKeySpec
(
key
);
// 创建一个密匙工厂,然后用它把DESKeySpec转换成
// 一个SecretKey对象
SecretKeyFactory
keyFactory
=
SecretKeyFactory
.
getInstance
(
DES
);
SecretKey
securekey
=
keyFactory
.
generateSecret
(
dks
);
// Cipher对象实际完成加密操作
Cipher
cipher
=
Cipher
.
getInstance
(
DES
);
// 用密匙初始化Cipher对象
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
securekey
,
sr
);
// 现在,获取数据并加密
// 正式执行加密操作
return
cipher
.
doFinal
(
src
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
/**
* 解密
*
* @param src
* 数据源
* @param key
* 密钥,长度必须是8的倍数
* @return 返回解密后的原始数据
* @throws Exception
*/
public
static
byte
[]
decrypt
(
byte
[]
src
,
byte
[]
key
)
throws
RuntimeException
{
try
{
// DES算法要求有一个可信任的随机数源
SecureRandom
sr
=
new
SecureRandom
();
// 从原始密匙数据创建一个DESKeySpec对象
DESKeySpec
dks
=
new
DESKeySpec
(
key
);
// 创建一个密匙工厂,然后用它把DESKeySpec对象转换成
// 一个SecretKey对象
SecretKeyFactory
keyFactory
=
SecretKeyFactory
.
getInstance
(
DES
);
SecretKey
securekey
=
keyFactory
.
generateSecret
(
dks
);
// Cipher对象实际完成解密操作
Cipher
cipher
=
Cipher
.
getInstance
(
DES
);
// 用密匙初始化Cipher对象
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
securekey
,
sr
);
// 现在,获取数据并解密
// 正式执行解密操作
return
cipher
.
doFinal
(
src
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
/**
* 数据解密
*
* @param data
* @return
* @throws Exception
*/
public
final
static
String
decrypt
(
String
data
,
String
enc
)
throws
Exception
{
return
new
String
(
decrypt
(
hex2byte
(
data
.
getBytes
(
enc
)),
key
.
getBytes
(
enc
)),
enc
);
}
/**
* 数据解密
*
* @param data
* @return
* @throws Exception
*/
public
final
static
String
decrypt
(
String
data
)
throws
Exception
{
return
new
String
(
decrypt
(
hex2byte
(
data
.
getBytes
()),
key
.
getBytes
()));
}
/**
* 数据加密
*
* @param data
* @return
* @throws Exception
*/
public
final
static
String
encrypt
(
String
data
)
{
if
(
data
!=
null
)
try
{
return
byte2hex
(
encrypt
(
data
.
getBytes
(),
key
.
getBytes
()));
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
return
null
;
}
/**
* 数据加密
*
* @param data
* @param enc
* 密钥
* @return
* @throws Exception
*/
public
final
static
String
encrypt
(
String
data
,
String
enc
)
{
if
(
data
!=
null
)
try
{
return
byte2hex
(
encrypt
(
data
.
getBytes
(
enc
),
key
.
getBytes
(
enc
)));
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
return
null
;
}
/**
* 二行制转字符串
*
* @param b
* @return
*/
private
static
String
byte2hex
(
byte
[]
b
)
{
StringBuilder
hs
=
new
StringBuilder
();
String
stmp
;
for
(
int
n
=
0
;
b
!=
null
&&
n
<
b
.
length
;
n
++)
{
stmp
=
Integer
.
toHexString
(
b
[
n
]
&
0XFF
);
if
(
stmp
.
length
()
==
1
)
hs
.
append
(
'0'
);
hs
.
append
(
stmp
);
}
return
hs
.
toString
().
toUpperCase
();
}
private
static
byte
[]
hex2byte
(
byte
[]
b
)
{
if
((
b
.
length
%
2
)
!=
0
)
throw
new
IllegalArgumentException
();
byte
[]
b2
=
new
byte
[
b
.
length
/
2
];
for
(
int
n
=
0
;
n
<
b
.
length
;
n
+=
2
)
{
String
item
=
new
String
(
b
,
n
,
2
);
b2
[
n
/
2
]
=
(
byte
)
Integer
.
parseInt
(
item
,
16
);
}
return
b2
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
content
=
""
;
System
.
out
.
println
(
"加密前:"
+
content
);
// 加密
String
encryptResult
=
encrypt
(
content
);
System
.
out
.
println
(
"加密后:"
+
encryptResult
);
// 解密
String
decryptResult
=
decrypt
(
encryptResult
);
System
.
out
.
println
(
"解密后:"
+
decryptResult
);
}
}
This diff is collapsed.
Click to expand it.
OBE-COMPONENTS-CORE/src/com/gx/obe/enttiytdo/LoginUserDTO.java
View file @
d9745b92
...
@@ -4,6 +4,10 @@ public class LoginUserDTO {
...
@@ -4,6 +4,10 @@ public class LoginUserDTO {
String
orgName
;
String
orgName
;
String
userName
;
String
userName
;
String
accessToken
;
String
checkUserLogin
;
String
data
;
public
String
getOrgName
()
{
public
String
getOrgName
()
{
return
orgName
;
return
orgName
;
}
}
...
@@ -16,5 +20,25 @@ public class LoginUserDTO {
...
@@ -16,5 +20,25 @@ public class LoginUserDTO {
public
void
setUserName
(
String
userName
)
{
public
void
setUserName
(
String
userName
)
{
this
.
userName
=
userName
;
this
.
userName
=
userName
;
}
}
public
String
getAccessToken
()
{
return
accessToken
;
}
public
void
setAccessToken
(
String
accessToken
)
{
this
.
accessToken
=
accessToken
;
}
public
String
getCheckUserLogin
()
{
return
checkUserLogin
;
}
public
void
setCheckUserLogin
(
String
checkUserLogin
)
{
this
.
checkUserLogin
=
checkUserLogin
;
}
public
String
getData
()
{
return
data
;
}
public
void
setData
(
String
data
)
{
this
.
data
=
data
;
}
}
}
This diff is collapsed.
Click to expand it.
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