Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
apollo
Commits
ccc34763
Unverified
Commit
ccc34763
authored
Aug 20, 2018
by
Jason Song
Committed by
GitHub
Aug 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1380 from nobodyiam/pandalin-ldap
Add ldap support
parents
4ea75826
1da45449
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
413 additions
and
24 deletions
+413
-24
apollo-portal/pom.xml
apollo-portal/pom.xml
+4
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/LdapUserInfo.java
...ctrip/framework/apollo/portal/entity/bo/LdapUserInfo.java
+67
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java
...rk/apollo/portal/spi/configuration/AuthConfiguration.java
+142
-24
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapProperties.java
...ework/apollo/portal/spi/configuration/LdapProperties.java
+120
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java
...rip/framework/apollo/portal/spi/ldap/LdapUserService.java
+80
-0
No files found.
apollo-portal/pom.xml
View file @
ccc34763
...
...
@@ -14,6 +14,10 @@
<github.path>
${project.artifactId}
</github.path>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-ldap
</artifactId>
</dependency>
<dependency>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo-common
</artifactId>
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/LdapUserInfo.java
0 → 100644
View file @
ccc34763
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
entity
.
bo
;
import
org.springframework.ldap.odm.annotations.Attribute
;
import
org.springframework.ldap.odm.annotations.Entry
;
import
org.springframework.ldap.odm.annotations.Id
;
import
javax.naming.Name
;
/**
* @author xm.lin xm.lin@anxincloud.com
* @Description
* @date 18-8-9 下午4:43
*/
@Entry
(
base
=
"cn=Manager"
,
objectClasses
=
{
"inetOrgPerson"
})
public
class
LdapUserInfo
{
@Id
private
Name
id
;
@Attribute
(
name
=
"cn"
)
private
String
username
;
@Attribute
(
name
=
"sn"
)
private
String
realName
;
@Attribute
(
name
=
"userPassword"
)
private
String
userPassword
;
@Attribute
(
name
=
"mail"
)
private
String
mail
;
public
Name
getId
()
{
return
id
;
}
public
void
setId
(
Name
id
)
{
this
.
id
=
id
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getRealName
()
{
return
realName
;
}
public
void
setRealName
(
String
realName
)
{
this
.
realName
=
realName
;
}
public
String
getUserPassword
()
{
return
userPassword
;
}
public
void
setUserPassword
(
String
userPassword
)
{
this
.
userPassword
=
userPassword
;
}
public
String
getMail
()
{
return
mail
;
}
public
void
setMail
(
String
mail
)
{
this
.
mail
=
mail
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java
View file @
ccc34763
This diff is collapsed.
Click to expand it.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapProperties.java
0 → 100644
View file @
ccc34763
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
spi
.
configuration
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.core.env.Environment
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ObjectUtils
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author xm.lin xm.lin@anxincloud.com
* @Description
* @date 18-8-9 下午4:36
*/
@ConfigurationProperties
(
prefix
=
"spring.ldap"
)
public
class
LdapProperties
{
private
static
final
int
DEFAULT_PORT
=
389
;
/**
* LDAP URLs of the server.
*/
private
String
[]
urls
;
/**
* Base suffix from which all operations should originate.
*/
private
String
base
;
/**
* Login username of the server.
*/
private
String
username
;
/**
* Login password of the server.
*/
private
String
password
;
/**
* Whether read-only operations should use an anonymous environment.
*/
private
boolean
anonymousReadOnly
;
/**
* LDAP specification settings.
*/
private
final
Map
<
String
,
String
>
baseEnvironment
=
new
HashMap
<>();
private
String
userDnPatterns
;
public
String
[]
getUrls
()
{
return
this
.
urls
;
}
public
void
setUrls
(
String
[]
urls
)
{
this
.
urls
=
urls
;
}
public
String
getBase
()
{
return
this
.
base
;
}
public
void
setBase
(
String
base
)
{
this
.
base
=
base
;
}
public
String
getUsername
()
{
return
this
.
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
this
.
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
boolean
getAnonymousReadOnly
()
{
return
this
.
anonymousReadOnly
;
}
public
void
setAnonymousReadOnly
(
boolean
anonymousReadOnly
)
{
this
.
anonymousReadOnly
=
anonymousReadOnly
;
}
public
String
getUserDnPatterns
()
{
return
userDnPatterns
;
}
public
void
setUserDnPatterns
(
String
userDnPatterns
)
{
this
.
userDnPatterns
=
userDnPatterns
;
}
public
Map
<
String
,
String
>
getBaseEnvironment
()
{
return
this
.
baseEnvironment
;
}
public
String
[]
determineUrls
(
Environment
environment
)
{
if
(
ObjectUtils
.
isEmpty
(
this
.
urls
))
{
return
new
String
[]{
"ldap://localhost:"
+
determinePort
(
environment
)};
}
return
this
.
urls
;
}
private
int
determinePort
(
Environment
environment
)
{
Assert
.
notNull
(
environment
,
"Environment must not be null"
);
String
localPort
=
environment
.
getProperty
(
"local.ldap.port"
);
if
(
localPort
!=
null
)
{
return
Integer
.
valueOf
(
localPort
);
}
return
DEFAULT_PORT
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java
0 → 100644
View file @
ccc34763
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
spi
.
ldap
;
import
com.ctrip.framework.apollo.portal.entity.bo.LdapUserInfo
;
import
com.ctrip.framework.apollo.portal.entity.bo.UserInfo
;
import
com.ctrip.framework.apollo.portal.spi.UserService
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.Lists
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.ldap.core.LdapTemplate
;
import
org.springframework.ldap.query.ContainerCriteria
;
import
org.springframework.ldap.query.LdapQueryBuilder
;
import
org.springframework.ldap.query.SearchScope
;
import
org.springframework.util.CollectionUtils
;
/**
* @author xm.lin xm.lin@anxincloud.com
* @Description
* @date 18-8-9 下午4:42
*/
public
class
LdapUserService
implements
UserService
{
@Autowired
private
LdapTemplate
ldapTemplate
;
@Override
public
List
<
UserInfo
>
searchUsers
(
String
keyword
,
int
offset
,
int
limit
)
{
List
<
LdapUserInfo
>
ldapUserInfoList
=
null
;
if
(
Strings
.
isNullOrEmpty
(
keyword
))
{
ldapUserInfoList
=
ldapTemplate
.
findAll
(
LdapUserInfo
.
class
);
}
else
{
ContainerCriteria
criteria
=
LdapQueryBuilder
.
query
().
searchScope
(
SearchScope
.
SUBTREE
)
.
where
(
"cn"
).
like
(
keyword
+
"*"
)
.
or
(
"sn"
).
like
(
keyword
+
"*"
);
ldapUserInfoList
=
ldapTemplate
.
find
(
criteria
,
LdapUserInfo
.
class
);
}
return
convertLdapUserToUserInfo
(
ldapUserInfoList
);
}
@Override
public
UserInfo
findByUserId
(
String
userId
)
{
ContainerCriteria
criteria
=
LdapQueryBuilder
.
query
().
where
(
"cn"
).
is
(
userId
);
LdapUserInfo
ldapUser
=
ldapTemplate
.
findOne
(
criteria
,
LdapUserInfo
.
class
);
UserInfo
userInfo
=
new
UserInfo
();
userInfo
.
setUserId
(
ldapUser
.
getUsername
());
userInfo
.
setName
(
ldapUser
.
getRealName
());
userInfo
.
setEmail
(
ldapUser
.
getMail
());
return
userInfo
;
}
@Override
public
List
<
UserInfo
>
findByUserIds
(
List
<
String
>
userIds
)
{
if
(!
CollectionUtils
.
isEmpty
(
userIds
))
{
LdapQueryBuilder
ldapQueryBuilder
=
LdapQueryBuilder
.
query
()
.
searchScope
(
SearchScope
.
SUBTREE
);
ContainerCriteria
criteria
=
ldapQueryBuilder
.
where
(
"cn"
).
is
(
userIds
.
get
(
0
));
userIds
.
stream
().
skip
(
1
).
forEach
(
userId
->
{
criteria
.
or
(
"cn"
).
is
(
userId
);
});
List
<
LdapUserInfo
>
ldapUserInfoList
=
ldapTemplate
.
find
(
criteria
,
LdapUserInfo
.
class
);
return
convertLdapUserToUserInfo
(
ldapUserInfoList
);
}
return
null
;
}
private
List
<
UserInfo
>
convertLdapUserToUserInfo
(
List
<
LdapUserInfo
>
ldapUserInfoList
)
{
List
<
UserInfo
>
userInfoList
=
Lists
.
newArrayList
();
if
(!
CollectionUtils
.
isEmpty
(
ldapUserInfoList
))
{
ldapUserInfoList
.
stream
().
map
(
p
->
{
UserInfo
userInfo
=
new
UserInfo
();
userInfo
.
setUserId
(
p
.
getUsername
());
userInfo
.
setName
(
p
.
getRealName
());
userInfo
.
setEmail
(
p
.
getMail
());
return
userInfo
;
}).
forEach
(
userInfoList:
:
add
);
}
return
userInfoList
;
}
}
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