[zeppelin]支持多组ldaprealm登录(代码片段)

ESOO ESOO     2022-11-23     394

关键词:

需求:

zeppelin(v:0.8.0) 目前接入了单个邮箱的Ldap验证,公司资源整合之后,需要支持多个邮箱Ldap验证,经研究发现,zeppelin使用的是shiro进行权限验证,shiro配置是支持多组Realm验证,配置上筛选器就可以。

shiro 多Realm

配置解析

zeppelindir/conf/shiro.ini 为zepplin中shiro 配置路径

  • 简单示例:
用户
[users]
#用户zhang的密码是123,此用户具有role1和role2两个角色
zhang=123,role1,role2
wang=123,role2 
#权限
[roles]
#角色role1对资源user拥有create、update权限
role1=user:create,user:update
#角色role2对资源user拥有create、delete权限
role2=user:create,user:delete
#角色role3对资源user拥有create权限
role3=user:create
  • ini配置中主要配置有四大类:main,users,roles,urls
[main]
#提供了对根对象 securityManager 及其依赖的配置
securityManager=org.apache.shiro.mgt.DefaultSecurityManager
…………
securityManager.realms=$jdbcRealm
 
[users]
#提供了对用户/密码及其角色的配置,用户名=密码,角色 1,角色 2
username=password,role1,role2
 
 
[roles]
#提供了角色及权限之间关系的配置,角色=权限 1,权限 2
role1=permission1,permission2
 
 
[urls]
#用于 web,提供了对 web url 拦截相关的配置,url=拦截器[参数],拦截器
/index.html = anon
/admin/** = authc, roles[admin], perms["permission1"]

main主要配置shiro的一些对象,例如securityManager ,Realm,authenticator,authcStrategy 等等,例如

[main]
#声明一个realm  
MyRealm1=com.shiro.mutilrealm.MyRealm1
MyRealm2=com.shiro.mutilrealm.MyRealm2
 
#配置验证器
authenticator = org.apache.shiro.authc.pam.ModularRealmAuthenticator
 
# AllSuccessfulStrategy 表示 MyRealm1和MyRealm2 认证都通过才算通过
#配置策略
#authcStrategy = org.apache.shiro.authc.pam.AllSuccessfulStrategy
authcStrategy = com.shiro.authenticationstrategy.MyAuthenticationStrategy
 
 
#将验证器和策略关联起来
authenticator.authenticationStrategy = $authcStrategy
 
 
#配置验证器所使用的Realm
authenticator.realms=$MyRealm2,$MyRealm1
 
#把Authenticator设置给securityManager
securityManager.authenticator = $authenticator

在这里我们就找到了想要的

配置多Ldap Realm

示例:

[main]
### @ucarinc.com Ldap Realm
ucarRealm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm
ucarRealm.systemUsername = ucarinc\\ldapZeppelin

#use either systemPassword or hadoopSecurityCredentialPath, more details in http://zeppelin.apache.org/docs/latest/security/shiroauthentication.html
ucarRealm.systemPassword = abcd.1234
ucarRealm.searchBase = OU=总部集团,OU=神州优车集团,DC=ucarinc,DC=com
ucarRealm.url = ldap://10.100.20.26:389
ucarRealm.groupRolesMap = "CN=tech_plat_zeppelin_admin,OU=group,OU=邮件组,DC=ucarinc,DC=com":"admin"

### @test1.com Ldap Realm 
zucheRealm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm
zucheRealm.systemUsername = test1@admin.com
zucheRealm.systemPassword = test1PED
zucheRealm.searchBase = ou=Test1,dc=test1,dc=com
zucheRealm.url = ldap://test1host:test1port
zucheRealm.groupRolesMap = "CN=admin,OU=group,DC=test1,DC=com":"admin"

### @test1.com Ldap Realm 
test1Realm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm
test1Realm.systemUsername = test1@admin.com
test1Realm.systemPassword = test1PED
test1Realm.searchBase = ou=Test1,dc=test1,dc=com
test1Realm.url = ldap://test1host:test1port
test1Realm.groupRolesMap = "CN=admin,OU=group,DC=test1,DC=com":"admin"

### @test2.com Ldap Realm 
test2Realm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm
test2Realm.systemUsername = test2@admin.com
test2Realm.systemPassword = test2PED
test2Realm.searchBase = ou=Test2,dc=test2,dc=com
test2Realm.url = ldap://test2host:test2port
test2Realm.groupRolesMap = "CN=admin,OU=group,DC=test2,DC=com":"admin"
#配置验证器
ucarauthenticator = org.apache.shiro.authc.pam.ModularRealmAuthenticator

#配置验证器所使用的Realm
ucarauthenticator.realms=$test1Realm,$test2Realm

#配置策略
ucarauthcStrategy = org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy

#将验证器和策略关联起来
ucarauthenticator.authenticationStrategy = $ucarauthcStrategy

 
#把Authenticator设置给securityManager
securityManager.authenticator = $ucarauthenticator

bug 解决

部署zeppelin 发现,在登录时不对,有错误发生,经排查发现在SecurityUtils.getRoles();

经查询发现,是没有捕获找不到ldaprole错误导致:

改成如下:

public static HashSet<String> getRoles() 
    if (!isEnabled) 
      return EMPTY_HASHSET;
    
    Subject subject = org.apache.shiro.SecurityUtils.getSubject();
    HashSet<String> roles = new HashSet<>();
    Map allRoles = null;

    try 
      if (subject.isAuthenticated()) 
        Collection realmsList = SecurityUtils.getRealmsList();
        for (Iterator<Realm> iterator = realmsList.iterator(); iterator.hasNext(); ) 
          Realm realm = iterator.next();
          String name = realm.getClass().getName();
          if (name.equals("org.apache.shiro.realm.text.IniRealm")) 
            allRoles = ((IniRealm) realm).getIni().get("roles");
            break;
           else if (name.equals("org.apache.zeppelin.realm.LdapRealm")) 
            try 
              AuthorizationInfo auth = ((LdapRealm) realm).queryForAuthorizationInfo(
                      new SimplePrincipalCollection(subject.getPrincipal(), realm.getName()),
                      ((LdapRealm) realm).getContextFactory()
              );
              if (auth != null) 
                roles = new HashSet<>(auth.getRoles());
              
             catch (NamingException e) 
              log.error("Can't fetch roles", e);
            
            break;
           else if (name.equals("org.apache.zeppelin.realm.ActiveDirectoryGroupRealm")) 
            allRoles = ((ActiveDirectoryGroupRealm) realm).getListRoles();
            break;
          
        
        if (allRoles != null) 
          Iterator it = allRoles.entrySet().iterator();
          while (it.hasNext()) 
            Map.Entry pair = (Map.Entry) it.next();
            if (subject.hasRole((String) pair.getKey())) 
              roles.add((String) pair.getKey());
            
          
        
      
     catch (Exception ex)
      log.error("getRoles error: " , ex);
    
    return roles;
  

部署成功!

Zeppelin LDAP 身份验证

...试为Zeppelin启用LDAP身份验证。shiro.ini中的配置如下所示:ldapRealm=org.apache.zeppelin.server.LdapGroupRealmldapRealm.contextFactory.environment[ldap.se 查看详情

从 LDAPRealm 注销 Worklight LDAP 身份验证

】从LDAPRealm注销WorklightLDAP身份验证【英文标题】:WorklightLDAPAuthenticationlogoutfromLDAPRealm【发布时间】:2014-10-3109:54:58【问题描述】:我正在尝试使用IBMWorklightStudio6.2.0.01制作LDAP身份验证系统登录系统工作正常,该部分没有问题,... 查看详情

使用 docker 登录 zeppelin 问题

】使用docker登录zeppelin问题【英文标题】:Logintozeppelinissueswithdocker【发布时间】:2018-03-2223:05:48【问题描述】:我已经下载了许多zeppeling/spark图像,但使用所有这些图像我都无法登录到笔记本电脑。这是容器内的shiro.ini文件:...... 查看详情

zeppelin0.10.0版本配置登录用户

参考技术A这个版本不需要修改zeppelin-site.xml文件只需要mvshiro.ini.templateshiro.ini这个文件vishiro.ini把下面的注释取消#admin=password1,admin重新启动,完活如果java客户端连接,需要调用ZeppelinClient的login方法 查看详情

apachezeppelin入门

参考技术AApacheZeppelin是一款基于Web的NoteBook,支持交互式数据分析。使用Zeppelin,可以使用丰富的预构建语言后端(或解释器)制作精美的数据驱动,交互式和协作文档,例如Scala(使用ApacheSpark),Python(使用ApacheSpark),SparkSQL... 查看详情

每个 Zeppelin 用户的不同虚拟环境

】每个Zeppelin用户的不同虚拟环境【英文标题】:DifferentVirtualEnvironmentsforeachZeppelinuser【发布时间】:2021-12-1411:46:41【问题描述】:我有一个在EMR集群中运行的zeppelin。这个zeppelin有多个用户通过基于Shiro的身份验证方法登录到zeppe... 查看详情

Zeppelin - LDAP 身份验证失败

】Zeppelin-LDAP身份验证失败【英文标题】:Zeppelin-LDAPAuthenticationfailed【发布时间】:2020-04-1418:29:38【问题描述】:我正在尝试在Zeppelin笔记本中配置ldap身份验证。我已经通过this链接指定了ldap服务器和其他配置。但是,当我尝试登... 查看详情

zeppelin学习笔记之zeppelin安装和elasticsearch整合

Zeppelin安装: ApacheZeppelin提供了web版的类似ipython的notebook,用于做数据分析和可视化。背后可以接入不同的数据处理引擎,包括spark,hive,tajo等,原生支持scala,java,shell,markdown等。http://zeppelin.apache.org安装:tar–zxvfzeppelin-0.7.3-bin-... 查看详情

如何设置zeppelin note权限访问控制

】如何设置zeppelinnote权限访问控制【英文标题】:howtosetzeppelinnotepermissionaccesscontrol【发布时间】:2018-03-1905:58:17【问题描述】:我尝试使用LDAP授权方式登录,看起来阅读器可以编辑整个NotePermission应该是只读的。比如我是UserA,... 查看详情

Apache Zeppelin - 如何在 Apache Zeppelin 中使用 Helium 框架

】ApacheZeppelin-如何在ApacheZeppelin中使用Helium框架【英文标题】:ApacheZeppelin-HowtouseHeliumframeworkinApacheZeppelin【发布时间】:2017-11-0416:09:25【问题描述】:从Zeppelin-0.7开始,Zeppelin开始使用Helium框架支持Helium插件/包。但是,我无法在H... 查看详情

Zeppelin, Livy, 我可以得到 proxyUser

】Zeppelin,Livy,我可以得到proxyUser【英文标题】:Zeppelin,Livy,CanIgettheproxyUser【发布时间】:2019-02-2715:58:03【问题描述】:我正在尝试在我的scala(%livy)脚本中获取用于登录Zeppelin的用户ID。我尝试在线搜索并注意到有一个名为“proxyUser... 查看详情

数据分析-zeppelin

参考技术AApacheZeppelin是一个让交互式数据分析变得可行的基于网页的notebook。Zeppelin提供了数据可视化的框架.官网地址:http://zeppelin.apache.org/Zeppelin部署前提是安装了JDK(建议JDK8).安装过程比较简单,部署其应用war包即可.查看其支持... 查看详情

zeppelin部署01zeppelin最新版本zeppelin-0.10.1下载安装配置启动及问题处理(一篇学会部署zeppelin)(代码片段)

1.简单介绍来自百度百科:ApacheZeppelin是一个让交互式数据分析变得可行的基于网页的开源框架。提供了数据分析、数据可视化等功能。是一个提供交互数据分析且基于Web的笔记本。方便你做出可数据驱动的、可交互且可协作... 查看详情

Apache Zeppelin 有智能感知吗?

】ApacheZeppelin有智能感知吗?【英文标题】:DoesApacheZeppelinhaveintellisense?【发布时间】:2015-12-2220:36:11【问题描述】:ApacheZeppelin在其笔记本ui中是否支持智能感知/自动完成?如果是这样,我该如何使用它?我尝试在互联网上搜索... 查看详情

Apache Zeppelin 如何可视化来自 Hbase 的数据?

】ApacheZeppelin如何可视化来自Hbase的数据?【英文标题】:HowdoesApacheZeppelinvisualizedatafromHbase?【发布时间】:2018-12-1510:59:17【问题描述】:由于ApacheZeppelin支持Hbase作为解释器,并且可以可视化任何已识别的后端语言,我想知道是... 查看详情

是否可以使用 spark yarn-cluster 运行 zeppelin

】是否可以使用sparkyarn-cluster运行zeppelin【英文标题】:Isitpossibletorunzeppelinwithsparkyarn-cluster【发布时间】:2016-01-2314:55:17【问题描述】:它与sparkyarn-client一起运行良好,但是yarn-cluster呢?如果可能的话,请分享我们如何做到这一... 查看详情

centos6.5中部署zeppelin并配置账号密码验证

centos6.5中部署Zeppelin并配置账号密码验证1.安装JavaZeppelin支持的操作系统如下图所示。在安装Zeppelin之前,你需要在部署的服务器上安装OracleJDK1.7或以上版本,并配置好相应的JAVA_HOME环境变量。以CentOS为例,具体操作过程如下:a)下... 查看详情

intellijideaultimate家族新成员bigdatatools——集成zeppelin和spark

集成Zeppelin和SparkBigDataTools是IntelliJIDEAUltimate的新插件,是为使用Zeppelin和Spark的数据工程师和其他专业人员所量身定做的一款软件。ZeppelinnotebookswithIntelliJIDEA该插件可在笔记本内部提供智能导航,代码完成,检查和快速修复以及... 查看详情