Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-cloud
Overview
Overview
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
黄营
datax-cloud
Commits
ae2cf8b2
Commit
ae2cf8b2
authored
Nov 19, 2019
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目初始化
parent
e4d65d2f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
111 deletions
+39
-111
AuthorizationServerConfig.java
.../java/cn/datax/auth/config/AuthorizationServerConfig.java
+4
-4
DataUserDetailService.java
...ain/java/cn/datax/auth/service/DataUserDetailService.java
+3
-2
DataConstant.java
...core/src/main/java/cn/datax/common/core/DataConstant.java
+17
-90
DataFeignRequestInterceptor.java
...ax/common/security/feign/DataFeignRequestInterceptor.java
+3
-3
DataServerProtectInterceptor.java
...on/security/interceptor/DataServerProtectInterceptor.java
+5
-5
DataUserAuthenticationConverter.java
...ommon/security/utils/DataUserAuthenticationConverter.java
+3
-3
DataGatewayRequestFilter.java
...ava/cn/datax/gateway/filter/DataGatewayRequestFilter.java
+2
-2
LoginController.java
...a/cn/datax/service/system/controller/LoginController.java
+1
-1
UserServiceImpl.java
...cn/datax/service/system/service/impl/UserServiceImpl.java
+1
-1
No files found.
datax-auth/src/main/java/cn/datax/auth/config/AuthorizationServerConfig.java
View file @
ae2cf8b2
...
@@ -118,10 +118,10 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
...
@@ -118,10 +118,10 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
return
(
accessToken
,
authentication
)
->
{
return
(
accessToken
,
authentication
)
->
{
final
Map
<
String
,
Object
>
additionalInfo
=
new
HashMap
<>();
final
Map
<
String
,
Object
>
additionalInfo
=
new
HashMap
<>();
DataUser
user
=
(
DataUser
)
authentication
.
getUserAuthentication
().
getPrincipal
();
DataUser
user
=
(
DataUser
)
authentication
.
getUserAuthentication
().
getPrincipal
();
additionalInfo
.
put
(
DataConstant
.
UserAdditionalInfo
.
LICENSE
.
getKey
()
,
"datax"
);
additionalInfo
.
put
(
DataConstant
.
DETAILS_SECURITY_LICENSE
,
"datax"
);
additionalInfo
.
put
(
DataConstant
.
UserAdditionalInfo
.
USERID
.
getKey
()
,
user
.
getId
());
additionalInfo
.
put
(
DataConstant
.
DETAILS_SECURITY_USER_ID
,
user
.
getId
());
additionalInfo
.
put
(
DataConstant
.
UserAdditionalInfo
.
USERNAME
.
getKey
()
,
user
.
getUsername
());
additionalInfo
.
put
(
DataConstant
.
DETAILS_SECURITY_USERNAME
,
user
.
getUsername
());
additionalInfo
.
put
(
DataConstant
.
UserAdditionalInfo
.
NICKNAME
.
getKey
()
,
user
.
getNickname
());
additionalInfo
.
put
(
DataConstant
.
DETAILS_SECURITY_NICKNAME
,
user
.
getNickname
());
((
DefaultOAuth2AccessToken
)
accessToken
).
setAdditionalInformation
(
additionalInfo
);
((
DefaultOAuth2AccessToken
)
accessToken
).
setAdditionalInformation
(
additionalInfo
);
return
accessToken
;
return
accessToken
;
};
};
...
...
datax-auth/src/main/java/cn/datax/auth/service/DataUserDetailService.java
View file @
ae2cf8b2
...
@@ -34,6 +34,7 @@ public class DataUserDetailService implements UserDetailsService {
...
@@ -34,6 +34,7 @@ public class DataUserDetailService implements UserDetailsService {
public
UserDetails
loadUserByUsername
(
String
s
)
throws
UsernameNotFoundException
{
public
UserDetails
loadUserByUsername
(
String
s
)
throws
UsernameNotFoundException
{
//远程获取用户
//远程获取用户
R
result
=
userServiceFeign
.
loginByUsername
(
s
);
R
result
=
userServiceFeign
.
loginByUsername
(
s
);
log
.
info
(
JSON
.
toJSONString
(
result
));
if
(
result
==
null
||
ObjectUtil
.
isEmpty
(
result
.
getData
())){
if
(
result
==
null
||
ObjectUtil
.
isEmpty
(
result
.
getData
())){
throw
new
UsernameNotFoundException
(
StrUtil
.
format
(
"{}用户不存在"
,
s
));
throw
new
UsernameNotFoundException
(
StrUtil
.
format
(
"{}用户不存在"
,
s
));
}
}
...
@@ -53,10 +54,10 @@ public class DataUserDetailService implements UserDetailsService {
...
@@ -53,10 +54,10 @@ public class DataUserDetailService implements UserDetailsService {
UserVo
userVo
=
userInfo
.
getUserVo
();
UserVo
userVo
=
userInfo
.
getUserVo
();
List
<
RoleVo
>
roles
=
userVo
.
getRoles
();
List
<
RoleVo
>
roles
=
userVo
.
getRoles
();
if
(
CollUtil
.
isNotEmpty
(
roles
))
{
if
(
CollUtil
.
isNotEmpty
(
roles
))
{
roles
.
stream
().
filter
(
roleVo
->
DataConstant
.
EnableState
.
ENABLE
.
getKey
()
==
roleVo
.
getStatus
()
&&
StrUtil
.
isNotBlank
(
roleVo
.
getRoleCode
())).
forEach
(
roleVo
->
authsSet
.
add
(
DataConstant
.
Security
.
ROLEPREFIX
.
getVal
()
+
roleVo
.
getRoleCode
()));
roles
.
stream
().
filter
(
roleVo
->
DataConstant
.
TRUE
==
roleVo
.
getStatus
()
&&
StrUtil
.
isNotBlank
(
roleVo
.
getRoleCode
())).
forEach
(
roleVo
->
authsSet
.
add
(
DataConstant
.
ROLE
+
roleVo
.
getRoleCode
()));
}
}
if
(
CollUtil
.
isEmpty
(
authsSet
)){
if
(
CollUtil
.
isEmpty
(
authsSet
)){
authsSet
.
add
(
DataConstant
.
Security
.
ROLEPREFIX
.
getVal
()
+
"VISITO
R"
);
authsSet
.
add
(
DataConstant
.
ROLE
+
"USE
R"
);
}
}
Collection
<?
extends
GrantedAuthority
>
authorities
Collection
<?
extends
GrantedAuthority
>
authorities
=
AuthorityUtils
.
createAuthorityList
(
authsSet
.
toArray
(
new
String
[
0
]));
=
AuthorityUtils
.
createAuthorityList
(
authsSet
.
toArray
(
new
String
[
0
]));
...
...
datax-common/datax-common-core/src/main/java/cn/datax/common/core/DataConstant.java
View file @
ae2cf8b2
...
@@ -3,106 +3,33 @@ package cn.datax.common.core;
...
@@ -3,106 +3,33 @@ package cn.datax.common.core;
public
class
DataConstant
{
public
class
DataConstant
{
/**
/**
*
Oauth2安全相关常量
*
Gateway请求头TOKEN名称(不要有空格)
*/
*/
public
static
enum
Security
{
public
static
final
String
GATEWAY_TOKEN_HEADER
=
"GatewayToken"
;
//请求头TOKEN名称
TOKENHEADER
(
"tokenHeader"
,
"gatewayToken"
),
//请求头TOKEN值
TOKENVALUE
(
"tokenValue"
,
"datax:gateway:123456"
),
//OAUTH2令牌类型
TOKENTYPE
(
"tokenType"
,
"bearer "
),
//security授权角色前缀
ROLEPREFIX
(
"rolePrefix"
,
"ROLE_"
);
Security
(
String
key
,
String
val
){
this
.
key
=
key
;
this
.
val
=
val
;
}
private
final
String
key
;
private
final
String
val
;
public
String
getKey
()
{
return
key
;
}
public
String
getVal
()
{
return
val
;
}
}
/**
/**
*
通用的是否
*
Gateway请求头TOKEN值
*/
*/
public
static
enum
TrueOrFalse
{
public
static
final
String
GATEWAY_TOKEN_VALUE
=
"datax:gateway:123456"
;
FALSE
(
0
,
false
),
TRUE
(
1
,
true
);
TrueOrFalse
(
Integer
key
,
boolean
val
){
this
.
key
=
key
;
this
.
val
=
val
;
}
private
final
Integer
key
;
private
final
boolean
val
;
public
Integer
getKey
()
{
return
key
;
}
public
boolean
getVal
()
{
return
val
;
}
}
/**
/**
*
用户认证返回额外信息
*
OAUTH2 令牌类型
*/
*/
public
static
enum
UserAdditionalInfo
{
public
static
final
String
OAUTH2_TOKEN_TYPE
=
"bearer "
;
LICENSE
(
"license"
,
"许可证"
),
USER
(
"user"
,
"用户"
),
USERID
(
"user_id"
,
"用户ID"
),
USERNAME
(
"username"
,
"用户名"
),
NICKNAME
(
"nickname"
,
"用户昵称"
),
DEPT
(
"user_dept"
,
"用户部门"
),
ROLE
(
"user_role"
,
"用户角色"
),
POST
(
"user_post"
,
"用户岗位"
);
UserAdditionalInfo
(
String
key
,
String
val
){
this
.
key
=
key
;
this
.
val
=
val
;
}
private
final
String
key
;
private
final
String
val
;
public
String
getKey
()
{
return
key
;
}
public
String
getVal
()
{
public
static
String
ROLE
=
"ROLE_"
;
return
val
;
}
}
/**
public
static
int
TRUE
=
1
;
* 通用的启用禁用状态
*/
public
static
enum
EnableState
{
DISABLE
(
0
,
"禁用"
),
ENABLE
(
1
,
"启用"
);
EnableState
(
Integer
key
,
String
val
){
this
.
key
=
key
;
this
.
val
=
val
;
}
private
final
Integer
key
;
public
static
int
FALSE
=
0
;
private
final
String
val
;
public
Integer
getKey
()
{
public
static
String
DETAILS_SECURITY_LICENSE
=
"license"
;
return
key
;
public
static
String
DETAILS_SECURITY_DATAX_USER
=
"datax_user"
;
}
public
static
String
DETAILS_SECURITY_USER_ID
=
"user_id"
;
public
static
String
DETAILS_SECURITY_USERNAME
=
"username"
;
public
static
String
DETAILS_SECURITY_NICKNAME
=
"nickname"
;
public
static
String
DETAILS_SECURITY_USER_DEPT
=
"user_dept"
;
public
static
String
DETAILS_SECURITY_USER_ROLE
=
"user_role"
;
public
static
String
DETAILS_SECURITY_USER_POST
=
"user_post"
;
public
String
getVal
()
{
return
val
;
}
}
}
}
datax-common/datax-common-security/src/main/java/cn/datax/common/security/feign/DataFeignRequestInterceptor.java
View file @
ae2cf8b2
...
@@ -16,13 +16,13 @@ public class DataFeignRequestInterceptor {
...
@@ -16,13 +16,13 @@ public class DataFeignRequestInterceptor {
public
RequestInterceptor
oauth2FeignRequestInterceptor
()
{
public
RequestInterceptor
oauth2FeignRequestInterceptor
()
{
return
requestTemplate
->
{
return
requestTemplate
->
{
// 请求头中添加 Gateway Token
// 请求头中添加 Gateway Token
String
tokenValue
=
new
String
(
Base64Utils
.
encode
(
DataConstant
.
Security
.
TOKENVALUE
.
getVal
()
.
getBytes
()));
String
zuulToken
=
new
String
(
Base64Utils
.
encode
(
DataConstant
.
GATEWAY_TOKEN_VALUE
.
getBytes
()));
requestTemplate
.
header
(
DataConstant
.
Security
.
TOKENHEADER
.
getVal
(),
tokenValue
);
requestTemplate
.
header
(
DataConstant
.
GATEWAY_TOKEN_HEADER
,
zuulToken
);
// 请求头中添加原请求头中的 Token
// 请求头中添加原请求头中的 Token
Object
details
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getDetails
();
Object
details
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getDetails
();
if
(
details
instanceof
OAuth2AuthenticationDetails
)
{
if
(
details
instanceof
OAuth2AuthenticationDetails
)
{
String
authorizationToken
=
((
OAuth2AuthenticationDetails
)
details
).
getTokenValue
();
String
authorizationToken
=
((
OAuth2AuthenticationDetails
)
details
).
getTokenValue
();
requestTemplate
.
header
(
HttpHeaders
.
AUTHORIZATION
,
DataConstant
.
Security
.
TOKENTYPE
.
getVal
()
+
authorizationToken
);
requestTemplate
.
header
(
HttpHeaders
.
AUTHORIZATION
,
DataConstant
.
OAUTH2_TOKEN_TYPE
+
authorizationToken
);
}
}
};
};
}
}
...
...
datax-common/datax-common-security/src/main/java/cn/datax/common/security/interceptor/DataServerProtectInterceptor.java
View file @
ae2cf8b2
...
@@ -16,11 +16,11 @@ public class DataServerProtectInterceptor implements HandlerInterceptor {
...
@@ -16,11 +16,11 @@ public class DataServerProtectInterceptor implements HandlerInterceptor {
@Override
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
IOException
{
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
IOException
{
// 从请求头中获取Token
// 从请求头中获取
Zuul
Token
String
token
=
request
.
getHeader
(
DataConstant
.
Security
.
TOKENVALUE
.
getVal
()
);
String
token
=
request
.
getHeader
(
DataConstant
.
GATEWAY_TOKEN_HEADER
);
String
gatewayToken
=
new
String
(
Base64Utils
.
encode
(
DataConstant
.
Security
.
TOKENHEADER
.
getVal
()
.
getBytes
()));
String
zuulToken
=
new
String
(
Base64Utils
.
encode
(
DataConstant
.
GATEWAY_TOKEN_VALUE
.
getBytes
()));
// 校验Token的正确性
// 校验
Zuul
Token的正确性
if
(
StrUtil
.
equals
(
gateway
Token
,
token
))
{
if
(
StrUtil
.
equals
(
zuul
Token
,
token
))
{
return
true
;
return
true
;
}
else
{
}
else
{
ResponseUtil
.
makeResponse
(
ResponseUtil
.
makeResponse
(
...
...
datax-common/datax-common-security/src/main/java/cn/datax/common/security/utils/DataUserAuthenticationConverter.java
View file @
ae2cf8b2
...
@@ -42,9 +42,9 @@ public class DataUserAuthenticationConverter implements UserAuthenticationConver
...
@@ -42,9 +42,9 @@ public class DataUserAuthenticationConverter implements UserAuthenticationConver
Object
principal
=
map
.
get
(
USERNAME
);
Object
principal
=
map
.
get
(
USERNAME
);
Collection
<?
extends
GrantedAuthority
>
authorities
=
this
.
getAuthorities
(
map
);
Collection
<?
extends
GrantedAuthority
>
authorities
=
this
.
getAuthorities
(
map
);
String
id
=
(
String
)
map
.
get
(
DataConstant
.
UserAdditionalInfo
.
USERID
.
getKey
()
);
String
id
=
(
String
)
map
.
get
(
DataConstant
.
DETAILS_SECURITY_USER_ID
);
String
username
=
(
String
)
map
.
get
(
DataConstant
.
UserAdditionalInfo
.
USERNAME
.
getKey
()
);
String
username
=
(
String
)
map
.
get
(
DataConstant
.
DETAILS_SECURITY_USERNAME
);
String
nickname
=
(
String
)
map
.
get
(
DataConstant
.
UserAdditionalInfo
.
NICKNAME
.
getKey
()
);
String
nickname
=
(
String
)
map
.
get
(
DataConstant
.
DETAILS_SECURITY_USERNAME
);
DataUser
user
=
new
DataUser
(
id
,
nickname
,
username
,
N_A
,
true
DataUser
user
=
new
DataUser
(
id
,
nickname
,
username
,
N_A
,
true
,
true
,
true
,
true
,
authorities
);
,
true
,
true
,
true
,
authorities
);
return
new
UsernamePasswordAuthenticationToken
(
user
,
N_A
,
authorities
);
return
new
UsernamePasswordAuthenticationToken
(
user
,
N_A
,
authorities
);
...
...
datax-gateway/src/main/java/cn/datax/gateway/filter/DataGatewayRequestFilter.java
View file @
ae2cf8b2
...
@@ -31,9 +31,9 @@ public class DataGatewayRequestFilter implements GlobalFilter {
...
@@ -31,9 +31,9 @@ public class DataGatewayRequestFilter implements GlobalFilter {
printLog
(
exchange
);
printLog
(
exchange
);
byte
[]
token
=
Base64Utils
.
encode
((
DataConstant
.
Security
.
TOKENVALUE
.
getVal
()
).
getBytes
());
byte
[]
token
=
Base64Utils
.
encode
((
DataConstant
.
GATEWAY_TOKEN_VALUE
).
getBytes
());
String
[]
headerValues
=
{
new
String
(
token
)};
String
[]
headerValues
=
{
new
String
(
token
)};
ServerHttpRequest
build
=
request
.
mutate
().
header
(
DataConstant
.
Security
.
TOKENHEADER
.
getVal
()
,
headerValues
).
build
();
ServerHttpRequest
build
=
request
.
mutate
().
header
(
DataConstant
.
GATEWAY_TOKEN_HEADER
,
headerValues
).
build
();
ServerWebExchange
newExchange
=
exchange
.
mutate
().
request
(
build
).
build
();
ServerWebExchange
newExchange
=
exchange
.
mutate
().
request
(
build
).
build
();
return
chain
.
filter
(
newExchange
);
return
chain
.
filter
(
newExchange
);
}
}
...
...
datax-modules/system-service-parent/system-service/src/main/java/cn/datax/service/system/controller/LoginController.java
View file @
ae2cf8b2
...
@@ -24,7 +24,7 @@ public class LoginController extends BaseController {
...
@@ -24,7 +24,7 @@ public class LoginController extends BaseController {
@Autowired
@Autowired
private
TokenStore
tokenStore
;
private
TokenStore
tokenStore
;
@GetMapping
(
"/
user
"
)
@GetMapping
(
"/
token
"
)
public
R
getTokenUser
()
{
public
R
getTokenUser
()
{
DataUser
user
=
SecurityUtil
.
getDataUser
();
DataUser
user
=
SecurityUtil
.
getDataUser
();
return
R
.
ok
().
setData
(
user
);
return
R
.
ok
().
setData
(
user
);
...
...
datax-modules/system-service-parent/system-service/src/main/java/cn/datax/service/system/service/impl/UserServiceImpl.java
View file @
ae2cf8b2
...
@@ -148,7 +148,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
...
@@ -148,7 +148,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
if
(
CollUtil
.
isNotEmpty
(
userVo
.
getRoles
())){
if
(
CollUtil
.
isNotEmpty
(
userVo
.
getRoles
())){
Set
<
String
>
permissions
=
new
HashSet
<>();
Set
<
String
>
permissions
=
new
HashSet
<>();
List
<
String
>
roleIds
=
userVo
.
getRoles
().
stream
()
List
<
String
>
roleIds
=
userVo
.
getRoles
().
stream
()
.
filter
(
roleVo
->
DataConstant
.
EnableState
.
ENABLE
.
getKey
()
==
roleVo
.
getStatus
())
.
filter
(
roleVo
->
DataConstant
.
TRUE
==
roleVo
.
getStatus
())
.
map
(
RoleVo:
:
getId
).
collect
(
Collectors
.
toList
());
.
map
(
RoleVo:
:
getId
).
collect
(
Collectors
.
toList
());
List
<
MenuEntity
>
menuEntitys
=
menuDao
.
selectMenuByRoleIds
(
roleIds
);
List
<
MenuEntity
>
menuEntitys
=
menuDao
.
selectMenuByRoleIds
(
roleIds
);
if
(
CollUtil
.
isNotEmpty
(
menuEntitys
)){
if
(
CollUtil
.
isNotEmpty
(
menuEntitys
)){
...
...
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