首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azkaban的LDAP认证

Azkaban的LDAP认证
EN

Stack Overflow用户
提问于 2015-07-15 00:08:33
回答 2查看 1.2K关注 0票数 2

我们正试图在生产环境中使用LDAP身份验证来设置Azkaban。关于怎么做有什么线索吗?文档表示,可以通过扩展UserManager类来添加插件jar文件。我是azkaban的新手,正在寻找一些示例代码

EN

回答 2

Stack Overflow用户

发布于 2015-08-07 19:07:49

您需要安装一个自定义的“用户管理器”插件。它可以在github:https://github.com/researchgate/azkaban-ldap-usermanager上找到

关于如何配置用户管理器插件的说明可以在github的首页找到。

从本质上讲,你需要:

  1. 下载并构建插件
  2. 将内置的.jar文件复制到Azkaban安装的./extlib目录中
  3. 编辑azkaban.properties文件,指定user.manager.class和许多user.manager.ldap属性。
票数 2
EN

Stack Overflow用户

发布于 2016-10-28 20:02:24

我们还想在azkaban中设置LDAP身份验证,但是第一个答案中提到的开源项目功能非常有限,不允许在建立到LDAP服务器的连接之后启动TLS协商。

我们编写了一个全新的java类来处理以下场景:

  • 不安全地建立LDAP连接(在端口389上)
  • 启动TLS响应和TLS谈判
  • 然后引诱用户凭据。

使用这种方法,我们也不必只为azkaban在LDAP中创建服务用户。

查看示例代码块

代码语言:javascript
复制
@Override
public User getUser(String username, String password) throws UserManagerException {
    if (username == null || username.trim().isEmpty()) {
        throw new UserManagerException("Username is empty.");
    } else if (password == null || password.trim().isEmpty()) {
        throw new UserManagerException("Password is empty.");
    }

    String email = null;
    String groups = null;
    StringBuilder url = new StringBuilder("ldap://").append(ldapHost).append(":").append(ldapPort);

    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url.toString());

    try {
        // Create initial context
        LdapContext ctx = new InitialLdapContext(env, null);
        // Start TLS
        StartTlsResponse tls = (StartTlsResponse) ctx.extendedOperation(new StartTlsRequest());
        SSLSession sess = tls.negotiate();

        // Adding username and password to environment
        StringBuilder sb = new StringBuilder("uid=").append(username).append(",").append(ldapUserBase);
        ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, "simple");
        ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, sb.toString());
        ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);

        // Search the user in a LDAP directory
        final LdapCtx x = (LdapCtx) ctx.lookup(sb.toString());

        // Lookup is successful - creating an Azkaban user
        User user = new User(username);

        // Searching LDAP directory to get email and group
        SearchControls ctls = new SearchControls();
        String[] attributes = { "cn", "memberOf", "mail" };
        ctls.setReturningAttributes(attributes);

        NamingEnumeration<?> answer = ctx.search(ldapUserBase, "(uid=" + username + ")", ctls);

        Boolean isAdmin = false;
        // Search user email and groups
        while (answer.hasMore()) {
            SearchResult rslt = (SearchResult) answer.next();
            Attributes attrs = rslt.getAttributes();
            groups = attrs.get("memberof").toString().split(":")[1].trim();
            if (attrs.get("memberof") != null && attrs.get("memberof").toString().split(":").length > 0) {
                groups = attrs.get("memberof").toString().split(":")[1].trim();
                for (String group : groups.split(",")) {
                    if (ldapAdminGroups.contains(group))
                        isAdmin = true;
                }
            }
            if (attrs.get("mail") != null) {
                email = attrs.get("mail").toString().split(":")[1].trim();
                user.setEmail(email);
            }
        }

        // Assign the correct role
        if (isAdmin)
            user.addRole("admin");
        else
            user.addRole("read");
        ctx.close();
        return user;
    } catch (NamingException e) {
        throw new UserManagerException("LDAP error: " + e.getMessage(), e);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        throw new UserManagerException("IO error", e);
    }
}

注意:我在这方面没有做过很多异常处理--你需要根据你的需要去做。

如何让它在阿兹卡班发挥作用:

  • 构建一个maven或gradle项目。
  • 不需要额外的库(除了Azkaban -即com.linkedin.azkaban)
  • 拥有一个继承“azkaban.user.UserManager”的新类
  • 在azkaban/extlib中构建和复制jar
  • 在azkaban.properties - set "user.manager.class=“和所有必需的属性,如主机,端口和ldap用户名(ou=Users,dc=stackoverflow,dc=com)详细信息。

您应该很好地通过LDAP对用户进行身份验证。

编码愉快!!

谢谢,Hussain Bohra

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31419418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档