Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
71171a71
提交
71171a71
编写于
2月 08, 2021
作者:
tangyaolong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
oauth2 Feign自动校验
上级
0dc3b762
变更
3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
93 行增加
和
4 行删除
+93
-4
IBZUAAFallback.java.ftl
...in/java/%SYS_PKGPATH%/util/client/IBZUAAFallback.java.ftl
+17
-0
IBZUAAFeignClient.java.ftl
...java/%SYS_PKGPATH%/util/client/IBZUAAFeignClient.java.ftl
+20
-0
FeignRequestInterceptor.java.ftl
...a/%SYS_PKGPATH%/util/web/FeignRequestInterceptor.java.ftl
+56
-4
未找到文件。
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/client/IBZUAAFallback.java.ftl
浏览文件 @
71171a71
<#
ibiztemplate
>
<#
ibiztemplate
>
TARGET
=
PSSYSTEM
TARGET
=
PSSYSTEM
</#
ibiztemplate
>
</#
ibiztemplate
>
<#
assign
oauth2Enable
=
false
>
<#
if
sysrun
??
&&
sysrun
.
getPSDevSlnMSDepAPI
()??
>
<#
assign
depSysApi
=
sysrun
.
getPSDevSlnMSDepAPI
()>
<#
if
depSysApi
.
getPSDCMSPlatformNode
()??>
<#
assign
depSysApiPlatformNode
=
depSysApi
.
getPSDCMSPlatformNode
()>
<#
assign
depSysApiPlatform
=
depSysApi
.
getPSDCMSPlatform
()>
<#
if
depSysApiPlatform
.
getUserParam
(
"ibiz.oauth2.enable"
,
""
)??
&&
depSysApiPlatform
.
getUserParam
(
"ibiz.oauth2.enable"
,
""
)
!="">
<#
assign
oauth2Enable
=
true
>
</#
if
>
</#
if
>
</#
if
>
package
${
pub
.
getPKGCodeName
()}.
util
.
client
;
package
${
pub
.
getPKGCodeName
()}.
util
.
client
;
import
${
pub
.
getPKGCodeName
()}.
util
.
security
.
AuthenticationUser
;
import
${
pub
.
getPKGCodeName
()}.
util
.
security
.
AuthenticationUser
;
...
@@ -26,6 +37,12 @@ public class IBZUAAFallback implements IBZUAAFeignClient {
...
@@ -26,6 +37,12 @@ public class IBZUAAFallback implements IBZUAAFeignClient {
return
null
;
return
null
;
}
}
<#
if
oauth2Enable
>
@
Override
public
Object
getToken
(
MultiValueMap
<
String
,
String
>
map
){
return
null
;
}
</#
if
>
@
Override
@
Override
public
String
getPublicKey
()
{
public
String
getPublicKey
()
{
return
null
;
return
null
;
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/client/IBZUAAFeignClient.java.ftl
浏览文件 @
71171a71
<#
ibiztemplate
>
<#
ibiztemplate
>
TARGET
=
PSSYSTEM
TARGET
=
PSSYSTEM
</#
ibiztemplate
>
</#
ibiztemplate
>
<#
assign
oauth2Enable
=
false
>
<#
if
sysrun
??
&&
sysrun
.
getPSDevSlnMSDepAPI
()??
>
<#
assign
depSysApi
=
sysrun
.
getPSDevSlnMSDepAPI
()>
<#
if
depSysApi
.
getPSDCMSPlatformNode
()??>
<#
assign
depSysApiPlatformNode
=
depSysApi
.
getPSDCMSPlatformNode
()>
<#
assign
depSysApiPlatform
=
depSysApi
.
getPSDCMSPlatform
()>
<#
if
depSysApiPlatform
.
getUserParam
(
"ibiz.oauth2.enable"
,
""
)??
&&
depSysApiPlatform
.
getUserParam
(
"ibiz.oauth2.enable"
,
""
)
!="">
<#
assign
oauth2Enable
=
true
>
</#
if
>
</#
if
>
</#
if
>
package
${
pub
.
getPKGCodeName
()}.
util
.
client
;
package
${
pub
.
getPKGCodeName
()}.
util
.
client
;
import
${
pub
.
getPKGCodeName
()}.
util
.
security
.
AuthenticationUser
;
import
${
pub
.
getPKGCodeName
()}.
util
.
security
.
AuthenticationUser
;
...
@@ -29,6 +40,15 @@ public interface IBZUAAFeignClient
...
@@ -29,6 +40,15 @@ public interface IBZUAAFeignClient
@
PostMapping
(
value
=
"/uaa/login"
)
@
PostMapping
(
value
=
"/uaa/login"
)
AuthenticationUser
login
(@
RequestBody
AuthorizationLogin
authorizationLogin
);
AuthenticationUser
login
(@
RequestBody
AuthorizationLogin
authorizationLogin
);
<#
if
oauth2Enable
>
/**
*
oauth2
认证
*
@
param
校验信息
*
@
return
*/
@
RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/oauth/token"
)
Object
getToken
(@
RequestBody
MultiValueMap
<
String
,
String
>
map
);
</#
if
>
@
PostMapping
(
value
=
"/uaa/loginbyusername"
)
@
PostMapping
(
value
=
"/uaa/loginbyusername"
)
AuthenticationUser
loginByUsername
(@
RequestBody
String
username
);
AuthenticationUser
loginByUsername
(@
RequestBody
String
username
);
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/web/FeignRequestInterceptor.java.ftl
浏览文件 @
71171a71
<#
ibiztemplate
>
<#
ibiztemplate
>
TARGET
=
PSSYSTEM
TARGET
=
PSSYSTEM
</#
ibiztemplate
>
</#
ibiztemplate
>
<#
assign
oauth2Enable
=
false
>
<#
if
sysrun
??
&&
sysrun
.
getPSDevSlnMSDepAPI
()??
>
<#
assign
depSysApi
=
sysrun
.
getPSDevSlnMSDepAPI
()>
<#
if
depSysApi
.
getPSDCMSPlatformNode
()??>
<#
assign
depSysApiPlatformNode
=
depSysApi
.
getPSDCMSPlatformNode
()>
<#
assign
depSysApiPlatform
=
depSysApi
.
getPSDCMSPlatform
()>
<#
if
depSysApiPlatform
.
getUserParam
(
"ibiz.oauth2.enable"
,
""
)??
&&
depSysApiPlatform
.
getUserParam
(
"ibiz.oauth2.enable"
,
""
)
!="">
<#
assign
oauth2Enable
=
true
>
</#
if
>
</#
if
>
</#
if
>
package
${
pub
.
getPKGCodeName
()}.
util
.
web
;
package
${
pub
.
getPKGCodeName
()}.
util
.
web
;
import
feign
.
RequestInterceptor
;
import
feign
.
RequestInterceptor
;
import
feign
.
RequestTemplate
;
import
feign
.
RequestTemplate
;
import
net
.
ibizsys
.
sample
.
mng
.
util
.
client
.
IBZUAAFeignClient
;
import
org
.
slf4j
.
Logger
;
import
org
.
slf4j
.
Logger
;
import
org
.
slf4j
.
LoggerFactory
;
import
org
.
slf4j
.
LoggerFactory
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Value
;
import
org
.
springframework
.
context
.
annotation
.
Configuration
;
import
org
.
springframework
.
context
.
annotation
.
Configuration
;
import
org
.
springframework
.
util
.
LinkedMultiValueMap
;
import
org
.
springframework
.
util
.
MultiValueMap
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
org
.
springframework
.
web
.
context
.
request
.
RequestContextHolder
;
import
org
.
springframework
.
web
.
context
.
request
.
RequestContextHolder
;
import
org
.
springframework
.
web
.
context
.
request
.
ServletRequestAttributes
;
import
org
.
springframework
.
web
.
context
.
request
.
ServletRequestAttributes
;
import
javax
.
servlet
.
http
.
HttpServletRequest
;
import
javax
.
servlet
.
http
.
HttpServletRequest
;
import
java
.
util
.
Enumeration
;
import
java
.
util
.
Enumeration
;
import
java
.
util
.
LinkedHashMap
;
/**
/**
*
feign
请求拦截器
*
feign
请求拦截器
...
@@ -22,23 +41,56 @@ public class FeignRequestInterceptor implements RequestInterceptor {
...
@@ -22,23 +41,56 @@ public class FeignRequestInterceptor implements RequestInterceptor {
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
<#
if
oauth2Enable
>
@
Autowired
IBZUAAFeignClient
ibzuaaFeignClient
;
@
Value
(
"${r'${ibiz.oauth2.grantType:client_credentials}'}"
)
private
String
grantType
;
@
Value
(
"${r'${ibiz.oauth2.clientId:test}'}"
)
private
String
clientId
;
@
Value
(
"${r'${ibiz.oauth2.clientSecret:test}'}"
)
private
String
clientSecret
;
@
Value
(
"${r'${ibiz.oauth2.header:accesstoken}'}"
)
private
String
oauth2Authorization
;
</#
if
>
@
Override
@
Override
public
void
apply
(
RequestTemplate
requestTemplate
)
{
public
void
apply
(
RequestTemplate
requestTemplate
)
{
ServletRequestAttributes
requestAttributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
ServletRequestAttributes
requestAttributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
if
(
requestAttributes
!=null){
<#
if
oauth2Enable
>
if
(
requestTemplate
.
path
().
matches
(
"/oauth/token"
)){
return
;
}
</#
if
>
if
(
requestAttributes
!= null) {
HttpServletRequest
request
=
requestAttributes
.
getRequest
();
HttpServletRequest
request
=
requestAttributes
.
getRequest
();
Enumeration
<
String
>
headerNames
=
request
.
getHeaderNames
();
Enumeration
<
String
>
headerNames
=
request
.
getHeaderNames
();
if
(
headerNames
!= null) {
if
(
headerNames
!= null) {
while
(
headerNames
.
hasMoreElements
())
{
while
(
headerNames
.
hasMoreElements
())
{
String
name
=
headerNames
.
nextElement
();
String
name
=
headerNames
.
nextElement
();
if
(
name
.
equalsIgnoreCase
(
"transfer-encoding"
))
{
if
(
name
.
equalsIgnoreCase
(
"transfer-encoding"
))
{
continue
;
continue
;
}
}
String
values
=
request
.
getHeader
(
name
);
String
values
=
request
.
getHeader
(
name
);
requestTemplate
.
header
(
name
,
values
);
requestTemplate
.
header
(
name
,
values
);
}
}
logger
.
info
(
"feign interceptor header:{}"
,
requestTemplate
);
<#
if
oauth2Enable
>
if
(
ObjectUtils
.
isEmpty
(
request
.
getHeader
(
oauth2Authorization
))){
MultiValueMap
<
String
,
String
>
postParameters
=
new
LinkedMultiValueMap
<>();
postParameters
.
add
(
"client_id"
,
clientId
);
postParameters
.
add
(
"client_secret"
,
clientSecret
);
postParameters
.
add
(
"grant_type"
,
grantType
);
LinkedHashMap
<
String
,
String
>
token
=
(
LinkedHashMap
<
String
,
String
>)
ibzuaaFeignClient
.
getToken
(
postParameters
);
if
(
!ObjectUtils.isEmpty(token.get("access_token"))){
requestTemplate
.
header
(
oauth2Authorization
,
"Bearer "
+
token
.
get
(
"access_token"
));
}
}
</#
if
>
logger
.
info
(
"feign interceptor header:{}"
,
requestTemplate
);
}
}
}
}
}
}
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录