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
37bf38fa
Commit
37bf38fa
authored
Nov 19, 2019
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目初始化
parent
019ca399
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
111 additions
and
39 deletions
+111
-39
AuthorizationServerConfig.java
.../java/cn/datax/auth/config/AuthorizationServerConfig.java
+4
-4
DataUserDetailService.java
...ain/java/cn/datax/auth/service/DataUserDetailService.java
+2
-3
DataConstant.java
...core/src/main/java/cn/datax/common/core/DataConstant.java
+90
-17
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
file-service.iml
...modules/file-service-parent/file-service/file-service.iml
+0
-0
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 @
37bf38fa
...
...
@@ -118,10 +118,10 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
return
(
accessToken
,
authentication
)
->
{
final
Map
<
String
,
Object
>
additionalInfo
=
new
HashMap
<>();
DataUser
user
=
(
DataUser
)
authentication
.
getUserAuthentication
().
getPrincipal
();
additionalInfo
.
put
(
DataConstant
.
DETAILS_SECURITY_LICENSE
,
"datax"
);
additionalInfo
.
put
(
DataConstant
.
DETAILS_SECURITY_USER_ID
,
user
.
getId
());
additionalInfo
.
put
(
DataConstant
.
DETAILS_SECURITY_USERNAME
,
user
.
getUsername
());
additionalInfo
.
put
(
DataConstant
.
DETAILS_SECURITY_NICKNAME
,
user
.
getNickname
());
additionalInfo
.
put
(
DataConstant
.
UserAdditionalInfo
.
LICENSE
.
getKey
()
,
"datax"
);
additionalInfo
.
put
(
DataConstant
.
UserAdditionalInfo
.
USERID
.
getKey
()
,
user
.
getId
());
additionalInfo
.
put
(
DataConstant
.
UserAdditionalInfo
.
USERNAME
.
getKey
()
,
user
.
getUsername
());
additionalInfo
.
put
(
DataConstant
.
UserAdditionalInfo
.
NICKNAME
.
getKey
()
,
user
.
getNickname
());
((
DefaultOAuth2AccessToken
)
accessToken
).
setAdditionalInformation
(
additionalInfo
);
return
accessToken
;
};
...
...
datax-auth/src/main/java/cn/datax/auth/service/DataUserDetailService.java
View file @
37bf38fa
...
...
@@ -34,7 +34,6 @@ public class DataUserDetailService implements UserDetailsService {
public
UserDetails
loadUserByUsername
(
String
s
)
throws
UsernameNotFoundException
{
//远程获取用户
R
result
=
userServiceFeign
.
loginByUsername
(
s
);
log
.
info
(
JSON
.
toJSONString
(
result
));
if
(
result
==
null
||
ObjectUtil
.
isEmpty
(
result
.
getData
())){
throw
new
UsernameNotFoundException
(
StrUtil
.
format
(
"{}用户不存在"
,
s
));
}
...
...
@@ -54,10 +53,10 @@ public class DataUserDetailService implements UserDetailsService {
UserVo
userVo
=
userInfo
.
getUserVo
();
List
<
RoleVo
>
roles
=
userVo
.
getRoles
();
if
(
CollUtil
.
isNotEmpty
(
roles
))
{
roles
.
stream
().
filter
(
roleVo
->
DataConstant
.
TRUE
==
roleVo
.
getStatus
()
&&
StrUtil
.
isNotBlank
(
roleVo
.
getRoleCode
())).
forEach
(
roleVo
->
authsSet
.
add
(
DataConstant
.
ROLE
+
roleVo
.
getRoleCode
()));
roles
.
stream
().
filter
(
roleVo
->
DataConstant
.
EnableState
.
ENABLE
.
getKey
()
==
roleVo
.
getStatus
()
&&
StrUtil
.
isNotBlank
(
roleVo
.
getRoleCode
())).
forEach
(
roleVo
->
authsSet
.
add
(
DataConstant
.
Security
.
ROLEPREFIX
.
getVal
()
+
roleVo
.
getRoleCode
()));
}
if
(
CollUtil
.
isEmpty
(
authsSet
)){
authsSet
.
add
(
DataConstant
.
ROLE
+
"USE
R"
);
authsSet
.
add
(
DataConstant
.
Security
.
ROLEPREFIX
.
getVal
()
+
"VISITO
R"
);
}
Collection
<?
extends
GrantedAuthority
>
authorities
=
AuthorityUtils
.
createAuthorityList
(
authsSet
.
toArray
(
new
String
[
0
]));
...
...
datax-common/datax-common-core/src/main/java/cn/datax/common/core/DataConstant.java
View file @
37bf38fa
...
...
@@ -3,33 +3,106 @@ package cn.datax.common.core;
public
class
DataConstant
{
/**
*
Gateway请求头TOKEN名称(不要有空格)
*
Oauth2安全相关常量
*/
public
static
final
String
GATEWAY_TOKEN_HEADER
=
"GatewayToken"
;
public
static
enum
Security
{
//请求头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
final
String
GATEWAY_TOKEN_VALUE
=
"datax:gateway:123456"
;
public
static
enum
TrueOrFalse
{
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
final
String
OAUTH2_TOKEN_TYPE
=
"bearer "
;
public
static
enum
UserAdditionalInfo
{
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
static
String
ROLE
=
"ROLE_"
;
public
String
getVal
()
{
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
;
}
public
static
int
FALSE
=
0
;
private
final
Integer
key
;
private
final
String
val
;
public
static
String
DETAILS_SECURITY_LICENSE
=
"license"
;
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
Integer
getKey
()
{
return
key
;
}
public
String
getVal
()
{
return
val
;
}
}
}
datax-common/datax-common-security/src/main/java/cn/datax/common/security/feign/DataFeignRequestInterceptor.java
View file @
37bf38fa
...
...
@@ -16,13 +16,13 @@ public class DataFeignRequestInterceptor {
public
RequestInterceptor
oauth2FeignRequestInterceptor
()
{
return
requestTemplate
->
{
// 请求头中添加 Gateway Token
String
zuulToken
=
new
String
(
Base64Utils
.
encode
(
DataConstant
.
GATEWAY_TOKEN_VALUE
.
getBytes
()));
requestTemplate
.
header
(
DataConstant
.
GATEWAY_TOKEN_HEADER
,
zuulToken
);
String
tokenValue
=
new
String
(
Base64Utils
.
encode
(
DataConstant
.
Security
.
TOKENVALUE
.
getVal
()
.
getBytes
()));
requestTemplate
.
header
(
DataConstant
.
Security
.
TOKENHEADER
.
getVal
(),
tokenValue
);
// 请求头中添加原请求头中的 Token
Object
details
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getDetails
();
if
(
details
instanceof
OAuth2AuthenticationDetails
)
{
String
authorizationToken
=
((
OAuth2AuthenticationDetails
)
details
).
getTokenValue
();
requestTemplate
.
header
(
HttpHeaders
.
AUTHORIZATION
,
DataConstant
.
OAUTH2_TOKEN_TYPE
+
authorizationToken
);
requestTemplate
.
header
(
HttpHeaders
.
AUTHORIZATION
,
DataConstant
.
Security
.
TOKENTYPE
.
getVal
()
+
authorizationToken
);
}
};
}
...
...
datax-common/datax-common-security/src/main/java/cn/datax/common/security/interceptor/DataServerProtectInterceptor.java
View file @
37bf38fa
...
...
@@ -16,11 +16,11 @@ public class DataServerProtectInterceptor implements HandlerInterceptor {
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
IOException
{
// 从请求头中获取
Zuul
Token
String
token
=
request
.
getHeader
(
DataConstant
.
GATEWAY_TOKEN_HEADER
);
String
zuulToken
=
new
String
(
Base64Utils
.
encode
(
DataConstant
.
GATEWAY_TOKEN_VALUE
.
getBytes
()));
// 校验
Zuul
Token的正确性
if
(
StrUtil
.
equals
(
zuul
Token
,
token
))
{
// 从请求头中获取Token
String
token
=
request
.
getHeader
(
DataConstant
.
Security
.
TOKENVALUE
.
getVal
()
);
String
gatewayToken
=
new
String
(
Base64Utils
.
encode
(
DataConstant
.
Security
.
TOKENHEADER
.
getVal
()
.
getBytes
()));
// 校验Token的正确性
if
(
StrUtil
.
equals
(
gateway
Token
,
token
))
{
return
true
;
}
else
{
ResponseUtil
.
makeResponse
(
...
...
datax-common/datax-common-security/src/main/java/cn/datax/common/security/utils/DataUserAuthenticationConverter.java
View file @
37bf38fa
...
...
@@ -42,9 +42,9 @@ public class DataUserAuthenticationConverter implements UserAuthenticationConver
Object
principal
=
map
.
get
(
USERNAME
);
Collection
<?
extends
GrantedAuthority
>
authorities
=
this
.
getAuthorities
(
map
);
String
id
=
(
String
)
map
.
get
(
DataConstant
.
DETAILS_SECURITY_USER_ID
);
String
username
=
(
String
)
map
.
get
(
DataConstant
.
DETAILS_SECURITY_USERNAME
);
String
nickname
=
(
String
)
map
.
get
(
DataConstant
.
DETAILS_SECURITY_USERNAME
);
String
id
=
(
String
)
map
.
get
(
DataConstant
.
UserAdditionalInfo
.
USERID
.
getKey
()
);
String
username
=
(
String
)
map
.
get
(
DataConstant
.
UserAdditionalInfo
.
USERNAME
.
getKey
()
);
String
nickname
=
(
String
)
map
.
get
(
DataConstant
.
UserAdditionalInfo
.
NICKNAME
.
getKey
()
);
DataUser
user
=
new
DataUser
(
id
,
nickname
,
username
,
N_A
,
true
,
true
,
true
,
true
,
authorities
);
return
new
UsernamePasswordAuthenticationToken
(
user
,
N_A
,
authorities
);
...
...
datax-gateway/src/main/java/cn/datax/gateway/filter/DataGatewayRequestFilter.java
View file @
37bf38fa
...
...
@@ -31,9 +31,9 @@ public class DataGatewayRequestFilter implements GlobalFilter {
printLog
(
exchange
);
byte
[]
token
=
Base64Utils
.
encode
((
DataConstant
.
GATEWAY_TOKEN_VALUE
).
getBytes
());
byte
[]
token
=
Base64Utils
.
encode
((
DataConstant
.
Security
.
TOKENVALUE
.
getVal
()
).
getBytes
());
String
[]
headerValues
=
{
new
String
(
token
)};
ServerHttpRequest
build
=
request
.
mutate
().
header
(
DataConstant
.
GATEWAY_TOKEN_HEADER
,
headerValues
).
build
();
ServerHttpRequest
build
=
request
.
mutate
().
header
(
DataConstant
.
Security
.
TOKENHEADER
.
getVal
()
,
headerValues
).
build
();
ServerWebExchange
newExchange
=
exchange
.
mutate
().
request
(
build
).
build
();
return
chain
.
filter
(
newExchange
);
}
...
...
datax-modules/file-service-parent/file-service/file-service.iml
deleted
100644 → 0
View file @
019ca399
This diff is collapsed.
Click to expand it.
datax-modules/system-service-parent/system-service/src/main/java/cn/datax/service/system/controller/LoginController.java
View file @
37bf38fa
...
...
@@ -24,7 +24,7 @@ public class LoginController extends BaseController {
@Autowired
private
TokenStore
tokenStore
;
@GetMapping
(
"/
token
"
)
@GetMapping
(
"/
user
"
)
public
R
getTokenUser
()
{
DataUser
user
=
SecurityUtil
.
getDataUser
();
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 @
37bf38fa
...
...
@@ -148,7 +148,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
if
(
CollUtil
.
isNotEmpty
(
userVo
.
getRoles
())){
Set
<
String
>
permissions
=
new
HashSet
<>();
List
<
String
>
roleIds
=
userVo
.
getRoles
().
stream
()
.
filter
(
roleVo
->
DataConstant
.
TRUE
==
roleVo
.
getStatus
())
.
filter
(
roleVo
->
DataConstant
.
EnableState
.
ENABLE
.
getKey
()
==
roleVo
.
getStatus
())
.
map
(
RoleVo:
:
getId
).
collect
(
Collectors
.
toList
());
List
<
MenuEntity
>
menuEntitys
=
menuDao
.
selectMenuByRoleIds
(
roleIds
);
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