Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pig_冷冷
Pig
提交
033f7603
Pig
项目概览
pig_冷冷
/
Pig
上一次同步 12 个月
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Pig
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
033f7603
编写于
7月 11, 2019
作者:
pig_冷冷
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🐛
Fixing a bug. oauth server 用户ID没有注入,securityutils 不能获取
上级
51f95c7d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
7 deletion
+30
-7
pig-auth/src/main/java/com/pig4cloud/pig/auth/config/AuthorizationServerConfig.java
.../pig4cloud/pig/auth/config/AuthorizationServerConfig.java
+6
-1
pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/constant/SecurityConstants.java
...pig4cloud/pig/common/core/constant/SecurityConstants.java
+20
-0
pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigUserAuthenticationConverter.java
...on/security/component/PigUserAuthenticationConverter.java
+4
-6
未找到文件。
pig-auth/src/main/java/com/pig4cloud/pig/auth/config/AuthorizationServerConfig.java
浏览文件 @
033f7603
...
...
@@ -19,6 +19,7 @@ package com.pig4cloud.pig.auth.config;
import
com.pig4cloud.pig.common.core.constant.SecurityConstants
;
import
com.pig4cloud.pig.common.security.component.PigWebResponseExceptionTranslator
;
import
com.pig4cloud.pig.common.security.service.PigClientDetailsService
;
import
com.pig4cloud.pig.common.security.service.PigUser
;
import
lombok.AllArgsConstructor
;
import
lombok.SneakyThrows
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -95,7 +96,11 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
public
TokenEnhancer
tokenEnhancer
()
{
return
(
accessToken
,
authentication
)
->
{
final
Map
<
String
,
Object
>
additionalInfo
=
new
HashMap
<>(
1
);
additionalInfo
.
put
(
"license"
,
SecurityConstants
.
PROJECT_LICENSE
);
PigUser
pigUser
=
(
PigUser
)
authentication
.
getUserAuthentication
().
getPrincipal
();
additionalInfo
.
put
(
SecurityConstants
.
DETAILS_LICENSE
,
SecurityConstants
.
PROJECT_LICENSE
);
additionalInfo
.
put
(
SecurityConstants
.
DETAILS_USER_ID
,
pigUser
.
getId
());
additionalInfo
.
put
(
SecurityConstants
.
DETAILS_USERNAME
,
pigUser
.
getUsername
());
additionalInfo
.
put
(
SecurityConstants
.
DETAILS_DEPT_ID
,
pigUser
.
getDeptId
());
((
DefaultOAuth2AccessToken
)
accessToken
).
setAdditionalInformation
(
additionalInfo
);
return
accessToken
;
};
...
...
pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/constant/SecurityConstants.java
浏览文件 @
033f7603
...
...
@@ -100,4 +100,24 @@ public interface SecurityConstants {
* 资源服务器默认bean名称
*/
String
RESOURCE_SERVER_CONFIGURER
=
"resourceServerConfigurerAdapter"
;
/**
* 用户ID字段
*/
String
DETAILS_USER_ID
=
"user_id"
;
/**
* 用户名字段
*/
String
DETAILS_USERNAME
=
"username"
;
/**
* 用户部门字段
*/
String
DETAILS_DEPT_ID
=
"dept_id"
;
/**
* 协议字段
*/
String
DETAILS_LICENSE
=
"license"
;
}
pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigUserAuthenticationConverter.java
浏览文件 @
033f7603
...
...
@@ -16,6 +16,7 @@
package
com.pig4cloud.pig.common.security.component
;
import
com.pig4cloud.pig.common.core.constant.SecurityConstants
;
import
com.pig4cloud.pig.common.security.service.PigUser
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.Authentication
;
...
...
@@ -35,9 +36,6 @@ import java.util.Map;
* 根据checktoken 的结果转化用户信息
*/
public
class
PigUserAuthenticationConverter
implements
UserAuthenticationConverter
{
private
static
final
String
USER_ID
=
"user_id"
;
private
static
final
String
DEPT_ID
=
"dept_id"
;
private
static
final
String
TENANT_ID
=
"tenant_id"
;
private
static
final
String
N_A
=
"N/A"
;
/**
...
...
@@ -67,9 +65,9 @@ public class PigUserAuthenticationConverter implements UserAuthenticationConvert
if
(
map
.
containsKey
(
USERNAME
))
{
Collection
<?
extends
GrantedAuthority
>
authorities
=
getAuthorities
(
map
);
String
username
=
(
String
)
map
.
get
(
USERNAME
);
Integer
id
=
(
Integer
)
map
.
get
(
USER_ID
);
Integer
deptId
=
(
Integer
)
map
.
get
(
DEPT_ID
);
String
username
=
(
String
)
map
.
get
(
SecurityConstants
.
DETAILS_
USERNAME
);
Integer
id
=
(
Integer
)
map
.
get
(
SecurityConstants
.
DETAILS_
USER_ID
);
Integer
deptId
=
(
Integer
)
map
.
get
(
SecurityConstants
.
DETAILS_
DEPT_ID
);
PigUser
user
=
new
PigUser
(
id
,
deptId
,
username
,
N_A
,
true
,
true
,
true
,
true
,
authorities
);
return
new
UsernamePasswordAuthenticationToken
(
user
,
N_A
,
authorities
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录