zope.authentication

软件截图:
zope.authentication
软件详细信息:
版本: 4.0.0
上传日期: 20 Feb 15
许可: 免费
人气: 5

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

zope.app.http
zope.app.http

11 May 15

zope.app.testing
zope.app.testing

14 Apr 15

zope.event
zope.event

14 Apr 15

zope.fanstatic
zope.fanstatic

11 May 15

意见 zope.authentication

评论没有发现
添加评论
打开图片!