Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
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
fangxinjiang
yifu-mvp
Commits
cfb9c5a6
Commit
cfb9c5a6
authored
Jan 09, 2023
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
B端&LDAP登录调整
parent
a65eaa6d
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
104 additions
and
15 deletions
+104
-15
YifuTokenEndpoint.java
...u/cloud/plus/v1/yifu/auth/endpoint/YifuTokenEndpoint.java
+2
-1
YifuUser.java
.../com/yifu/cloud/plus/v1/yifu/common/core/vo/YifuUser.java
+8
-1
YifuDaoAuthenticationProvider.java
...mon/security/component/YifuDaoAuthenticationProvider.java
+2
-1
YifuUserDetailsService.java
.../yifu/common/security/service/YifuUserDetailsService.java
+11
-5
YifuUserDetailsServiceImpl.java
...u/common/security/service/YifuUserDetailsServiceImpl.java
+19
-1
application-dev.yml
yifu-job/yifu-job-biz/src/main/resources/application-dev.yml
+3
-0
application-test.yml
...-job/yifu-job-biz/src/main/resources/application-test.yml
+3
-0
SysUser.java
...com/yifu.cloud.plus.v1/yifu/admin/api/entity/SysUser.java
+7
-0
UserVO.java
...java/com/yifu.cloud.plus.v1/yifu/admin/api/vo/UserVO.java
+7
-0
UserController.java
...u/cloud/plus/v1/yifu/admin/controller/UserController.java
+8
-1
SysUserService.java
...yifu/cloud/plus/v1/yifu/admin/service/SysUserService.java
+8
-0
SysUserServiceImpl.java
...d/plus/v1/yifu/admin/service/impl/SysUserServiceImpl.java
+22
-5
SysUserMapper.xml
...yifu-upms-biz/src/main/resources/mapper/SysUserMapper.xml
+4
-0
No files found.
yifu-auth/src/main/java/com/yifu/cloud/plus/v1/yifu/auth/endpoint/YifuTokenEndpoint.java
View file @
cfb9c5a6
...
...
@@ -116,7 +116,8 @@ public class YifuTokenEndpoint {
user
.
getPhone
(),
true
,
true
,
true
,
CommonConstants
.
STATUS_NORMAL
.
equals
(
user
.
getLockFlag
()),
user
.
getUserGroup
(),
authorities
,
user
.
getLdapDn
(),
info
.
getClientRoleMap
(),
info
.
getSettleIdList
());
info
.
getClientRoleMap
(),
info
.
getSettleIdList
(),
user
.
getType
());
thisUser
.
setClientRoleMap
(
info
.
getClientRoleMap
());
return
thisUser
;
}
...
...
yifu-common/yifu-common-core/src/main/java/com/yifu/cloud/plus/v1/yifu/common/core/vo/YifuUser.java
View file @
cfb9c5a6
...
...
@@ -92,13 +92,19 @@ public class YifuUser extends User {
@Getter
@Setter
private
List
<
String
>
settleIdList
;
/**
* @Author fxj
* @Description 员工类型
**/
@Getter
private
String
type
;
public
YifuUser
(
String
id
,
Long
deptId
,
String
deptName
,
String
username
,
String
nickname
,
String
systemFlag
,
String
password
,
String
phone
,
boolean
enabled
,
boolean
accountNonExpired
,
boolean
credentialsNonExpired
,
boolean
accountNonLocked
,
String
userGroup
,
Collection
<?
extends
GrantedAuthority
>
authorities
,
String
ldapDn
,
Map
<
String
,
List
<
Long
>>
clientRoleMap
,
List
<
String
>
settleIdList
)
{
List
<
String
>
settleIdList
,
String
type
)
{
super
(
username
,
password
,
enabled
,
accountNonExpired
,
credentialsNonExpired
,
accountNonLocked
,
authorities
);
this
.
id
=
id
;
this
.
deptId
=
deptId
;
...
...
@@ -110,5 +116,6 @@ public class YifuUser extends User {
this
.
ldapDn
=
ldapDn
;
this
.
clientRoleMap
=
clientRoleMap
;
this
.
settleIdList
=
settleIdList
;
this
.
type
=
type
;
}
}
yifu-common/yifu-common-security/src/main/java/com/yifu/cloud/plus/v1/yifu/common/security/component/YifuDaoAuthenticationProvider.java
View file @
cfb9c5a6
...
...
@@ -97,7 +97,8 @@ public class YifuDaoAuthenticationProvider extends AbstractUserDetailsAuthentica
}
try
{
UserDetails
loadedUser
=
optional
.
get
().
loadUserByUsername
(
username
);
//接收到前端传的密码
UserDetails
loadedUser
=
optional
.
get
().
loadUserByUsernameDiy
(
username
,(
String
)
authentication
.
getCredentials
());
if
(
loadedUser
==
null
)
{
throw
new
InternalAuthenticationServiceException
(
"UserDetailsService returned null, which is an interface contract violation"
);
...
...
yifu-common/yifu-common-security/src/main/java/com/yifu/cloud/plus/v1/yifu/common/security/service/YifuUserDetailsService.java
View file @
cfb9c5a6
...
...
@@ -14,6 +14,8 @@ import org.springframework.security.core.authority.AuthorityUtils;
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
org.springframework.security.crypto.password.PasswordEncoder
;
import
java.util.Arrays
;
import
java.util.Collection
;
...
...
@@ -25,7 +27,6 @@ import java.util.Set;
* @date 2021/12/21
*/
public
interface
YifuUserDetailsService
extends
UserDetailsService
,
Ordered
{
/**
* 是否支持此客户端校验
* @param clientId 目标客户端
...
...
@@ -52,7 +53,6 @@ public interface YifuUserDetailsService extends UserDetailsService, Ordered {
if
(
result
==
null
||
result
.
getData
()
==
null
)
{
throw
new
UsernameNotFoundException
(
"用户不存在"
);
}
UserInfo
info
=
result
.
getData
();
Set
<
String
>
dbAuthsSet
=
new
HashSet
<>();
...
...
@@ -63,17 +63,16 @@ public interface YifuUserDetailsService extends UserDetailsService, Ordered {
dbAuthsSet
.
addAll
(
Arrays
.
asList
(
info
.
getPermissions
()));
}
Collection
<?
extends
GrantedAuthority
>
authorities
=
AuthorityUtils
.
createAuthorityList
(
dbAuthsSet
.
toArray
(
new
String
[
0
]));
SysUser
user
=
info
.
getSysUser
();
// 构造security用户
return
new
YifuUser
(
user
.
getUserId
(),
user
.
getDeptId
(),
user
.
getDeptName
(),
user
.
getUsername
(),
user
.
getNickname
(),
user
.
getSystemFlag
(),
SecurityConstants
.
BCRYPT
+
user
.
getPassword
(),
user
.
getPhone
(),
true
,
true
,
true
,
StrUtil
.
equals
(
user
.
getLockFlag
(),
CommonConstants
.
STATUS_NORMAL
),
user
.
getUserGroup
(),
authorities
,
user
.
getLdapDn
(),
info
.
getClientRoleMap
(),
info
.
getSettleIdList
());
user
.
getUserGroup
(),
authorities
,
user
.
getLdapDn
(),
info
.
getClientRoleMap
(),
info
.
getSettleIdList
(),
user
.
getType
());
}
/**
...
...
@@ -85,4 +84,11 @@ public interface YifuUserDetailsService extends UserDetailsService, Ordered {
return
this
.
loadUserByUsername
(
yifuUser
.
getUsername
());
}
/**
* 自定义获取用户信息 兼容 LDAP 或 EKP
*/
default
UserDetails
loadUserByUsernameDiy
(
String
username
,
String
password
)
{
return
this
.
loadUserByUsernameDiy
(
username
,
password
);
}
}
yifu-common/yifu-common-security/src/main/java/com/yifu/cloud/plus/v1/yifu/common/security/service/YifuUserDetailsServiceImpl.java
View file @
cfb9c5a6
...
...
@@ -67,7 +67,25 @@ public class YifuUserDetailsServiceImpl implements YifuUserDetailsService {
}
return
userDetails
;
}
/**
* 用户名密码登录
* @param username 用户名
* @return
*/
@Override
@SneakyThrows
public
UserDetails
loadUserByUsernameDiy
(
String
username
,
String
password
)
{
Cache
cache
=
cacheManager
.
getCache
(
CacheConstants
.
USER_DETAILS
);
if
(
cache
!=
null
&&
cache
.
get
(
username
)
!=
null
)
{
return
(
YifuUser
)
cache
.
get
(
username
).
get
();
}
R
<
UserInfo
>
result
=
HttpDaprUtil
.
invokeMethodGet
(
daprUpmsProperties
.
getAppUrl
(),
daprUpmsProperties
.
getAppId
(),
"/user/getInfoByUsername"
,
"?username="
+
username
+
"&password="
+
password
,
UserInfo
.
class
,
SecurityConstants
.
FROM_IN
);
UserDetails
userDetails
=
getUserDetails
(
result
);
if
(
cache
!=
null
)
{
cache
.
put
(
username
,
userDetails
);
}
return
userDetails
;
}
@Override
public
int
getOrder
()
{
return
Integer
.
MIN_VALUE
;
...
...
yifu-job/yifu-job-biz/src/main/resources/application-dev.yml
View file @
cfb9c5a6
# 数据源配置
spring
:
mvc
:
pathmatch
:
matching-strategy
:
ant_path_matcher
redis
:
host
:
127.0.0.1
password
:
'
@yf_2017'
...
...
yifu-job/yifu-job-biz/src/main/resources/application-test.yml
View file @
cfb9c5a6
# 数据源配置
spring
:
mvc
:
pathmatch
:
matching-strategy
:
ant_path_matcher
redis
:
host
:
192.168.1.65
port
:
22379
...
...
yifu-upms/yifu-upms-api/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/api/entity/SysUser.java
View file @
cfb9c5a6
...
...
@@ -145,4 +145,11 @@ public class SysUser extends BaseEntity {
@Schema
(
description
=
"LDAP_DN"
)
private
String
ldapDn
;
/**
* @Author fxj
* @Description 0 系统用户 1 LDAP用户 2 B端用户 3.微信用户 默认系统用户
* @Date 14:56 2023/1/6
**/
private
String
type
;
}
yifu-upms/yifu-upms-api/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/api/vo/UserVO.java
View file @
cfb9c5a6
...
...
@@ -134,4 +134,11 @@ public class UserVO implements Serializable {
*/
@Schema
(
description
=
"LDAP_DN"
)
private
String
ldapDn
;
/**
* @Author fxj
* @Description 0 系统用户 1 LDAP用户 2 B端用户 3.微信用户 默认系统用户
* @Date 14:56 2023/1/6
**/
private
String
type
;
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/admin/controller/UserController.java
View file @
cfb9c5a6
...
...
@@ -56,6 +56,7 @@ import java.util.Set;
* @date 2019/2/1
*/
@Tag
(
name
=
"用户管理模块"
,
description
=
"用户管理"
)
@Log4j2
@RestController
@RequiredArgsConstructor
@RequestMapping
(
"/user"
)
...
...
@@ -101,10 +102,16 @@ public class UserController {
}
return
R
.
ok
(
userService
.
getUserInfo
(
user
));
}
@SysLog
(
"登录获取账号信息异常"
)
@Inner
@GetMapping
(
"/getInfoByUsername"
)
public
UserInfo
infoAPI
(
@RequestParam
(
required
=
true
,
name
=
"username"
)
String
username
)
{
public
UserInfo
infoAPI
(
@RequestParam
(
required
=
true
,
name
=
"username"
)
String
username
,
@RequestParam
(
required
=
false
,
name
=
"password"
)
String
password
)
{
SysUser
user
=
userService
.
getOne
(
Wrappers
.<
SysUser
>
query
().
lambda
().
eq
(
SysUser:
:
getUsername
,
username
));
if
(
Common
.
isNotNull
(
user
)){
userService
.
ldapLogin
(
username
,
password
,
user
);
}
return
userService
.
getUserInfo
(
user
);
}
...
...
yifu-upms/yifu-upms-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/admin/service/SysUserService.java
View file @
cfb9c5a6
...
...
@@ -169,5 +169,13 @@ public interface SysUserService extends IService<SysUser> {
* @return
*/
Boolean
updateLockFlagById
(
SysUser
user
,
String
lockFlag
);
/**
* @Author fxj
* @Description LDAP用户登录处理
* @Date 14:51 2023/1/9
* @Param
* @return
**/
void
ldapLogin
(
String
username
,
String
password
,
SysUser
user
);
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/admin/service/impl/SysUserServiceImpl.java
View file @
cfb9c5a6
...
...
@@ -42,10 +42,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.enums.MenuTypeEnum
;
import
com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.RedisUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.*
;
import
com.yifu.cloud.plus.v1.yifu.common.dapr.util.ArchivesDaprUtil
;
import
com.yifu.cloud.plus.v1.yifu.common.ldap.entity.PersonVo
;
import
com.yifu.cloud.plus.v1.yifu.common.ldap.util.LdapUtil
;
...
...
@@ -134,6 +131,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/
@Override
public
UserInfo
getUserInfo
(
SysUser
sysUser
)
{
// LDAP用户处理
UserInfo
userInfo
=
new
UserInfo
();
userInfo
.
setSysUser
(
sysUser
);
// 设置角色列表
...
...
@@ -171,7 +169,26 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
userInfo
.
setClientRoleMap
(
clientRoleMap
);
return
userInfo
;
}
/**
* @Author fxj
* @Description LDAP登录验证
* @Date 15:01 2023/1/9
**/
public
void
ldapLogin
(
String
username
,
String
password
,
SysUser
user
){
// 如果是LDAP用户 登录LDAP验证并重置密码为用户的正确密码
if
(
Common
.
isNotNull
(
user
)
&&
CommonConstants
.
ONE_STRING
.
equals
(
user
.
getType
())){
try
{
if
(
ldapUtil
.
authenticate
(
username
,
password
)){
user
.
setPassword
(
ENCODER
.
encode
(
password
));
}
else
{
// 登录失败,随机密码,保证用户密码不一致
user
.
setPassword
(
password
+
RandomUtil
.
getSix
());
}
}
catch
(
Exception
e
)
{
log
.
error
(
"LDAP登录异常"
,
e
);
}
}
}
/**
* 分页查询用户信息(含有角色信息)
* @param page 分页对象
...
...
yifu-upms/yifu-upms-biz/src/main/resources/mapper/SysUserMapper.xml
View file @
cfb9c5a6
...
...
@@ -36,6 +36,7 @@
<result
column=
"post"
property=
"post"
/>
<result
column=
"email"
property=
"email"
/>
<result
column=
"system_flag"
property=
"systemFlag"
/>
<result
column=
"type"
property=
"type"
/>
<collection
property=
"roleList"
ofType=
"com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysRole"
select=
"com.yifu.cloud.plus.v1.yifu.admin.mapper.SysRoleMapper.listRolesByUserId"
column=
"user_id"
>
</collection>
...
...
@@ -60,6 +61,7 @@
<result
column=
"post"
property=
"post"
/>
<result
column=
"email"
property=
"email"
/>
<result
column=
"system_flag"
property=
"systemFlag"
/>
<result
column=
"type"
property=
"type"
/>
<collection
property=
"roleList"
ofType=
"com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysRole"
>
<id
column=
"role_id"
property=
"roleId"
/>
<result
column=
"role_name"
property=
"roleName"
/>
...
...
@@ -158,6 +160,7 @@
sys_user.post,
sys_user.email,
sys_user.system_flag,
sys_user.type,
sys_dept.name AS deptName
FROM sys_user
LEFT JOIN sys_dept ON sys_dept.dept_id = sys_user.dept_id
...
...
@@ -192,6 +195,7 @@
u.user_group,
u.email,
u.system_flag,
u.type
d.name AS deptName
FROM sys_user u
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
...
...
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