Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增强LDAP用户服务,支持按组查找用户 #1794

Merged
merged 24 commits into from
Feb 13, 2019
Merged

增强LDAP用户服务,支持按组查找用户 #1794

merged 24 commits into from
Feb 13, 2019

Conversation

idefav
Copy link
Contributor

@idefav idefav commented Dec 18, 2018

修改LdapUserService SPI接口实现
新增按照group去查找可用用户

以前的版本只能按照"memberOf"去分组,这个方式在ApacheDS和OpenLdap里面没有,只有Windows的ActiveDirectory可以用,修改之后的版本可以支持按照组去筛选用户

示例配置: application-ldap.yml

spring:
  ldap:
    base: "dc=example,dc=com"
    username: "uid=admin,ou=system" # 配置管理员账号,用于搜索、匹配用户
    password: "password"
    searchFilter: "(uid={0})"  # 用户过滤器,登录的时候用这个过滤器来搜索用户
    urls:
    - "ldap://localhost:10389"

ldap:
  mapping: # 配置 ldap 属性
    objectClass: "inetOrgPerson" # ldap 用户 objectClass 配置
    loginId: "uid" # ldap 用户惟一 id,用来作为登录的 id
    rdn: "cn" # ldap rdn
    userDisplayName: "displayName" # ldap 用户名,用来作为显示名
    email: "mail" # ldap 邮箱属性
  group: # 配置ldap group
    objectClass: "groupOfNames"  # 配置groupClassName
    groupBase: "ou=group" # group search base
    groupSearch: "(&(cn=apollo-admins)(&(member=*)))" # group filter
    groupMembership: "member" # group memberShip

ApacheDS 截图:
image

Apollo Portal 使用截图:
image

image

@codecov-io
Copy link

codecov-io commented Dec 18, 2018

Codecov Report

Merging #1794 into master will decrease coverage by 0.65%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1794      +/-   ##
============================================
- Coverage     50.83%   50.17%   -0.66%     
- Complexity     1978     1979       +1     
============================================
  Files           398      400       +2     
  Lines         12185    12342     +157     
  Branches       1250     1272      +22     
============================================
- Hits           6194     6193       -1     
- Misses         5533     5691     +158     
  Partials        458      458
Impacted Files Coverage Δ Complexity Δ
...portal/spi/configuration/LdapExtendProperties.java 0% <0%> (ø) 0 <0> (?)
...o/portal/spi/ldap/FilterLdapByGroupUserSearch.java 0% <0%> (ø) 0 <0> (?)
...mework/apollo/portal/spi/ldap/LdapUserService.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...lo/portal/spi/configuration/AuthConfiguration.java 5.74% <0%> (-0.36%) 1 <0> (ø)
...mework/apollo/portal/component/PortalSettings.java 65.07% <0%> (-4.77%) 5% <0%> (ø)
.../apollo/internals/RemoteConfigLongPollService.java 80.36% <0%> (+1.22%) 28% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update daa1839...be488cd. Read the comment docs.

@coveralls
Copy link

coveralls commented Dec 18, 2018

Coverage Status

Coverage decreased (-0.7%) to 53.889% when pulling be488cd on idefav:master into daa1839 on ctripcorp:master.

@nobodyiam
Copy link
Member

Looks nice, will take a detaild look soon!

@yanggz01
Copy link

sorry, I want know if it support ldaps?

@nobodyiam
Copy link
Member

@yanggz01 I don't have a ldaps environment, maybe you could do some test?

@nobodyiam
Copy link
Member

@codepiano @pandalin @danshan

几位有空的话也帮忙review一下~

@codepiano
Copy link
Contributor

从我搜到的资料看 OpenLdap 是可以支持的,需要开启 memberOf overlay,apacheDS 有支持的计划,不过两三年了还没加上。换新的实现也可以,只要用户无感知,windows ad 的 case 我可以抽空测试一下

@nobodyiam
Copy link
Member

@codepiano @idefav

我参考了这篇文章在open ldap中开启了memberOf特性,和当前版本的功能是兼容的。

@idefav
Copy link
Contributor Author

idefav commented Jan 21, 2019

@codepiano @idefav

我参考了这篇文章在open ldap中开启了memberOf特性,和当前版本的功能是兼容的。

嗯,OpenLDAP是可以用这个办法开启memberOf属性,但是ApacheDS目前还不能支持memberOf属性;如果用ApacheDS就不能集成到Apollo里面来了

@idefav
Copy link
Contributor Author

idefav commented Jan 21, 2019

@codepiano @idefav

我参考了这篇文章在open ldap中开启了memberOf特性,和当前版本的功能是兼容的。

我这里用了Jenkins、Jfrog Artifactory、Gitlab、SonarQube都是支持group方式和memberOf方式两种,建议还是要把基于group方式的实现加入进来。

@nobodyiam
Copy link
Member

@idefav

多谢反馈~

ApacheDS有比较简单的安装方式吗?另外,当前的PR能支持OpenLDAP吗?功能层面肯定是希望能支持更多的接入方式,不过在代码上希望能尽可能地保持简单和通用~

@idefav
Copy link
Contributor Author

idefav commented Jan 22, 2019

@idefav

多谢反馈~

ApacheDS有比较简单的安装方式吗?另外,当前的PR能支持OpenLDAP吗?功能层面肯定是希望能支持更多的接入方式,不过在代码上希望能尽可能地保持简单和通用~

当前的Group方式是支持OpenLDAP的,其实只要是使用groupOfNames或者groupOfUniqueNames,使用member、uniqueMember属性设置成员(成员要完整的路径,不能是成员ID),应该都是支持的
代码我看看有没有更好的方式去实现,可以优化一下,可以把memberUID的方式也加入进去

ApacheDS Windows安装比较简单,官网下个安装包直接安装就可以了

Linux 下安装

wget http://mirrors.shu.edu.cn/apache//directory/apacheds/dist/2.0.0.AM25/apacheds-2.0.0.AM25-x86_64.rpm
yum install apacheds-2.0.0.AM25-x86_64.rpm
/etc/init.d/apacheds-2.0.0.AM25-default start

安装完成之后安装一个Apache Directory Studio 操作ApacheDS就可以了
image

这里有个文档可以参考:
https://blog.csdn.net/u014315941/article/details/52174740

@nobodyiam
Copy link
Member

@idefav

好的,我后面装一个ApacheDS试试,代码的话还有劳看下是否可以尽可能通用一些~

@idefav
Copy link
Contributor Author

idefav commented Jan 24, 2019

@idefav

好的,我后面装一个ApacheDS试试,代码的话还有劳看下是否可以尽可能通用一些~

@idefav
Copy link
Contributor Author

idefav commented Feb 12, 2019

@nobodyiam 我修改了实现方式,现在支持按照memberUid和member两种方式查找用户,支持OpenLDAP和ApacheDS

@nobodyiam
Copy link
Member

@idefav Thanks! Will take a detailed look soon!

Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nobodyiam nobodyiam merged commit 682de9c into apolloconfig:master Feb 13, 2019
CrackerCat pushed a commit to CrackerCat/apollo-1 that referenced this pull request Jul 31, 2024
enhance ldap user service to support filtering users by group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants