zope.authentication

軟件截圖:
zope.authentication
軟件詳細信息:
版本: 4.0.0
上傳日期: 20 Feb 15
許可: 免費
人氣: 22

Rating: nan/5 (Total Votes: 0)

zope.authentication提供了在Zope的框架使用的認證概念的定義。
詳細文檔
退出支持
退出支持是指通過一個簡單的界面ILogout:
 從>>>進口zope.authentication.interfaces ILogout
它具有單一“註銷”的方法。
目前使用ILogout是適應的IAuthentication組件ILogout為了說明這一點,我們將創建一個簡單的註銷實現,適應IAuthentication:
  >>> @adapter(IAuthentication)
  ... @implementer(ILogout)
  ...類SimpleLogout(對象):
  ...
  ...高清__init __(個體經營,AUTH):
  ...通
  ...
  ...高清註銷(個體經營,要求):
  ...打印“用戶已註銷”
  >>> provideAdapter(SimpleLogout)
有所為代表的認證程序:
  >>> @implementer(IAuthentication)
  ...類認證(對象):
  ...通
  >>> AUTH =認證()
要執行退出,我們適應AUTH以ILogout並稱之為“註銷”:
  >>>註銷= ILogout(AUTH)
  >>> logout.logout(TestRequest())
 用戶已註銷
在“NoLogout”適配器
類:
 從>>>進口zope.authentication.logout NoLogout
可以註冊為ILogout用於IAuthentication組件不是否則適應ILogout後備提供商。 NoLogout的退出方法是無操作:
  >>> NoLogout(AUTH).logout(TestRequest())
退出登錄用戶界面
因為有些身份驗證協議不支持正式註銷,這可能無法為用戶註銷,一旦他或她登錄。在這種情況下,這將是不恰當的呈現用戶界面註銷。
由於註銷支持站點配置,Zope提供一個適配器,註冊的時候,表示該站點配置為註銷:
 從>>>進口zope.authentication.logout LogoutSupported
這個類僅僅是作為一個標誌,因為它實現了ILogoutSupported:
 從>>>進口zope.authentication.interfaces ILogoutSupported
  >>> ILogoutSupported.implementedBy(LogoutSupported)
 真
  >>>請求=對象()
  >>> ILogoutSupported.providedBy(LogoutSupported(要求))
 真
主要條款
主要條款是用來支持瀏覽器界面進行搜索主要來源。他們提供訪問令牌和標題的值。主要條款視圖使用驗證工具來獲得主要稱號。讓我們創建一個驗證工具來展示它是如何工作:
  >>>類校長:
  ...高清__init __(自我,身份證,職稱):
  ... self.id,self.title = ID,標題
 從>>>進口zope.interface實施者
 從>>>進口zope.authentication.interfaces IAuthentication
 從>>>進口zope.authentication.interfaces PrincipalLookupError
  >>> @implementer(IAuthentication)
  ...類AuthUtility:
  ......數據= {“吉姆”:“吉姆富爾頓”,“斯蒂芬”:“斯蒂芬·里克特'}
  ...
  ...高清getPrincipal(個體經營,ID):
  ...標題= self.data.get(ID)
  ......如果標題不是無:
  ...回本金(ID,標題)
  ...提高PrincipalLookupError
現在,我們需要安裝驗證程序:
 從>>>進口zope.component provideUtility
  >>> provideUtility(AuthUtility(),IAuthentication)
我們需要的主要來源,使我們可以從它創建一個視圖。
 從>>>進口zope.component getUtility
  >>>類PrincipalSource:
  ...高清__contains __(個體經營,ID):
  ... AUTH = getUtility(IAuthentication)
  ...嘗試:
  ... auth.getPrincipal(ID)
  ......除了PrincipalLookupError:
  ...返回False
  ...其他:
  ...返回True
現在,我們可以創建一個方面的看法:
 從>>>進口zope.authentication.principal PrincipalTerms
  >>>術語= PrincipalTerms(PrincipalSource(),無)
現在,我們可以要求條款查看條款:
  >>>期限= terms.getTerm('斯蒂芬')
  >>> term.title
 “斯蒂芬·里克特”
  >>> term.token
 “c3RlcGhhbg__”
如果我們問了一個不存在的一個術語,我們得到了一個查找錯誤:
  >>> terms.getTerm('鮑勃')
 回溯(最近通話最後一個):
  ...
  LookupError:鮑勃
如果我們有一個道理,我們可以得到它的主要標識。
  >>> terms.getValue('c3RlcGhhbg__“)
 “史蒂芬”

什麼在此版本中是新的

  • 在打破了zope.component.nextutility不適當的測試依賴。
  • (前向兼容zope.component 4.0.0)。
  • 在替換棄用zope.component.adapts使用具有同等zope.component.adapter裝飾。
  • 在替換棄用zope.interface.implements使用具有同等zope.interface.implementer裝飾。
  • 在丟棄的Python 2.4和2.5的支持。

要求

  • 在Python中

顯影劑的其他軟件 Zope Corporation and Contributors

cipher.session
cipher.session

20 Feb 15

zope.exceptions
zope.exceptions

20 Feb 15

zope.schema
zope.schema

14 Apr 15

zope.browserpage
zope.browserpage

20 Feb 15

意見 zope.authentication

評論沒有發現
添加評論
打開圖片!