Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dm_project
Project
Project
Details
Activity
Releases
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
姚本章
dm_project
Commits
cf7632b3
Commit
cf7632b3
authored
Dec 31, 2020
by
zhangc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复认证中已知问题
parent
29646613
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
141 additions
and
85 deletions
+141
-85
WebAppConfigurer.java
...eway/src/main/java/com/jz/dm/config/WebAppConfigurer.java
+1
-0
AuthController.java
...ay/src/main/java/com/jz/dm/controller/AuthController.java
+1
-1
OrganizationManageController.java
...va/com/jz/dm/controller/OrganizationManageController.java
+1
-2
ApiAuthMapper.java
...gateway/src/main/java/com/jz/dm/mapper/ApiAuthMapper.java
+1
-1
ApiAuth.java
...ateway/src/main/java/com/jz/dm/models/domian/ApiAuth.java
+5
-5
AuthInfoDto.java
...teway/src/main/java/com/jz/dm/models/dto/AuthInfoDto.java
+8
-6
AuthDmpUserApiReq.java
...ain/java/com/jz/dm/models/req/auth/AuthDmpUserApiReq.java
+10
-2
AuthMallUserApiReq.java
...in/java/com/jz/dm/models/req/auth/AuthMallUserApiReq.java
+10
-2
SaltResetReq.java
...src/main/java/com/jz/dm/models/req/auth/SaltResetReq.java
+2
-2
MakeDataBankApiReq.java
...in/java/com/jz/dm/models/req/make/MakeDataBankApiReq.java
+8
-4
AuthUserResponse.java
...src/main/java/com/jz/dm/models/resp/AuthUserResponse.java
+2
-2
AuthServiceImpl.java
...src/main/java/com/jz/dm/service/impl/AuthServiceImpl.java
+36
-21
ProducerServiceImpl.java
...main/java/com/jz/dm/service/impl/ProducerServiceImpl.java
+12
-9
ApiAuthMapper.xml
jz-dm-apigateway/src/main/resources/mapper/ApiAuthMapper.xml
+43
-27
TestAuth.java
...ateway/src/test/java/com/jz/dm/gateway/auth/TestAuth.java
+1
-1
No files found.
jz-dm-apigateway/src/main/java/com/jz/dm/config/WebAppConfigurer.java
View file @
cf7632b3
...
...
@@ -23,6 +23,7 @@ public class WebAppConfigurer extends WebMvcConfigurerAdapter {
// 可添加多个,这里选择拦截所有请求地址,进入后判断是否有加注解即可
registry
.
addInterceptor
(
getAccessLimitInterceptor
())
.
addPathPatterns
(
"/api/organization/**"
)
.
excludePathPatterns
(
"api/producer/**"
)
.
excludePathPatterns
(
"/**/*.html"
,
//html静态资源
"/**/*.js"
,
//js静态资源
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/controller/AuthController.java
View file @
cf7632b3
...
...
@@ -48,7 +48,7 @@ public class AuthController {
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation
(
"
商城
用户API认证"
)
@ApiOperation
(
"
DMP
用户API认证"
)
@PostMapping
(
value
=
"dmp-auth-api"
)
public
Mono
<
Result
>
authDmpUserApi
(
@RequestBody
@Valid
AuthDmpUserApiReq
req
)
{
return
Mono
.
fromSupplier
(()
->
authService
.
addDmpUserApiAuth
(
req
));
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/controller/OrganizationManageController.java
View file @
cf7632b3
...
...
@@ -7,7 +7,6 @@ import com.jz.dm.models.req.organizationManage.OrganizationManageListQueryReq;
import
com.jz.dm.models.req.organizationManage.OrganizationManageUpdateReq
;
import
com.jz.dm.service.OrganizationManageService
;
import
com.jz.dm.web.annotation.AccessLimit
;
import
com.jz.dm.web.annotation.ApiLogAspect
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -53,7 +52,7 @@ public class OrganizationManageController {
@ApiOperation
(
"组织详情查询"
)
@PostMapping
(
value
=
"/getOrgDetail"
)
@AccessLimit
(
limit
=
1000
,
sec
=
1
)
@ApiLogAspect
//
@ApiLogAspect
public
Mono
<
Result
>
getOrganizationDetail
(
@RequestBody
@Valid
OrganizationManageDetailQueryReq
req
)
{
return
Mono
.
fromSupplier
(()
->
organizationManageService
.
getOrganizationDetail
(
req
));
}
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/mapper/ApiAuthMapper.java
View file @
cf7632b3
...
...
@@ -19,7 +19,7 @@ public interface ApiAuthMapper extends BaseMapper<ApiAuth> {
* @param req
* @return
*/
AuthInfoDto
selectAuthDetail
(
AuthDetailInfoReq
req
);
AuthInfoDto
selectAuthDetail
(
@Param
(
"req"
)
AuthDetailInfoReq
req
);
/**
* 分页查询认证列表
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/domian/ApiAuth.java
View file @
cf7632b3
...
...
@@ -56,11 +56,11 @@ public class ApiAuth extends BaseObject implements Serializable {
@TableField
(
"salt"
)
private
String
salt
;
/**
* 组织id
*/
@TableField
(
"org_id"
)
private
Long
orgId
;
/
//
**
//
* 组织id
//
*/
//
@TableField("org_id")
//
private Long orgId;
/**
* 授权方式:1.按次调用 2.按月调用 3.按季调用 4.按年调用
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/dto/AuthInfoDto.java
View file @
cf7632b3
...
...
@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* @author ZC
...
...
@@ -25,12 +24,15 @@ public class AuthInfoDto implements Serializable {
@ApiModelProperty
(
value
=
"授权组织id"
)
private
Long
apiOrgId
;
@ApiModelProperty
(
value
=
"api应用id"
)
private
Long
apiInterfaceId
;
/*
@ApiModelProperty(value = "api应用id")
private Long apiInterfaceId;
*/
@ApiModelProperty
(
value
=
"授权组织名称"
)
private
String
orgName
;
@ApiModelProperty
(
value
=
"授权组织名称"
)
private
String
authCode
;
@ApiModelProperty
(
value
=
"apiKey"
)
private
String
apiKey
;
...
...
@@ -38,10 +40,10 @@ public class AuthInfoDto implements Serializable {
private
String
authMode
;
@ApiModelProperty
(
value
=
"开始时间"
)
private
Date
validStartTime
;
private
String
validStartTime
;
@ApiModelProperty
(
value
=
"结束时间"
)
private
Date
validEndTime
;
private
String
validEndTime
;
@ApiModelProperty
(
value
=
"状态(1-正常 2-作废"
)
private
String
status
;
...
...
@@ -50,7 +52,7 @@ public class AuthInfoDto implements Serializable {
private
String
remark
;
@ApiModelProperty
(
value
=
"创建时间"
)
private
Date
createTim
e
;
private
String
createDat
e
;
@ApiModelProperty
(
value
=
"创建用户"
)
private
String
createUser
;
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/req/auth/AuthDmpUserApiReq.java
View file @
cf7632b3
package
com
.
jz
.
dm
.
models
.
req
.
auth
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.jz.dm.common.enums.auth.AuthModeEnum
;
import
com.jz.dm.common.enums.auth.AuthTypeEnum
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* @author ZC
...
...
@@ -43,9 +46,14 @@ public class AuthDmpUserApiReq implements Serializable {
private
AuthModeEnum
authMode
;
@ApiModelProperty
(
value
=
"开始时间"
,
required
=
false
)
private
String
validStartTime
;
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
validStartTime
;
@ApiModelProperty
(
value
=
"结束时间"
,
required
=
false
)
private
String
validEndTime
;
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
validEndTime
;
@ApiModelProperty
(
value
=
"备注"
,
required
=
false
)
private
String
remark
;
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/req/auth/AuthMallUserApiReq.java
View file @
cf7632b3
package
com
.
jz
.
dm
.
models
.
req
.
auth
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.jz.dm.common.enums.auth.AuthModeEnum
;
import
com.jz.dm.common.enums.auth.AuthTypeEnum
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* @author ZC
...
...
@@ -46,9 +49,14 @@ public class AuthMallUserApiReq implements Serializable {
private
AuthModeEnum
authMode
;
@ApiModelProperty
(
value
=
"开始时间"
,
required
=
false
)
private
String
validStartTime
;
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
validStartTime
;
@ApiModelProperty
(
value
=
"结束时间"
,
required
=
false
)
private
String
validEndTime
;
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
validEndTime
;
@ApiModelProperty
(
value
=
"备注"
,
required
=
false
)
private
String
remark
;
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/req/auth/SaltResetReq.java
View file @
cf7632b3
...
...
@@ -23,8 +23,8 @@ public class SaltResetReq implements Serializable {
@NotNull
(
message
=
"id不能为空"
)
private
Long
id
;
@ApiModelProperty
(
value
=
"盐值"
,
required
=
true
)
/*
@ApiModelProperty(value = "盐值",required = true)
@NotNull(message = "盐值不能为空")
private
String
salt
;
private String salt;
*/
}
jz-dm-apigateway/src/main/java/com/jz/dm/models/req/make/MakeDataBankApiReq.java
View file @
cf7632b3
...
...
@@ -24,9 +24,9 @@ public class MakeDataBankApiReq implements Serializable {
@NotNull
(
message
=
"api类型不能为空"
)
public
String
apiType
;
@ApiModelProperty
(
value
=
"api
Id 等价于apiKey
"
,
required
=
true
)
@NotNull
(
message
=
"api
Id
不能为空"
)
public
String
api
Id
;
@ApiModelProperty
(
value
=
"api
Key 等价于apiId
"
,
required
=
true
)
@NotNull
(
message
=
"api
Key
不能为空"
)
public
String
api
Key
;
@ApiModelProperty
(
value
=
"接口描述"
,
required
=
false
)
public
String
apiDesc
;
...
...
@@ -36,7 +36,7 @@ public class MakeDataBankApiReq implements Serializable {
@ApiModelProperty
(
value
=
"传输方式(1为HTTPS,2为HTTP)"
,
required
=
true
)
@NotNull
(
message
=
"传输方式不能为空"
)
public
String
transMode
;
public
String
apiProtocl
;
@ApiModelProperty
(
value
=
"加密方式0 无,1:MD5 2:RSA"
,
required
=
true
)
@NotNull
(
message
=
"加密方式不能为空"
)
...
...
@@ -66,4 +66,8 @@ public class MakeDataBankApiReq implements Serializable {
@ApiModelProperty
(
value
=
"api样例"
,
required
=
false
)
public
String
apiExample
;
@ApiModelProperty
(
value
=
"文件id"
,
required
=
false
)
//@NotNull(message = "文件id不能为空")
public
Long
fileId
;
}
jz-dm-apigateway/src/main/java/com/jz/dm/models/resp/Auth
Mall
UserResponse.java
→
jz-dm-apigateway/src/main/java/com/jz/dm/models/resp/AuthUserResponse.java
View file @
cf7632b3
...
...
@@ -10,14 +10,14 @@ import java.io.Serializable;
* @author ZC
* @PACKAGE_NAME: com.jz.dm.models.resp
* @PROJECT_NAME: jz-dm-parent
* @NAME: Auth
Mall
UserResponse
* @NAME: AuthUserResponse
* @DATE: 2020-12-30/19:35
* @DAY_NAME_SHORT: 周三
* @Description:
**/
@Data
@ApiModel
public
class
Auth
Mall
UserResponse
implements
Serializable
{
public
class
AuthUserResponse
implements
Serializable
{
@ApiModelProperty
(
value
=
"授权码"
)
public
String
authCode
;
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/impl/AuthServiceImpl.java
View file @
cf7632b3
...
...
@@ -18,12 +18,14 @@ import com.jz.dm.models.domian.ApiInterface;
import
com.jz.dm.models.domian.ApiOrg
;
import
com.jz.dm.models.dto.AuthInfoDto
;
import
com.jz.dm.models.req.auth.*
;
import
com.jz.dm.models.resp.Auth
Mall
UserResponse
;
import
com.jz.dm.models.resp.AuthUserResponse
;
import
com.jz.dm.service.AuthService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.util.Date
;
...
...
@@ -59,7 +61,7 @@ public class AuthServiceImpl implements AuthService {
public
Result
getAuthListInfo
(
AuthListInfoReq
req
)
{
IPage
<
AuthInfoDto
>
page
=
new
Page
<>(
req
.
getPageNum
(),
req
.
getPageSize
());
QueryWrapper
<
AuthInfoDto
>
query
=
new
QueryWrapper
<>();
query
.
orderByDesc
(
"create_date"
);
query
.
orderByDesc
(
"
au.
create_date"
);
IPage
<
AuthInfoDto
>
listSelectApiAuth
=
apiAuthMapper
.
listSelectApiAuth
(
page
,
query
);
return
Result
.
of_success
(
listSelectApiAuth
);
}
...
...
@@ -82,7 +84,9 @@ public class AuthServiceImpl implements AuthService {
* @return
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRES_NEW
)
public
Result
addDmpUserApiAuth
(
AuthDmpUserApiReq
req
)
{
AuthUserResponse
response
=
new
AuthUserResponse
();
ApiInterface
apiInterface
=
getInterface
(
req
.
getApiKey
());
if
(
null
==
apiInterface
)
{
return
Result
.
of_error
(
"api授权信息不存在!"
);
...
...
@@ -93,12 +97,12 @@ public class AuthServiceImpl implements AuthService {
}
//授权验证
if
(
StringUtils
.
isNotBlank
(
req
.
getAuthType
().
name
())
&&
!
AuthTypeEnum
.
DMP_AUTH
.
name
().
equals
(
req
.
getAuthType
()))
{
!
AuthTypeEnum
.
DMP_AUTH
.
name
().
equals
(
req
.
getAuthType
()
.
name
()
))
{
return
Result
.
of_error
(
"授权类型错误!"
);
}
//认证类型
if
(
StringUtils
.
isNotBlank
(
req
.
getAuthMode
().
name
())
&&
AuthModeEnum
.
PERMANENT_TIME_MODE
.
name
().
equals
(
req
.
getAuthMode
()))
{
if
(
StringUtils
.
isBlank
(
req
.
getValidStartTime
())
||
StringUtils
.
isBlank
(
req
.
getValidEndTime
()
))
{
if
(
StringUtils
.
isNotBlank
(
req
.
getAuthMode
().
name
())
&&
AuthModeEnum
.
PERMANENT_TIME_MODE
.
name
().
equals
(
req
.
getAuthMode
()
.
name
()
))
{
if
(
null
==
req
.
getValidStartTime
()
||
null
==
req
.
getValidEndTime
(
))
{
return
Result
.
of_error
(
"开始或结束时间不能为空!"
);
}
}
...
...
@@ -108,22 +112,26 @@ public class AuthServiceImpl implements AuthService {
}
String
authCode
=
""
;
ApiAuth
apiAuth
=
new
ApiAuth
();
apiAuth
.
setAuthType
(
req
.
getAuthType
().
name
());
apiAuth
.
setAuthMode
(
req
.
getAuthMode
().
name
());
apiAuth
.
setApiInterfaceId
(
apiInterface
.
getId
());
apiAuth
.
setApiOrgId
(
apiOrg
.
getId
());
BeanUtils
.
copyProperties
(
req
,
apiAuth
);
apiAuth
.
setApiInterfaceId
(
apiInterface
.
getId
());
if
(
StringUtils
.
isNotBlank
(
req
.
getOrgType
())
//内部组织
&&
Constants
.
AUTH_INT
.
equalsIgnoreCase
(
req
.
getOrgType
()))
{
authCode
=
getAuthCode
(
apiOrg
.
getOrgCode
(),
""
,
Constants
.
AUTH_INT
);
}
/*else if (StringUtils.isNotBlank(req.getOrgType()) //外部组织
&& Constants.AUTH_OUT.equalsIgnoreCase(req.getOrgType())) {
authCode = getAuthCode("", req.getUserId(),Constants.AUTH_OUT);
}*/
apiAuth
.
setAuthCode
(
authCode
);
//授权码
String
salt
=
RandomUtil
.
getStringRandom
(
8
);
apiAuth
.
setSalt
(
salt
);
//盐值
apiAuth
.
setStatus
(
"1"
);
//授权状态
apiAuth
.
setCreateUser
(
""
);
apiAuth
.
setRemark
(
req
.
getRemark
());
response
.
setAuthCode
(
authCode
);
response
.
setSalt
(
salt
);
if
(
apiAuthMapper
.
insert
(
apiAuth
)
>
0
)
{
return
Result
.
of_success
(
ResultMsg
.
SUCCESS
);
return
Result
.
of_success
(
ResultMsg
.
SUCCESS
,
response
);
}
return
Result
.
of_success
(
ResultMsg
.
FAILURE
);
}
...
...
@@ -135,8 +143,9 @@ public class AuthServiceImpl implements AuthService {
* @return
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRES_NEW
)
public
Result
addMallUserApiAuth
(
AuthMallUserApiReq
req
)
{
Auth
MallUserResponse
response
=
new
AuthMall
UserResponse
();
Auth
UserResponse
response
=
new
Auth
UserResponse
();
ApiInterface
apiInterface
=
getInterface
(
req
.
getApiKey
());
if
(
null
==
apiInterface
)
{
return
Result
.
of_error
(
"api授权信息不存在!"
);
...
...
@@ -147,23 +156,26 @@ public class AuthServiceImpl implements AuthService {
}
//授权验证
if
(
StringUtils
.
isNotBlank
(
req
.
getAuthType
().
name
())
&&
!
AuthTypeEnum
.
DATA_BANK_AUTH
.
name
().
equals
(
req
.
getAuthType
()))
{
!
AuthTypeEnum
.
DATA_BANK_AUTH
.
name
().
equals
(
req
.
getAuthType
()
.
name
()
))
{
return
Result
.
of_error
(
"授权类型错误!"
);
}
//认证类型
if
(
StringUtils
.
isNotBlank
(
req
.
getAuthMode
().
name
())
&&
AuthModeEnum
.
RECORD_TIME_MODE
.
name
().
equals
(
req
.
getAuthMode
()))
{
if
(
StringUtils
.
isBlank
(
req
.
getValidStartTime
())
||
StringUtils
.
isBlank
(
req
.
getValidEndTime
()
))
{
if
(
StringUtils
.
isNotBlank
(
req
.
getAuthMode
().
name
())
&&
AuthModeEnum
.
RECORD_TIME_MODE
.
name
().
equals
(
req
.
getAuthMode
()
.
name
()
))
{
if
(
null
==
req
.
getValidStartTime
()
||
null
==
req
.
getValidEndTime
(
))
{
return
Result
.
of_error
(
"开始或结束时间不能为空!"
);
}
}
if
(
StringUtils
.
isNotBlank
(
req
.
getAuthMode
().
name
())
&&
AuthModeEnum
.
PERMANENT_TIME_MODE
.
name
().
equals
(
req
.
getAuthMode
()))
{
AuthModeEnum
.
PERMANENT_TIME_MODE
.
name
().
equals
(
req
.
getAuthMode
()
.
name
()
))
{
return
Result
.
of_error
(
"授权类型错误!"
);
}
String
authCode
=
""
;
ApiAuth
apiAuth
=
new
ApiAuth
();
BeanUtils
.
copyProperties
(
req
,
apiAuth
);
apiAuth
.
setAuthType
(
req
.
getAuthType
().
name
());
apiAuth
.
setAuthMode
(
req
.
getAuthMode
().
name
());
apiAuth
.
setApiInterfaceId
(
apiInterface
.
getId
());
apiAuth
.
setApiOrgId
(
apiOrg
.
getId
());
BeanUtils
.
copyProperties
(
req
,
apiAuth
);
if
(
StringUtils
.
isNotBlank
(
req
.
getOrgType
())
//内部组织
&&
Constants
.
AUTH_INT
.
equalsIgnoreCase
(
req
.
getOrgType
()))
{
authCode
=
getAuthCode
(
apiOrg
.
getOrgCode
(),
""
,
Constants
.
AUTH_INT
);
...
...
@@ -175,6 +187,8 @@ public class AuthServiceImpl implements AuthService {
String
salt
=
RandomUtil
.
getStringRandom
(
8
);
apiAuth
.
setSalt
(
salt
);
//盐值
apiAuth
.
setStatus
(
"1"
);
//授权状态
apiAuth
.
setCreateUser
(
""
);
apiAuth
.
setRemark
(
req
.
getRemark
());
response
.
setAuthCode
(
authCode
);
response
.
setSalt
(
salt
);
if
(
apiAuthMapper
.
insert
(
apiAuth
)
>
0
)
{
...
...
@@ -222,26 +236,27 @@ public class AuthServiceImpl implements AuthService {
*/
@Override
public
Result
updateSaltInfo
(
SaltResetReq
req
)
{
AuthUserResponse
response
=
new
AuthUserResponse
();
ApiAuth
apiAuth
=
apiAuthMapper
.
selectById
(
req
.
getId
());
if
(
null
==
apiAuth
)
{
return
Result
.
of_error
(
"认证用户不存在"
);
}
if
(
StringUtils
.
isNotBlank
(
req
.
getSalt
()))
{
String
salt
=
RandomUtil
.
getStringRandom
(
8
);
UpdateWrapper
<
ApiAuth
>
update
=
new
UpdateWrapper
<>();
update
.
set
(
"salt"
,
req
.
getSalt
()
);
update
.
set
(
"salt"
,
salt
);
update
.
set
(
"create_time"
,
new
Date
());
update
.
set
(
"create_user"
,
""
);
update
.
eq
(
"id"
,
req
.
getId
());
if
(
apiAuthMapper
.
update
(
null
,
update
)
>
0
)
{
re
turn
Result
.
of_success
(
ResultMsg
.
UPDATE_SUCCESS
);
}
re
sponse
.
setSalt
(
salt
);
return
Result
.
of_success
(
ResultMsg
.
UPDATE_SUCCESS
,
response
);
}
return
Result
.
of_success
(
ResultMsg
.
UPDATE_FAIL
);
}
private
ApiInterface
getInterface
(
String
apiKey
)
{
QueryWrapper
<
ApiInterface
>
queryInface
=
new
QueryWrapper
<>();
queryInface
.
last
(
"where is_deleted=0 and api_key =
"
+
apiKey
+
"
"
);
queryInface
.
last
(
"where is_deleted=0 and api_key =
'"
+
apiKey
+
"'
"
);
ApiInterface
apiInterface
=
apiInterfaceMapper
.
selectOne
(
queryInface
);
if
(
null
!=
apiInterface
)
{
return
apiInterface
;
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/impl/ProducerServiceImpl.java
View file @
cf7632b3
...
...
@@ -4,10 +4,10 @@ import com.alibaba.fastjson.JSONArray;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.exceptions.ApiException
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.jz.common.bean.SysUserDto
;
import
com.jz.common.constant.ResultMsg
;
import
com.jz.common.exception.ResponseException
;
import
com.jz.common.utils.RedisUtils
;
import
com.jz.common.utils.Result
;
import
com.jz.dm.common.constant.TagConstants
;
...
...
@@ -123,14 +123,17 @@ public class ProducerServiceImpl implements ProducerService {
&&
"2"
.
equals
(
req
.
getApiType
())){
//数据银行制作API
ApiInterface
anInterface
=
new
ApiInterface
();
anInterface
.
setCreateUser
(
""
);
anInterface
.
setStatus
(
"2"
);
//发布
anInterface
.
setSignType
(
req
.
getType
());
//加密类型
BeanUtils
.
copyProperties
(
req
,
anInterface
);
int
resIn
=
apiInterfaceMapper
.
insert
(
anInterface
);
ApiInterfaceCustom
interfaceCustom
=
new
ApiInterfaceCustom
();
interfaceCustom
.
setCreateUser
(
""
);
interfaceCustom
.
setApiInterfaceId
(
anInterface
.
getId
());
BeanUtils
.
copyProperties
(
req
,
interfaceCustom
);
int
resOut
=
apiInterfaceCustomMapper
.
insert
(
interfaceCustom
);
if
(
resOut
==
0
||
resIn
<
0
){
throw
new
ApiException
(
"保存信息
!"
);
if
(
resOut
==
0
||
resIn
==
0
){
throw
ResponseException
.
of_error
(
"保存信息失败
!"
);
}
}
else
if
(
StringUtils
.
isNotBlank
(
req
.
getApiType
())
&&
"3"
.
equals
(
req
.
getApiType
())){
//数据银行制作数据包
...
...
@@ -139,10 +142,10 @@ public class ProducerServiceImpl implements ProducerService {
}
ApiInterfaceReq
makeBigDataApiReq
=
new
ApiInterfaceReq
();
makeBigDataApiReq
.
setApiType
(
req
.
getApiType
());
makeBigDataApiReq
.
setApiId
(
req
.
getApi
Id
());
makeBigDataApiReq
.
setApiId
(
req
.
getApi
Key
());
makeBigDataApiReq
.
setApiDesc
(
req
.
getApiDesc
());
makeBigDataApiReq
.
setVersion
(
req
.
getVersion
());
makeBigDataApiReq
.
setTransMode
(
req
.
get
TransMode
());
makeBigDataApiReq
.
setTransMode
(
req
.
get
ApiProtocl
());
makeBigDataApiReq
.
setType
(
req
.
getType
());
makeBigDataApiReq
.
setTargetUrl
(
req
.
getTargetUrl
());
makeBigDataApiReq
.
setTimeout
(
req
.
getTimeout
());
...
...
@@ -237,7 +240,7 @@ public class ProducerServiceImpl implements ProducerService {
}
/**
*
*
保存api基本信息
* @param req
* @return
*/
...
...
@@ -263,15 +266,14 @@ public class ProducerServiceImpl implements ProducerService {
}
else
if
(
timeout
>
maxTimeout
)
{
return
Result
.
of_success
(
"接口超时时间最大5000ms"
);
}
apiInterface
.
setTimeout
(
req
.
getTimeout
());
int
res
=
apiInterfaceMapper
.
insert
(
apiInterface
);
if
(
res
==
0
){
throw
new
RuntimeException
(
ResultMsg
.
UPDATE_FAIL
.
getMsg
()
);
throw
ResponseException
.
of_error
(
"保存Api信息失败!"
);
}
return
Result
.
of_success
(
ResultMsg
.
INSERT_SUCCESS
);
}
/**
* 保存修改的api信息
*
...
...
@@ -320,6 +322,7 @@ public class ProducerServiceImpl implements ProducerService {
return
Result
.
of_success
(
"接口超时时间最大5000ms"
);
}
apiInterface
.
setUpdateDate
(
new
Date
());
apiInterface
.
setTimeout
(
req
.
getTimeout
());
//apiInterface.setUpdateUser(currentUser.getUserName());
int
result
=
apiInterfaceMapper
.
updateById
(
apiInterface
);
if
(
result
>
0
)
{
...
...
jz-dm-apigateway/src/main/resources/mapper/ApiAuthMapper.xml
View file @
cf7632b3
...
...
@@ -11,12 +11,20 @@
SELECT au.id AS id,
au.api_org_id AS apiOrgId,
au.api_interface_id AS apiInterFace,
au.auth_mode AS authMode,
au.valid_start_time AS validStartTime,
au.valid_end_time AS validEndTime,
au.status AS status,
(CASE au.auth_mode
WHEN 'RECORD_TIME_MODE' THEN '按时间调用'
WHEN 'PERMANENT_TIME_MODE' THEN '永久有效'
WHEN 'POWER_CALL_MODE' THEN '按次调用'
END) AS authMode,
au.auth_code AS authCode,
DATE_FORMAT(au.valid_start_time,'%Y-%m-%d %H:%i:%s') AS validStartTime,
DATE_FORMAT(au.valid_end_time,'%Y-%m-%d %H:%i:%s') AS validEndTime,
(CASE au.status
WHEN '1' THEN '正常'
WHEN '2' THEN '作废'
END) AS status,
au.remark AS remark,
au.create_time
AS createDate,
DATE_FORMAT(au.create_date,'%Y-%m-%d %H:%i:%s')
AS createDate,
au.create_user AS createUser,
ao.org_name AS orgName,
ai.api_key AS apiKey
...
...
@@ -24,19 +32,27 @@
JOIN t_api_interface AS ai ON au.api_interface_id = ai.id AND ai.is_deleted =0 AND ai.`status` ='2'
JOIN t_api_org AS ao ON au.api_org_id = ao.id AND ao.`status` ='1' AND ao.is_deleted =0
WHERE au.is_deleted =0
AND au.id =#{req.
getI
d}
AND au.id =#{req.
i
d}
</select>
<select
id=
"listSelectApiAuth"
resultType=
"com.jz.dm.models.dto.AuthInfoDto"
>
SELECT au.id AS id,
au.api_org_id AS apiOrgId,
au.api_interface_id AS apiInterFace,
au.auth_mode AS authMode,
au.valid_start_time AS validStartTime,
au.valid_end_time AS validEndTime,
au.status AS status,
(CASE au.auth_mode
WHEN 'RECORD_TIME_MODE' THEN '按时间调用'
WHEN 'PERMANENT_TIME_MODE' THEN '永久有效'
WHEN 'POWER_CALL_MODE' THEN '按次调用'
END) AS authMode,
au.auth_code AS authCode,
DATE_FORMAT(au.valid_start_time,'%Y-%m-%d %H:%i:%s') AS validStartTime,
DATE_FORMAT(au.valid_end_time,'%Y-%m-%d %H:%i:%s') AS validEndTime,
(CASE au.status
WHEN '1' THEN '正常'
WHEN '2' THEN '作废'
END) AS status,
au.remark AS remark,
au.create_time
AS createDate,
DATE_FORMAT(au.create_date,'%Y-%m-%d %H:%i:%s')
AS createDate,
au.create_user AS createUser,
ao.org_name AS orgName,
ai.api_key AS apiKey
...
...
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/
org
/TestAuth.java
→
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/
auth
/TestAuth.java
View file @
cf7632b3
package
com
.
jz
.
dm
.
gateway
.
org
;
package
com
.
jz
.
dm
.
gateway
.
auth
;
import
com.jz.dm.gateway.SpringTestCase
;
import
com.jz.dm.service.AuthService
;
...
...
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