Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
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
fangxinjiang
yifu-mvp
Commits
9ee46006
Commit
9ee46006
authored
Aug 22, 2022
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ekp-common
parent
bf2fb84c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
154 deletions
+61
-154
pom.xml
yifu-common/yifu-common-ekp/pom.xml
+2
-10
EkpSalaryProperties.java
...fu.cloud.plus.v1/yifu/ekp/config/EkpSalaryProperties.java
+32
-0
EkpSalaryUtil.java
...a/com/yifu.cloud.plus.v1/yifu/ekp/util/EkpSalaryUtil.java
+20
-0
spring.factories
...u-common-ekp/src/main/resources/META-INF/spring.factories
+1
-1
ekpSalaryConfig.properties
...-common-ekp/src/main/resources/ekpSalaryConfig.properties
+6
-0
WithMockSecurityContextFactory.java
...oud.plus.v1/yifu/test/WithMockSecurityContextFactory.java
+0
-85
WithMockOAuth2User.java
...loud.plus.v1/yifu/test/annotation/WithMockOAuth2User.java
+0
-29
OAuthMockKit.java
...va/com/yifu.cloud.plus.v1/yifu/test/kit/OAuthMockKit.java
+0
-29
No files found.
yifu-common/yifu-common-
test
/pom.xml
→
yifu-common/yifu-common-
ekp
/pom.xml
View file @
9ee46006
...
...
@@ -9,19 +9,11 @@
<version>
1.0.0
</version>
</parent>
<artifactId>
yifu-common-
test
</artifactId>
<artifactId>
yifu-common-
ekp
</artifactId>
<packaging>
jar
</packaging>
<description>
yifu
oauth 2.0 单元测试
工具类
</description>
<description>
yifu
EKP
工具类
</description>
<dependencies>
<dependency>
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-common-security
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-test
</artifactId>
</dependency>
</dependencies>
</project>
yifu-common/yifu-common-ekp/src/main/java/com/yifu.cloud.plus.v1/yifu/ekp/config/EkpSalaryProperties.java
0 → 100644
View file @
9ee46006
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
ekp
.
config
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.stereotype.Component
;
/**
* @Author fxj
* @Description 薪资明细对接
* @Date 11:57 2022/8/22
* @Param
* @return
**/
@Data
@Component
@PropertySource
(
"classpath:ekpSalaryConfig.properties"
)
@ConfigurationProperties
(
value
=
"ekp"
,
ignoreInvalidFields
=
false
)
public
class
EkpSalaryProperties
{
String
url
;
String
fdModelId
;
String
fdFlowId
;
String
docStatus
;
String
LoginName
;
String
docSubject
;
}
yifu-common/yifu-common-ekp/src/main/java/com/yifu.cloud.plus.v1/yifu/ekp/util/EkpSalaryUtil.java
0 → 100644
View file @
9ee46006
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
ekp
.
util
;
import
com.yifu.cloud.plus.v1.yifu.common.ekp.config.EkpSalaryProperties
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
/**
* @Author fxj
* @Date 2022/7/11
* @Description
* @Version 1.0
*/
@Log4j2
@EnableConfigurationProperties
(
EkpSalaryProperties
.
class
)
public
class
EkpSalaryUtil
{
@Autowired
private
EkpSalaryProperties
ekpProperties
;
}
yifu-common/yifu-common-ekp/src/main/resources/META-INF/spring.factories
View file @
9ee46006
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.yifu.cloud.plus.v1.yifu.common.dapr.util.EkpSalaryUtil
\ No newline at end of file
com.yifu.cloud.plus.v1.yifu.ekp.util.EkpSalaryUtil
\ No newline at end of file
yifu-common/yifu-common-ekp/src/main/resources/ekpSalaryConfig.properties
0 → 100644
View file @
9ee46006
ekp.url
=
http://119.96.227.251:8080/api/sys-modeling/appModelRestService/addModel
ekp.fdModelId
=
'181d7633ff8bc797276d0d3a54e80ad6'
ekp.fdFlowId
=
'182b40249c1bc940d7226b941c7a4183'
ekp.docStatus
=
'20'
ekp.LoginName
=
'admin'
ekp.docSubject
=
'\u85AA\u8D44\u8BA2\u5355\u660E\u7EC6\u6570\u636E\u63A5\u53E3'
yifu-common/yifu-common-test/src/main/java/com/yifu.cloud.plus.v1/yifu/test/WithMockSecurityContextFactory.java
deleted
100644 → 0
View file @
bf2fb84c
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
test
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.json.JSONUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.SpringContextHolder
;
import
com.yifu.cloud.plus.v1.yifu.test.annotation.WithMockOAuth2User
;
import
org.springframework.security.core.context.SecurityContext
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.oauth2.client.OAuth2ClientContext
;
import
org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails
;
import
org.springframework.security.oauth2.common.DefaultOAuth2AccessToken
;
import
org.springframework.security.oauth2.provider.OAuth2Authentication
;
import
org.springframework.security.oauth2.provider.token.RemoteTokenServices
;
import
org.springframework.security.test.context.support.WithSecurityContextFactory
;
/**
* @author lengleng
* @date 2020/9/22
* <p>
* oauth2 上下文生成处理器
*/
public
class
WithMockSecurityContextFactory
implements
WithSecurityContextFactory
<
WithMockOAuth2User
>
{
@Override
public
SecurityContext
createSecurityContext
(
WithMockOAuth2User
oAuth2User
)
{
// 1. 请求认证中心获取token
String
token
=
getToken
(
oAuth2User
);
// 2. 解析认证中心返回用户
OAuth2Authentication
authentication
=
getUser
(
token
);
// 3. 构建 oauth2 上下文
SecurityContext
context
=
SecurityContextHolder
.
createEmptyContext
();
context
.
setAuthentication
(
authentication
);
// 4. 上下文保存 token
DefaultOAuth2AccessToken
accessToken
=
new
DefaultOAuth2AccessToken
(
token
);
OAuth2ClientContext
clientContext
=
SpringContextHolder
.
getBean
(
OAuth2ClientContext
.
class
);
clientContext
.
setAccessToken
(
accessToken
);
return
context
;
}
/**
* 请求认证中心获取token
* @param oAuth2User 账号、密码
* @return String token
*/
private
String
getToken
(
WithMockOAuth2User
oAuth2User
)
{
OAuth2ProtectedResourceDetails
clientProperties
=
SpringContextHolder
.
getBean
(
OAuth2ProtectedResourceDetails
.
class
);
String
result
=
HttpRequest
.
post
(
clientProperties
.
getAccessTokenUri
())
.
basicAuth
(
clientProperties
.
getClientId
(),
clientProperties
.
getClientSecret
())
.
form
(
"username"
,
oAuth2User
.
username
()).
form
(
"password"
,
oAuth2User
.
password
())
.
form
(
"grant_type"
,
"password"
).
form
(
"scope"
,
clientProperties
.
getScope
()).
execute
().
body
();
return
JSONUtil
.
parseObj
(
result
).
getStr
(
"access_token"
);
}
/**
* 使用token 获取用户详情
* @param token token
* @return user详细
*/
private
OAuth2Authentication
getUser
(
String
token
)
{
RemoteTokenServices
tokenServices
=
SpringContextHolder
.
getBean
(
RemoteTokenServices
.
class
);
return
tokenServices
.
loadAuthentication
(
token
);
}
}
yifu-common/yifu-common-test/src/main/java/com/yifu.cloud.plus.v1/yifu/test/annotation/WithMockOAuth2User.java
deleted
100644 → 0
View file @
bf2fb84c
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
test
.
annotation
;
import
com.yifu.cloud.plus.v1.yifu.test.WithMockSecurityContextFactory
;
import
org.springframework.security.test.context.support.WithSecurityContext
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
/**
* @author lengleng
* @date 2020/9/22
* <p>
* WithMockOAuth2User 注解
*/
@Retention
(
RetentionPolicy
.
RUNTIME
)
@WithSecurityContext
(
factory
=
WithMockSecurityContextFactory
.
class
)
public
@interface
WithMockOAuth2User
{
/**
* 用户名
*/
String
username
()
default
"admin"
;
/**
* 密码
*/
String
password
()
default
"123456"
;
}
\ No newline at end of file
yifu-common/yifu-common-test/src/main/java/com/yifu.cloud.plus.v1/yifu/test/kit/OAuthMockKit.java
deleted
100644 → 0
View file @
bf2fb84c
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
test
.
kit
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.SpringContextHolder
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.security.oauth2.client.OAuth2ClientContext
;
import
org.springframework.test.web.servlet.request.RequestPostProcessor
;
/**
* @author lengleng
* @date 2020/9/22
* <p>
* Mock 工具类
*/
public
class
OAuthMockKit
{
/**
* mock 请求增加统一请求头
* @return RequestPostProcessor 类似于拦截器
*/
public
static
RequestPostProcessor
token
()
{
return
mockRequest
->
{
OAuth2ClientContext
clientContext
=
SpringContextHolder
.
getBean
(
OAuth2ClientContext
.
class
);
String
token
=
clientContext
.
getAccessToken
().
getValue
();
mockRequest
.
addHeader
(
HttpHeaders
.
AUTHORIZATION
,
String
.
format
(
"Bearer: %s"
,
token
));
return
mockRequest
;
};
}
}
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