Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
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
wangpeng
dinky
Commits
3de42d73
Unverified
Commit
3de42d73
authored
Jan 23, 2024
by
gaoyan
Committed by
GitHub
Jan 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Optimized ] Optimized the logic for obtaining users from LDAP (#3050)
Co-authored-by:
gaoyan1998
<
gaoyan1998@users.noreply.github.com
>
parent
e57093b6
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
20 deletions
+30
-20
LdapContext.java
dinky-admin/src/main/java/org/dinky/context/LdapContext.java
+15
-5
LdapController.java
...in/src/main/java/org/dinky/controller/LdapController.java
+1
-0
LdapServiceImpl.java
...src/main/java/org/dinky/service/impl/LdapServiceImpl.java
+4
-3
UserServiceImpl.java
...src/main/java/org/dinky/service/impl/UserServiceImpl.java
+0
-2
SystemConfiguration.java
...c/main/java/org/dinky/data/model/SystemConfiguration.java
+10
-10
No files found.
dinky-admin/src/main/java/org/dinky/context/LdapContext.java
View file @
3de42d73
...
@@ -34,6 +34,9 @@ import org.springframework.ldap.core.ContextMapper;
...
@@ -34,6 +34,9 @@ import org.springframework.ldap.core.ContextMapper;
import
org.springframework.ldap.core.DirContextOperations
;
import
org.springframework.ldap.core.DirContextOperations
;
import
org.springframework.ldap.core.support.LdapContextSource
;
import
org.springframework.ldap.core.support.LdapContextSource
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
public
class
LdapContext
{
public
class
LdapContext
{
private
static
final
SystemConfiguration
configuration
=
SystemConfiguration
.
getInstances
();
private
static
final
SystemConfiguration
configuration
=
SystemConfiguration
.
getInstances
();
...
@@ -65,7 +68,9 @@ public class LdapContext {
...
@@ -65,7 +68,9 @@ public class LdapContext {
return
controls
;
return
controls
;
}
}
/** Context mapper for LDAP user identification. */
/**
* Context mapper for LDAP user identification.
*/
public
static
class
UserContextMapper
implements
ContextMapper
<
LdapUserIdentification
>
{
public
static
class
UserContextMapper
implements
ContextMapper
<
LdapUserIdentification
>
{
/**
/**
...
@@ -81,7 +86,9 @@ public class LdapContext {
...
@@ -81,7 +86,9 @@ public class LdapContext {
}
}
}
}
/** Attributes mapper from LDAP user to Local user. */
/**
* Attributes mapper from LDAP user to Local user.
*/
public
static
class
UserAttributesMapperMapper
implements
AttributesMapper
<
User
>
{
public
static
class
UserAttributesMapperMapper
implements
AttributesMapper
<
User
>
{
/**
/**
...
@@ -98,16 +105,19 @@ public class LdapContext {
...
@@ -98,16 +105,19 @@ public class LdapContext {
Attribute
nicknameAttr
=
Attribute
nicknameAttr
=
attributes
.
get
(
configuration
.
getLdapCastNickname
().
getValue
());
attributes
.
get
(
configuration
.
getLdapCastNickname
().
getValue
());
if
(
usernameAttr
!=
null
&&
nicknameAttr
!=
null
)
{
if
(
usernameAttr
!=
null
)
{
User
user
=
new
User
();
User
user
=
new
User
();
user
.
setUsername
(
usernameAttr
.
get
().
toString
());
user
.
setUsername
(
usernameAttr
.
get
().
toString
());
if
(
nicknameAttr
!=
null
)
{
user
.
setNickname
(
nicknameAttr
.
get
().
toString
());
user
.
setNickname
(
nicknameAttr
.
get
().
toString
());
}
user
.
setUserType
(
UserType
.
LDAP
.
getCode
());
user
.
setUserType
(
UserType
.
LDAP
.
getCode
());
user
.
setEnabled
(
true
);
user
.
setEnabled
(
true
);
return
user
;
return
user
;
}
}
else
{
log
.
error
(
"LDAP user mapping failed, username attribute is null"
);
return
null
;
return
null
;
}
}
}
}
}
}
}
dinky-admin/src/main/java/org/dinky/controller/LdapController.java
View file @
3de42d73
...
@@ -87,6 +87,7 @@ public class LdapController {
...
@@ -87,6 +87,7 @@ public class LdapController {
List
<
User
>
users
=
ldapService
.
listUsers
();
List
<
User
>
users
=
ldapService
.
listUsers
();
List
<
User
>
localUsers
=
userService
.
list
();
List
<
User
>
localUsers
=
userService
.
list
();
// 已经存在的用户不可导入 | Existing users cannot be imported
users
.
stream
()
users
.
stream
()
.
filter
(
ldapUser
->
.
filter
(
ldapUser
->
localUsers
.
stream
().
anyMatch
(
user
->
user
.
getUsername
().
equals
(
ldapUser
.
getUsername
())))
localUsers
.
stream
().
anyMatch
(
user
->
user
.
getUsername
().
equals
(
ldapUser
.
getUsername
())))
...
...
dinky-admin/src/main/java/org/dinky/service/impl/LdapServiceImpl.java
View file @
3de42d73
...
@@ -30,6 +30,7 @@ import org.dinky.service.LdapService;
...
@@ -30,6 +30,7 @@ import org.dinky.service.LdapService;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
javax.naming.directory.Attributes
;
import
javax.naming.directory.Attributes
;
...
@@ -87,10 +88,10 @@ public class LdapServiceImpl implements LdapService {
...
@@ -87,10 +88,10 @@ public class LdapServiceImpl implements LdapService {
// Build the User with cast
// Build the User with cast
User
user
=
new
User
();
User
user
=
new
User
();
user
.
setUsername
(
loginDTO
.
getUsername
());
user
.
setUsername
(
loginDTO
.
getUsername
());
user
.
setNickname
(
attributes
Optional
.
of
(
attributes
.
get
(
configuration
.
getLdapCastNickname
().
getValue
())
.
get
(
configuration
.
getLdapCastNickname
().
getValue
())
.
get
(
)
.
get
()
)
.
toString
(
));
.
ifPresent
(
obj
->
user
.
setNickname
(
obj
.
toString
()
));
return
user
;
return
user
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
if
(
e
instanceof
AuthenticationException
)
{
if
(
e
instanceof
AuthenticationException
)
{
...
...
dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java
View file @
3de42d73
...
@@ -276,7 +276,6 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
...
@@ -276,7 +276,6 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
// User doesn't exist locally
// User doesn't exist locally
// Check if LDAP user autoload is enabled
// Check if LDAP user autoload is enabled
if
(!
SystemConfiguration
.
getInstances
().
getLdapAutoload
().
getValue
())
{
if
(!
SystemConfiguration
.
getInstances
().
getLdapAutoload
().
getValue
())
{
loginLogService
.
saveLoginLog
(
userFromLocal
,
Status
.
USER_NAME_PASSWD_ERROR
);
throw
new
AuthException
(
Status
.
LDAP_USER_AUTOLOAD_FORBAID
);
throw
new
AuthException
(
Status
.
LDAP_USER_AUTOLOAD_FORBAID
);
}
}
...
@@ -285,7 +284,6 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
...
@@ -285,7 +284,6 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
SystemConfiguration
.
getInstances
().
getLdapDefaultTeant
().
getValue
();
SystemConfiguration
.
getInstances
().
getLdapDefaultTeant
().
getValue
();
Tenant
tenant
=
tenantService
.
getTenantByTenantCode
(
defaultTeantCode
);
Tenant
tenant
=
tenantService
.
getTenantByTenantCode
(
defaultTeantCode
);
if
(
Asserts
.
isNull
(
tenant
))
{
if
(
Asserts
.
isNull
(
tenant
))
{
loginLogService
.
saveLoginLog
(
userFromLocal
,
Status
.
LDAP_DEFAULT_TENANT_NOFOUND
);
throw
new
AuthException
(
Status
.
LDAP_DEFAULT_TENANT_NOFOUND
);
throw
new
AuthException
(
Status
.
LDAP_DEFAULT_TENANT_NOFOUND
);
}
}
...
...
dinky-common/src/main/java/org/dinky/data/model/SystemConfiguration.java
View file @
3de42d73
...
@@ -169,6 +169,16 @@ public class SystemConfiguration {
...
@@ -169,6 +169,16 @@ public class SystemConfiguration {
.
defaultValue
(
""
)
.
defaultValue
(
""
)
.
note
(
Status
.
SYS_LDAP_SETTINGS_BASEDN_NOTE
);
.
note
(
Status
.
SYS_LDAP_SETTINGS_BASEDN_NOTE
);
private
final
Configuration
<
String
>
ldapCastUsername
=
key
(
Status
.
SYS_LDAP_SETTINGS_CASTUSERNAME
)
.
stringType
()
.
defaultValue
(
"cn"
)
.
note
(
Status
.
SYS_LDAP_SETTINGS_CASTUSERNAME_NOTE
);
private
final
Configuration
<
String
>
ldapCastNickname
=
key
(
Status
.
SYS_LDAP_SETTINGS_CASTNICKNAME
)
.
stringType
()
.
defaultValue
(
"sn"
)
.
note
(
Status
.
SYS_LDAP_SETTINGS_CASTNICKNAME_NOTE
);
private
final
Configuration
<
String
>
ldapFilter
=
key
(
Status
.
SYS_LDAP_SETTINGS_FILTER
)
private
final
Configuration
<
String
>
ldapFilter
=
key
(
Status
.
SYS_LDAP_SETTINGS_FILTER
)
.
stringType
()
.
stringType
()
.
defaultValue
(
""
)
.
defaultValue
(
""
)
...
@@ -184,16 +194,6 @@ public class SystemConfiguration {
...
@@ -184,16 +194,6 @@ public class SystemConfiguration {
.
defaultValue
(
"DefaultTenant"
)
.
defaultValue
(
"DefaultTenant"
)
.
note
(
Status
.
SYS_LDAP_SETTINGS_DEFAULTTEANT_NOTE
);
.
note
(
Status
.
SYS_LDAP_SETTINGS_DEFAULTTEANT_NOTE
);
private
final
Configuration
<
String
>
ldapCastUsername
=
key
(
Status
.
SYS_LDAP_SETTINGS_CASTUSERNAME
)
.
stringType
()
.
defaultValue
(
"cn"
)
.
note
(
Status
.
SYS_LDAP_SETTINGS_CASTUSERNAME_NOTE
);
private
final
Configuration
<
String
>
ldapCastNickname
=
key
(
Status
.
SYS_LDAP_SETTINGS_CASTNICKNAME
)
.
stringType
()
.
defaultValue
(
"sn"
)
.
note
(
Status
.
SYS_LDAP_SETTINGS_CASTNICKNAME_NOTE
);
private
final
Configuration
<
Boolean
>
ldapEnable
=
key
(
Status
.
SYS_LDAP_SETTINGS_ENABLE
)
private
final
Configuration
<
Boolean
>
ldapEnable
=
key
(
Status
.
SYS_LDAP_SETTINGS_ENABLE
)
.
booleanType
()
.
booleanType
()
.
defaultValue
(
false
)
.
defaultValue
(
false
)
...
...
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