pkslow.com 南瓜慢说

  • AllArticles
  • Container
  • Spring
  • Life
  • Cloud
  • Collections
  • About
  • GitHub

  • Search
Terraform101 English Terraform Middleware config Go Private Kubernetes pkslow Test HTTPS Redis Docker Mac Plan Stream MongoDB Spring DevOps JVM String Map Set List Performance Email Springboot JavaCollections ArrayList Java

Spring Cloud Data Flow整合UAA之使用LDAP进行账号管理

Created on: 2021-01-01 | Category: Springboot | 0 | View: 809

1 前言

Spring Cloud Data Flow整合UAA的文章已经写了两篇,之前的方案是把用户信息保存在数据库中;但在许多企业,是使用AD来管理账户信息,本文将讲解如何整合Data Flow和LDAP。

Spring Cloud Data Flow相关文章:

Spring Cloud Data Flow初体验,以Local模式运行

把Spring Cloud Data Flow部署在Kubernetes上,再跑个任务试试

Spring Cloud Data Flow用Shell来操作,方便建立CICD

被Spring坑了一把,查看源码终于解决了DataFlow部署K8s应用的问题

Spring Cloud Data Flow整合Cloudfoundry UAA服务做权限控制

Spring Cloud Data Flow整合UAA使用外置数据库和API接口

2 启动LDAP服务器

2.1 启动服务器

我们使用Apache的开源框架来作为Ldap服务器,引入依赖如下:

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>2.1.0.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>org.apache.directory.server</groupId>
    <artifactId>apacheds-protocol-ldap</artifactId>
    <version>1.5.5</version>
  </dependency>
  <dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-ldap</artifactId>
  </dependency>
</dependencies>

Springboot的启动类如下:

@SpringBootApplication
public class LdapServer {
    public static void main(String[] args) throws Throwable {
        SpringApplication.run(LdapServer.class, args);
    }

    @Bean
    public ApacheDSContainer apacheDSContainer() throws Exception {
        final File temporaryFolder = Files.createTempDirectory("ldap_server").toFile();
        final String ldapFileName = "testUsers.ldif";

        ApacheDSContainer apacheDSContainer = new ApacheDSContainer("dc=springframework,dc=org",
                "classpath:" + ldapFileName);

        apacheDSContainer.setPort(40000);
        final File workingDir = new File(temporaryFolder, UUID.randomUUID().toString());
        apacheDSContainer.setWorkingDirectory(workingDir);
        return apacheDSContainer;
    }
}

启动端口为40000,用户配置信息ldif文件为testUsers.ldif,我们把测试使用到的AD账户和群组信息都配置在这个文件里。dc=springframework,dc=org是AD的根目录,所有配置信息树的起点。

testUsers.ldif比较大,请参考:https://github.com/LarryDpk/pkslow-samples/blob/master/spring-cloud/ldap-server/src/main/resources/testUsers.ldif 。

2.2 连接服务器

启动了Ldap服务器后,我们可以通过Apache Directory Studio客户端工具来进行查看和管理。如下图所示:

3 UAA配置

UAA服务器需要配置相关信息以连接Ldap服务,配置在uaa.yml文件中,具体添加的配置如下:

spring_profiles: default,postgresql,ldap

ldap:
  profile:
    file: ldap/ldap-search-and-bind.xml
  base:
    url: 'ldap://localhost:40000/'
    userDn: 'uid=leah,ou=people,dc=springframework,dc=org'
    password: 'leahberlin'
    searchBase: 'ou=otherpeople,dc=springframework,dc=org'
    searchFilter: 'uid={0}'
    referral: follow
  groups:
    file: 'ldap/ldap-groups-map-to-scopes.xml'
    searchBase: 'ou=groups,dc=springframework,dc=org'
    searchSubtree: true
    groupSearchFilter: member={0}
    maxSearchDepth: 10
    autoAdd: true

profiles需要添加ldap来打开这个功能。

添加配置后,重启UAA服务器即可生效。但我们现在可以通过用户的登陆信息获取他的AD群组,但这个群组与UAA的群组是不一样的,需要为它们建立一个映射关系。即:

AD group --> UAA group --> Data Flow Role。

这个映射关系的后半部分之前讲解了,前半部分通过uaac或Rest API可以配置,如下:

uaac group map "cn=view,ou=groups,dc=springframework,dc=org" --name="dataflow.view" --origin=ldap
uaac group map "cn=create,ou=groups,dc=springframework,dc=org" --name="dataflow.create" --origin=ldap
uaac group map "cn=manage,ou=groups,dc=springframework,dc=org" --name="dataflow.manage" --origin=ldap

4 登陆测试

我们直接用ldif文件配置的用户marlene/supersecret登陆如下:

实际上,我们依旧可以使用保存在数据库中账号(如larry/larry)登陆,它们是可以并存的,提供了很大的便利性。

5 总结

本文讲解了Data Flow与LDAP的整合,至此,在Spring Cloud Data Flow的鉴权方面,已经讲述比较完整了。

代码请查看:https://github.com/LarryDpk/pkslow-samples


参考文档:

security-ldap-uaa-example

OpenLDAP 概念与工作原理介绍


Code for all: GitHub

欢迎关注微信公众号<南瓜慢说>,将持续为你更新...

file

Recommendations:
Cloud Native
Terraform
Container: Docker/Kubernetes
Spring Boot / Spring Cloud
Https
如何制定切实可行的计划并好好执行

  • Author 作者: LarryDpk 南瓜慢说
  • Link 链接: https://www.pkslow.com/archives/spring-cloud-dataflow-uaa-ldap
  • 版权声明: 本博客所有文章除特别声明外,不可转载!
# Terraform101 # English # Terraform # Middleware # config # Go # Private # Kubernetes # pkslow # Test # HTTPS # Redis # Docker # Mac # Plan # Stream # MongoDB # Spring # DevOps # JVM # String # Map # Set # List # Performance # Email # Springboot # JavaCollections # ArrayList # Java
Terraform101 English Terraform Middleware config Go Private Kubernetes pkslow Test HTTPS Redis Docker Mac Plan Stream MongoDB Spring DevOps JVM String Map Set List Performance Email Springboot JavaCollections ArrayList Java
Springboot整合Swagger
Docker启动PostgreSQL时创建多个数据库
  • Contents
  • Site Overview
南瓜慢说

南瓜慢说

多年Java开发,主要专注后端技术:Java/Spring/Springboot/微服务/大数据等。

多读书,多分享;多写作,多整理。

241 Posts
9 Categories
30 Tags
RSS
0%
© 2020 — 2022 南瓜慢说 pkslow The WebSite keeping alive:   粤ICP备20036375号