Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
POC
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBizPOC_20003
POC
提交
7587f9e1
提交
7587f9e1
编写于
4年前
作者:
MoneyQ
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新 LoginUserDetailService.java
上级
0d397110
master
无相关合并请求
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
60 行增加
和
14 行删除
+60
-14
LoginUserDetailService.java
.../ibiz/web/security/userdetail/LoginUserDetailService.java
+60
-14
未找到文件。
im-app/im-app-web/src/main/java/com/ibiz/web/security/userdetail/LoginUserDetailService.java
浏览文件 @
7587f9e1
package
com
.
ibiz
.
web
.
security
.
userdetail
;
import
com.ibiz.util.security.userdetail.LoginUser
;
import
org.springframework.data.domain.Page
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
com.ibiz.util.helper.SpringContextHolder
;
import
com.ibiz.util.security.userdetail.LoginUser
;
import
com.ibiz.util.web.AppContextConstants
;
import
com.ibiz.web.r7rt_org.domain.OrgDeptUser
;
import
com.ibiz.web.r7rt_org.domain.OrgUser
;
import
com.ibiz.web.r7rt_org.filter.OrgDeptUserSearchContext
;
import
com.ibiz.web.r7rt_org.filter.OrgUserSearchContext
;
import
com.ibiz.web.r7rt_org.service.OrgDeptUserService
;
import
com.ibiz.web.r7rt_org.service.OrgUserService
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.TimeZone
;
public
class
LoginUserDetailService
implements
UserDetailsService
{
@Override
public
UserDetails
loadUserByUsername
(
String
username
)
throws
UsernameNotFoundException
{
@Override
public
UserDetails
loadUserByUsername
(
String
username
)
throws
UsernameNotFoundException
{
OrgUserService
orgUserService
=
SpringContextHolder
.
getBean
(
OrgUserService
.
class
);
OrgUserSearchContext
orgUserContext
=
new
OrgUserSearchContext
();
orgUserContext
.
set
(
"n_usercode_eq"
,
username
);
Page
<
OrgUser
>
orgUsers
=
orgUserService
.
fetchDefault
(
orgUserContext
);
if
(!
orgUsers
.
hasContent
())
{
throw
new
RuntimeException
(
"无法获取组织用户"
);
}
// 获取组织人员信息
OrgUser
orgUser
=
orgUsers
.
getContent
().
get
(
0
);
List
<
SimpleGrantedAuthority
>
authorities
=
new
ArrayList
<
SimpleGrantedAuthority
>();
BCryptPasswordEncoder
passwordEncoder
=
new
BCryptPasswordEncoder
();
LoginUser
user
=
new
LoginUser
(
username
,
passwordEncoder
.
encode
(
"123456"
),
authorities
);
user
.
setPersonId
(
orgUser
.
getOrgUserId
());
user
.
setOrgUserId
(
orgUser
.
getOrgUserId
());
user
.
setOrgUserName
(
orgUser
.
getOrgUserName
());
user
.
setOrgId
(
orgUser
.
getOrgId
());
user
.
setOrgName
(
orgUser
.
getOrgName
());
user
.
setUserMode
(
"default"
);
user
.
setTimeZone
(
TimeZone
.
getDefault
());
user
.
setLocale
(
Locale
.
CHINESE
);
user
.
setSuperUser
(
false
);
List
<
SimpleGrantedAuthority
>
authorities
=
new
ArrayList
<
SimpleGrantedAuthority
>()
;
SimpleGrantedAuthority
userAuthority
=
new
SimpleGrantedAuthority
(
"USER"
);
authorities
.
add
(
userAuthority
);
if
(
username
.
equals
(
"admin"
)){
SimpleGrantedAuthority
adminAuthority
=
new
SimpleGrantedAuthority
(
"ADMIN"
);
authorities
.
add
(
adminAuthority
);
}
BCryptPasswordEncoder
passwordEncoder
=
new
BCryptPasswordEncoder
()
;
LoginUser
user
=
new
LoginUser
(
username
,
passwordEncoder
.
encode
(
"123456"
),
authorities
)
;
return
user
;
// 获取部门信息
OrgDeptUserService
orgDeptUserService
=
SpringContextHolder
.
getBean
(
OrgDeptUserService
.
class
);
OrgDeptUserSearchContext
orgDeptUserContext
=
new
OrgDeptUserSearchContext
();
orgDeptUserContext
.
set
(
"n_orguserid_eq"
,
orgUser
.
getOrgUserId
());
Page
<
OrgDeptUser
>
orgDeptUsers
=
orgDeptUserService
.
fetchDefault
(
orgDeptUserContext
);
if
(
orgDeptUsers
.
hasContent
())
{
user
.
setOrgDeptId
(
orgDeptUsers
.
getContent
().
get
(
0
).
getOrgDeptId
());
user
.
setOrgDeptName
(
orgDeptUsers
.
getContent
().
get
(
0
).
getOrgDeptName
());
for
(
OrgDeptUser
orgDeptUser
:
orgDeptUsers
)
{
Map
deptInfo
=
new
HashMap
<
String
,
String
>()
;
deptInfo
.
put
(
AppContextConstants
.
CONTEXT_ORGSECTORID
,
orgDeptUser
.
getOrgDeptId
());
deptInfo
.
put
(
AppContextConstants
.
CONTEXT_ORGSECTORNAME
,
orgDeptUser
.
getOrgDeptName
());
user
.
getOrgDepts
().
add
(
deptInfo
)
;
}
}
return
user
;
}
}
}
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录