# Shiro 授權
原文鏈接 : [http://zeppelin.apache.org/docs/0.7.2/security/shiroauthentication.html](http://zeppelin.apache.org/docs/0.7.2/security/shiroauthentication.html)
譯文鏈接 : [http://www.apache.wiki/pages/viewpage.action?pageId=10030709](http://www.apache.wiki/pages/viewpage.action?pageId=10030709)
貢獻者 : [小瑤](/display/~chenyao) [ApacheCN](/display/~apachecn) [Apache中文網](/display/~apachechina)
## 概觀
**[Apache Shiro](http://shiro.apache.org/)**?是一個功能強大且易于使用的 **Java** 安全框架,可執行身份驗證,授權,加密和會話管理。在本文檔中,我們將逐步介紹 **Shiro** 如何用于 **Zeppelin** **notebook authentication** ( 筆記本驗證?)。
當您連接到 **Apache Zeppelin** 時,系統將要求您輸入憑據。登錄后,您可以訪問包括其他用戶注釋在內的所有備注。
## 安全設置
您可以通過一些簡單的步驟設置?**Zeppelin notebook authentication**?。
### 1.啟用 Shiro
默認情況下是在 **conf** ,你將會找到?**shiro.ini.template** ,以此文件為例,強烈建議您通過執行以下命令創建文件 **shiro.ini**
```
cp conf/shiro.ini.template conf/shiro.ini
```
有關 **shiro.ini** 文件格式的更多信息?,請參閱?[Shiro配置](http://shiro.apache.org/configuration.html#Configuration-INISections)?。
### 2.Secure the Websocket channel ( 固定 WebSocket 通道 )
在?**conf/zeppelin-site.xml** 中設置屬性?**zeppelin.anonymous.allowed** 為 **false** 。如果您還沒有這個文件,只需將**?conf/zeppelin-site.xml.template** 復制到?**conf/zeppelin-site.xml** 。
### 3.啟動 Zeppelin
```
bin/zeppelin-daemon.sh start (or restart)
```
然后你可以瀏覽 **Zeppelin** 在?[http://localhost:8080](http://localhost:8080)?。
### 4.登錄
最后,您可以使用以下 用戶名/密碼 組合之一進行登錄。

```
[users]
admin = password1, admin
user1 = password2, role1, role2
user2 = password3, role3
user3 = password4, role2
```
你可以為密碼旁邊的每個用戶設置角色。
## Groups and permissions (optional) ( 組和權限(可選) )
如果要利用用戶組和權限,請在 **shiro.ini** 中的 **[main]** 段下使用 **LDAP** 或 **AD** 的以下配置之一。
```
activeDirectoryRealm = org.apache.zeppelin.realm.ActiveDirectoryGroupRealm
activeDirectoryRealm.systemUsername = userNameA
activeDirectoryRealm.systemPassword = passwordA
activeDirectoryRealm.searchBase = CN=Users,DC=SOME_GROUP,DC=COMPANY,DC=COM
activeDirectoryRealm.url = ldap://ldap.test.com:389
activeDirectoryRealm.groupRolesMap = "CN=aGroupName,OU=groups,DC=SOME_GROUP,DC=COMPANY,DC=COM":"group1"
activeDirectoryRealm.authorizationCachingEnabled = false
ldapRealm = org.apache.zeppelin.server.LdapGroupRealm
# search base for ldap groups (only relevant for LdapGroupRealm):
ldapRealm.contextFactory.environment[ldap.searchBase] = dc=COMPANY,dc=COM
ldapRealm.contextFactory.url = ldap://ldap.test.com:389
ldapRealm.userDnTemplate = uid={0},ou=Users,dc=COMPANY,dc=COM
ldapRealm.contextFactory.authenticationMechanism = SIMPLE
```
還要定義系統中要擁有的角色/組,如下所示;
```
[roles]
admin = *
hr = *
finance = *
group1 = *
```
## Configure Realm (optional) ( 配置領域(可選) )
領域負責 **Apache Zeppelin** 的身份驗證和授權。默認情況下,**Apache Zeppelin** 使用?**[IniRealm](https://shiro.apache.org/static/latest/apidocs/org/apache/shiro/realm/text/IniRealm.html)**?(用戶和組可配置在?**conf/shiro.ini**?文件**?[user]?**和**?[group]**?部分)。您還可以利用 **Shiro Realms** ,如?**[JndiLdapRealm](https://shiro.apache.org/static/latest/apidocs/org/apache/shiro/realm/ldap/JndiLdapRealm.html)**?,**?[JdbcRealm](https://shiro.apache.org/static/latest/apidocs/org/apache/shiro/realm/jdbc/JdbcRealm.html)?**或創建?[我們自己的](https://shiro.apache.org/static/latest/apidocs/org/apache/shiro/realm/AuthorizingRealm.html)?。要了解有關 **Apache Shiro** 領域的更多信息,請查看?[此文檔](http://shiro.apache.org/realm.html)。
我們還提供社區自定義領域。
### 活動目錄
```
activeDirectoryRealm = org.apache.zeppelin.realm.ActiveDirectoryGroupRealm
activeDirectoryRealm.systemUsername = userNameA
activeDirectoryRealm.systemPassword = passwordA
activeDirectoryRealm.hadoopSecurityCredentialPath = jceks://file/user/zeppelin/conf/zeppelin.jceks
activeDirectoryRealm.searchBase = CN=Users,DC=SOME_GROUP,DC=COMPANY,DC=COM
activeDirectoryRealm.url = ldap://ldap.test.com:389
activeDirectoryRealm.groupRolesMap = "CN=aGroupName,OU=groups,DC=SOME_GROUP,DC=COMPANY,DC=COM":"group1"
activeDirectoryRealm.authorizationCachingEnabled = false
```
而不是在 **shiro.ini** 管理員的明文中指定 **systemPassword** 管理員可以選擇在 **“hadoop憑據”** 中指定相同。使用 **hadoop** 憑據命令行創建密鑰庫文件,因為 **hadoop commons** 應該在類路徑中?
`hadoop credential create activeDirectoryRealm.systempassword -provider jceks://file/user/zeppelin/conf/zeppelin.jceks`
更改Shiro.ini文件中的以下值,并取消注釋行:
`activeDirectoryRealm.hadoopSecurityCredentialPath = jceks://file/user/zeppelin/conf/zeppelin.jceks`
### LDAP
```
ldapRealm = org.apache.zeppelin.realm.LdapGroupRealm
# search base for ldap groups (only relevant for LdapGroupRealm):
ldapRealm.contextFactory.environment[ldap.searchBase] = dc=COMPANY,dc=COM
ldapRealm.contextFactory.url = ldap://ldap.test.com:389
ldapRealm.userDnTemplate = uid={0},ou=Users,dc=COMPANY,dc=COM
ldapRealm.contextFactory.authenticationMechanism = SIMPLE
```
### PAM
**[PAM](https://en.wikipedia.org/wiki/Pluggable_authentication_module)**?認證支持允許在 **Zeppelin** 正在運行的主機上重用現有的認證模塊。在典型的系統模塊中,每個服務配置例如 **sshd** , **passwd** 等?**/etc/pam.d/?**。您可以重新使用這些服務之一或為 **Zeppelin** 創建自己的服務。激活 **PAM** 認證需要兩個參數:1. **realm**:正在使用的 **Shiro** 域 2\. **service** :配置為使用的服務?**/etc/pam.d/**?。這里的名稱需要與下面的文件名相同?**/etc/pam.d/**
```
[main]
pamRealm=org.apache.zeppelin.realm.PamRealm
pamRealm.service=sshd
```
### ZeppelinHub
**[ZeppelinHub](https://www.zeppelinhub.com/)**?是一種服務,可同步您的 **Apache Zeppelin** 筆記本,并使您輕松協作。
為了使登錄您的 **ZeppelinHub** 證書,應用以下變化`**conf/shiro.ini**?`下?`**[main]**?`節。
```
### A sample for configuring ZeppelinHub Realm
zeppelinHubRealm = org.apache.zeppelin.realm.ZeppelinHubRealm
## Url of ZeppelinHub
zeppelinHubRealm.zeppelinhubUrl = https://www.zeppelinhub.com
securityManager.realms = $zeppelinHubRealm
```
注意
**ZeppelinHub** 沒有被轉交給 **Apache Zeppelin** 項目。
## 保護您的Zeppelin信息(可選)
默認情況下,定義的任何人都**?[users]**?可以在 **Apache Zeppelin**?中共享解釋器設置,憑證和配置信息。有時您可能希望隱藏這些用于您的用例的信息。由于 **Shiro** 提供了基于 **URL** 的安全性,您可以通過在下面的行中注釋或取消注釋來隱藏信息**?conf/shiro.ini**?。
```
[urls]
/api/interpreter/** = authc, roles[admin]
/api/configurations/** = authc, roles[admin]
/api/credential/** = authc, roles[admin]
```
在這種情況下,只有具有 **admin** 角色的角色才能看到解釋器設置,憑據和配置信息。如果要向其他用戶授予此權限,您可以按照在部分中定義的角色[]進行更改**?[users]**?。
注意
所有上述配置都在 **conf/shiro.ini** 文件中定義。
## 其他認證方式
* [使用 **NGINX** 的 **HTTP** 基本認證](http://zeppelin.apache.org/docs/0.7.2/security/authentication.html)
- 快速入門
- 什么是Apache Zeppelin?
- 安裝
- 配置
- 探索Apache Zeppelin UI
- 教程
- 動態表單
- 發表你的段落
- 自定義Zeppelin主頁
- 升級Zeppelin版本
- 從源碼編譯
- 使用Flink和Spark Clusters安裝Zeppelin教程
- 解釋器
- 概述
- 解釋器安裝
- 解釋器依賴管理
- 解釋器的模擬用戶
- 解釋員執行Hook(實驗)
- Alluxio 解釋器
- Beam 解釋器
- BigQuery 解釋器
- Cassandra CQL 解釋器
- Elasticsearch 解釋器
- Flink 解釋器
- Geode/Gemfire OQL 解釋器
- HBase Shell 解釋器
- HDFS文件系統 解釋器
- Hive 解釋器
- Ignite 解釋器
- JDBC通用 解釋器
- Kylin 解釋器
- Lens 解釋器
- Livy 解釋器
- Markdown 解釋器
- Pig 解釋器
- PostgreSQL, HAWQ 解釋器
- Python 2&3解釋器
- R 解釋器
- Scalding 解釋器
- Scio 解釋器
- Shell 解釋器
- Spark 解釋器
- 系統顯示
- 系統基本顯示
- 后端Angular API
- 前端Angular API
- 更多
- 筆記本存儲
- REST API
- 解釋器 API
- 筆記本 API
- 筆記本資源 API
- 配置 API
- 憑據 API
- Helium API
- Security ( 安全 )
- Shiro 授權
- 筆記本 授權
- 數據源 授權
- Helium 授權
- Advanced ( 高級 )
- Zeppelin on Vagrant VM ( Zeppelin 在 Vagrant 虛擬機上 )
- Zeppelin on Spark Cluster Mode( Spark 集群模式下的 Zeppelin )
- Zeppelin on CDH ( Zeppelin 在 CDH 上 )
- Contibute ( 貢獻 )
- Writing a New Interpreter ( 寫一個新的解釋器 )
- Writing a new Visualization (Experimental) ( 編寫新的可視化(實驗) )
- Writing a new Application (Experimental) ( 寫一個新的應用程序( 實驗 ) )
- Contributing to Apache Zeppelin ( Code ) ( 向 Apache Zeppelin 貢獻( 代碼 ) )
- Contributing to Apache Zeppelin ( Website ) ( 向 Apache Zeppelin 貢獻(website) )