Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
customer-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
customer-service
Commits
8ef7f262
Commit
8ef7f262
authored
Apr 20, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增接口:帐号密码校验
parent
e33d13e9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
279 additions
and
21 deletions
+279
-21
ErrorMessageComponent.java
...ight/customer/common/component/ErrorMessageComponent.java
+5
-0
PasswordComponent.java
.../freight/customer/common/component/PasswordComponent.java
+58
-0
GoodsOwnerController.java
...er/module/goodsowner/controller/GoodsOwnerController.java
+47
-5
AccountForm.java
.../freight/customer/module/goodsowner/form/AccountForm.java
+5
-5
AccountServiceImpl.java
...er/module/goodsowner/service/impl/AccountServiceImpl.java
+8
-10
ValidatorPassword.java
...module/goodsowner/validator/groups/ValidatorPassword.java
+15
-0
application-dev.yml
src/main/resources/application-dev.yml
+4
-1
PasswordComponentTest.java
...ight/customer/common/component/PasswordComponentTest.java
+53
-0
GoodsOwnerControllerTest.java
...odule/goodsowner/controller/GoodsOwnerControllerTest.java
+84
-0
No files found.
src/main/java/com/esv/freight/customer/common/component/ErrorMessageComponent.java
View file @
8ef7f262
...
...
@@ -48,4 +48,9 @@ public class ErrorMessageComponent {
@Value
(
"${error-message.goodsowner.account.detail.1002}"
)
private
String
goodsOwnerAccountDetail1002
;
@Value
(
"${error-message.goodsowner.account.password-check.1001}"
)
private
String
goodsOwnerAccountPasswordCheck1001
;
@Value
(
"${error-message.goodsowner.account.password-check.1002}"
)
private
String
goodsOwnerAccountPasswordCheck1002
;
}
src/main/java/com/esv/freight/customer/common/component/PasswordComponent.java
0 → 100644
View file @
8ef7f262
package
com
.
esv
.
freight
.
customer
.
common
.
component
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.springframework.stereotype.Component
;
import
java.util.UUID
;
/**
* @description: 帐号密码组件
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.component.PasswordComponent
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/20 10:40
* @version:1.0
*/
@Component
public
class
PasswordComponent
{
/**
* description 生成帐号密码盐
* param []
* return java.lang.String
* author Administrator
* createTime 2020/04/20 10:41
**/
public
String
generateAccountPwdSalt
()
{
return
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
}
/**
* description 对(原始密码+盐)进行加密
* param [initPwd, salt]
* return java.lang.String
* author Administrator
* createTime 2020/04/20 10:44
**/
public
String
generatePwd4Salt
(
String
initPwd
,
String
salt
)
{
return
DigestUtils
.
md5Hex
(
initPwd
+
salt
);
}
/**
* description 校验密码
* param [initPwd, salt, dbPwd]
* return boolean
* author Administrator
* createTime 2020/04/20 10:47
**/
public
boolean
checkPwd4Salt
(
String
initPwd
,
String
salt
,
String
dbPwd
)
{
String
digestPwd
=
this
.
generatePwd4Salt
(
initPwd
,
salt
);
if
(
digestPwd
.
equals
(
dbPwd
))
{
return
true
;
}
else
{
return
false
;
}
}
}
src/main/java/com/esv/freight/customer/module/goodsowner/controller/GoodsOwnerController.java
View file @
8ef7f262
package
com
.
esv
.
freight
.
customer
.
module
.
goodsowner
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.esv.freight.customer.common.component.ErrorMessageComponent
;
import
com.esv.freight.customer.common.component.PasswordComponent
;
import
com.esv.freight.customer.common.exception.EException
;
import
com.esv.freight.customer.common.response.ECode
;
import
com.esv.freight.customer.common.response.EResponse
;
...
...
@@ -15,10 +17,7 @@ import com.esv.freight.customer.module.goodsowner.entity.AuditHistoryEntity;
import
com.esv.freight.customer.module.goodsowner.form.AccountForm
;
import
com.esv.freight.customer.module.goodsowner.form.AccountInfoForm
;
import
com.esv.freight.customer.module.goodsowner.service.AccountService
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorAudit
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorAuditHistory
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorBlock
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorUnblock
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.*
;
import
com.esv.freight.customer.module.goodsowner.vo.AccountInfoVO
;
import
com.esv.freight.customer.module.goodsowner.vo.AuditHistoryVO
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -51,9 +50,15 @@ public class GoodsOwnerController {
private
AccountService
accountService
;
private
ErrorMessageComponent
errorMessageComponent
;
private
PasswordComponent
passwordComponent
;
@Autowired
public
GoodsOwnerController
(
AccountService
accountService
)
{
public
GoodsOwnerController
(
AccountService
accountService
,
ErrorMessageComponent
errorMessageComponent
,
PasswordComponent
passwordComponent
)
{
this
.
accountService
=
accountService
;
this
.
errorMessageComponent
=
errorMessageComponent
;
this
.
passwordComponent
=
passwordComponent
;
}
@PostMapping
(
"/list"
)
...
...
@@ -192,6 +197,43 @@ public class GoodsOwnerController {
/****************************** 参数校验 ******************************/
AccountInfoDto
accountInfoDto
=
accountService
.
getAccountInfo
(
form
);
// 查询结果处理
if
(
null
!=
form
.
getId
())
{
if
(
null
==
accountInfoDto
)
{
throw
new
EException
(
1001
,
errorMessageComponent
.
getGoodsOwnerAccountDetail1001
());
}
}
else
if
(
null
!=
form
.
getAccount
())
{
if
(
null
==
accountInfoDto
)
{
throw
new
EException
(
1002
,
errorMessageComponent
.
getGoodsOwnerAccountDetail1002
());
}
}
else
{
}
AccountInfoVO
accountInfoVO
=
new
AccountInfoVO
();
BeanUtils
.
copyProperties
(
accountInfoDto
,
accountInfoVO
);
return
EResponse
.
ok
(
accountInfoVO
);
}
/**
* description 帐号密码校验
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/20 11:22
**/
@PostMapping
(
"/password/check"
)
public
EResponse
checkAccountPwd
(
@RequestBody
@Validated
(
ValidatorPassword
.
class
)
AccountForm
form
)
throws
EException
{
AccountInfoDto
accountInfoDto
=
accountService
.
getAccountInfo
(
form
);
// 校验帐号是否存在
if
(
null
==
accountInfoDto
)
{
throw
new
EException
(
1001
,
errorMessageComponent
.
getGoodsOwnerAccountPasswordCheck1001
());
}
// 校验密码是否正确
if
(!
passwordComponent
.
checkPwd4Salt
(
form
.
getPassword
(),
accountInfoDto
.
getSalt
(),
accountInfoDto
.
getPassword
()))
{
throw
new
EException
(
1002
,
errorMessageComponent
.
getGoodsOwnerAccountPasswordCheck1001
());
}
AccountInfoVO
accountInfoVO
=
new
AccountInfoVO
();
BeanUtils
.
copyProperties
(
accountInfoDto
,
accountInfoVO
);
return
EResponse
.
ok
(
accountInfoVO
);
...
...
src/main/java/com/esv/freight/customer/module/goodsowner/form/AccountForm.java
View file @
8ef7f262
package
com
.
esv
.
freight
.
customer
.
module
.
goodsowner
.
form
;
import
com.esv.freight.customer.common.validator.groups.ValidatorDetail
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorAudit
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorAuditHistory
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorBlock
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorUnblock
;
import
com.esv.freight.customer.module.goodsowner.validator.groups.*
;
import
lombok.Data
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
...
...
@@ -33,9 +30,12 @@ public class AccountForm {
@Length
(
max
=
100
,
message
=
"参数remark长度不合法"
,
groups
=
{
ValidatorAudit
.
class
})
private
String
remark
;
@Length
(
max
=
11
,
message
=
"参数account长度不合法"
,
groups
=
{
ValidatorDetail
.
class
})
@Length
(
max
=
11
,
message
=
"参数account长度不合法"
,
groups
=
{
ValidatorDetail
.
class
,
ValidatorPassword
.
class
})
private
String
account
;
@Length
(
max
=
32
,
message
=
"参数password长度不合法"
,
groups
=
{
ValidatorPassword
.
class
})
private
String
password
;
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
JSON_STYLE
);
...
...
src/main/java/com/esv/freight/customer/module/goodsowner/service/impl/AccountServiceImpl.java
View file @
8ef7f262
...
...
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.esv.freight.customer.common.component.ErrorMessageComponent
;
import
com.esv.freight.customer.common.component.PasswordComponent
;
import
com.esv.freight.customer.common.exception.EException
;
import
com.esv.freight.customer.common.util.FeignUtils
;
import
com.esv.freight.customer.common.util.ReqUtils
;
...
...
@@ -38,6 +39,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
private
FeignBaseService
feignBaseService
;
private
PasswordComponent
passwordComponent
;
private
ErrorMessageComponent
errorMessageComponent
;
private
InfoService
infoService
;
...
...
@@ -45,8 +48,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
private
AuditHistoryService
auditHistoryService
;
@Autowired
public
AccountServiceImpl
(
FeignBaseService
feignBaseService
,
ErrorMessageComponent
errorMessageComponent
,
InfoService
infoService
,
AuditHistoryService
auditHistoryService
)
{
public
AccountServiceImpl
(
FeignBaseService
feignBaseService
,
PasswordComponent
passwordComponent
,
ErrorMessageComponent
errorMessageComponent
,
InfoService
infoService
,
AuditHistoryService
auditHistoryService
)
{
this
.
feignBaseService
=
feignBaseService
;
this
.
passwordComponent
=
passwordComponent
;
this
.
errorMessageComponent
=
errorMessageComponent
;
this
.
infoService
=
infoService
;
this
.
auditHistoryService
=
auditHistoryService
;
...
...
@@ -96,10 +101,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
// 3.新增帐号
BeanUtils
.
copyProperties
(
form
,
accountEntity
);
accountEntity
.
setId
(
null
);
String
salt
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
password
=
DigestUtils
.
md5Hex
(
form
.
getPassword
()
+
salt
);
String
salt
=
passwordComponent
.
generateAccountPwdSalt
();
accountEntity
.
setSalt
(
salt
);
accountEntity
.
setPassword
(
password
);
accountEntity
.
setPassword
(
password
Component
.
generatePwd4Salt
(
form
.
getPassword
(),
salt
)
);
accountEntity
.
setSourceType
(
GoodsOwnerConstants
.
OWNER_SOURCE_TYPE_PLATFORM
);
accountEntity
.
setAuditStatus
(
GoodsOwnerConstants
.
OWNER_AUDIT_STATUS_SUCCESS
);
this
.
baseMapper
.
insert
(
accountEntity
);
...
...
@@ -258,14 +262,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
AccountInfoDto
dto
=
null
;
if
(
null
!=
form
.
getId
())
{
dto
=
this
.
baseMapper
.
getAccountInfoById
(
form
.
getId
());
if
(
null
==
dto
)
{
throw
new
EException
(
1001
,
errorMessageComponent
.
getGoodsOwnerAccountDetail1001
());
}
}
else
if
(
null
!=
form
.
getAccount
())
{
dto
=
this
.
baseMapper
.
getAccountInfoByAccount
(
form
.
getAccount
());
if
(
null
==
dto
)
{
throw
new
EException
(
1002
,
errorMessageComponent
.
getGoodsOwnerAccountDetail1002
());
}
}
else
{
}
...
...
src/main/java/com/esv/freight/customer/module/goodsowner/validator/groups/ValidatorPassword.java
0 → 100644
View file @
8ef7f262
package
com
.
esv
.
freight
.
customer
.
module
.
goodsowner
.
validator
.
groups
;
import
javax.validation.groups.Default
;
/**
* @description: 参数校验分组:帐号密码
* @project: SpringCloudTemplate
* @name: com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorPassword
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public
interface
ValidatorPassword
extends
Default
{
}
src/main/resources/application-dev.yml
View file @
8ef7f262
...
...
@@ -65,4 +65,7 @@ error-message:
1001
:
无效的帐号ID
detail
:
1001
:
无效的帐号ID
1002
:
无效的手机号
\ No newline at end of file
1002
:
无效的手机号
password-check
:
1001
:
无效的手机号
1002
:
密码错误
\ No newline at end of file
src/test/java/com/esv/freight/customer/common/component/PasswordComponentTest.java
0 → 100644
View file @
8ef7f262
package
com
.
esv
.
freight
.
customer
.
common
.
component
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.component.PasswordComponentTest
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/20 11:23
* @version:1.0
*/
@SpringBootTest
@Slf4j
public
class
PasswordComponentTest
{
@Autowired
PasswordComponent
passwordComponent
;
@Before
public
void
before
()
{
log
.
info
(
"=================================== Test Start ==================================="
);
}
@After
public
void
after
()
{
log
.
info
(
"=================================== Test End ==================================="
);
}
@Test
public
void
checkPwd4Salt_success_test
()
{
String
salt
=
passwordComponent
.
generateAccountPwdSalt
();
String
initPwd
=
DigestUtils
.
md5Hex
(
"123456"
);
String
digestPwd
=
passwordComponent
.
generatePwd4Salt
(
initPwd
,
salt
);
log
.
info
(
"salt={}"
,
salt
);
log
.
info
(
"digestPwd={}"
,
digestPwd
);
Assert
.
assertTrue
(
passwordComponent
.
checkPwd4Salt
(
initPwd
,
salt
,
digestPwd
));
}
@Test
public
void
digest_test
()
{
log
.
info
(
DigestUtils
.
md5Hex
(
"123456"
));
}
}
src/test/java/com/esv/freight/customer/module/goodsowner/controller/GoodsOwnerControllerTest.java
View file @
8ef7f262
...
...
@@ -532,4 +532,88 @@ public class GoodsOwnerControllerTest extends BaseTestController {
JSONObject
result
=
JSONObject
.
parseObject
(
responseStr
);
Assert
.
assertEquals
(
1002
,
result
.
getIntValue
(
"code"
));
}
/**
* 帐号密码校验
**/
@Test
public
void
h1_checkAccountPwd_success_test
()
throws
Exception
{
String
url
=
"/goodsowner/account/password/check"
;
// 构造数据
AccountForm
form
=
new
AccountForm
();
form
.
setAccount
(
"18524431581"
);
form
.
setPassword
(
"e10adc3949ba59abbe56e057f20f883e"
);
JSONObject
reqJson
=
JSONObject
.
parseObject
(
form
.
toString
());
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
headers
(
this
.
getDefaultHttpHeaders
())
.
content
(
reqJson
.
toJSONString
()))
.
andDo
(
MockMvcResultHandlers
.
print
())
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andReturn
();
String
responseStr
=
mvcResult
.
getResponse
().
getContentAsString
();
log
.
info
(
responseStr
);
JSONObject
result
=
JSONObject
.
parseObject
(
responseStr
);
Assert
.
assertEquals
(
ECode
.
SUCCESS
.
code
(),
result
.
getIntValue
(
"code"
));
}
/**
* 帐号密码校验:帐号不存在
**/
@Test
public
void
h2_checkAccountPwd_wrong_account_failure_test
()
throws
Exception
{
String
url
=
"/goodsowner/account/password/check"
;
// 构造数据
AccountForm
form
=
new
AccountForm
();
form
.
setAccount
(
"12012345678"
);
form
.
setPassword
(
"e10adc3949ba59abbe56e057f20f883e"
);
JSONObject
reqJson
=
JSONObject
.
parseObject
(
form
.
toString
());
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
headers
(
this
.
getDefaultHttpHeaders
())
.
content
(
reqJson
.
toJSONString
()))
.
andDo
(
MockMvcResultHandlers
.
print
())
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andReturn
();
String
responseStr
=
mvcResult
.
getResponse
().
getContentAsString
();
log
.
info
(
responseStr
);
JSONObject
result
=
JSONObject
.
parseObject
(
responseStr
);
Assert
.
assertEquals
(
1001
,
result
.
getIntValue
(
"code"
));
}
/**
* 帐号密码校验:密码错误
**/
@Test
public
void
h3_checkAccountPwd_wrong_password_failure_test
()
throws
Exception
{
String
url
=
"/goodsowner/account/password/check"
;
// 构造数据
AccountForm
form
=
new
AccountForm
();
form
.
setAccount
(
"18524431581"
);
form
.
setPassword
(
"e10adc3949ba59abbe56e057f20f8abc"
);
JSONObject
reqJson
=
JSONObject
.
parseObject
(
form
.
toString
());
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
headers
(
this
.
getDefaultHttpHeaders
())
.
content
(
reqJson
.
toJSONString
()))
.
andDo
(
MockMvcResultHandlers
.
print
())
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andReturn
();
String
responseStr
=
mvcResult
.
getResponse
().
getContentAsString
();
log
.
info
(
responseStr
);
JSONObject
result
=
JSONObject
.
parseObject
(
responseStr
);
Assert
.
assertEquals
(
1002
,
result
.
getIntValue
(
"code"
));
}
}
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