[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pas/ Added
challenger that does not create a challenge when the user is already
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Oct 12 03:56:53 EDT 2004
Log message for revision 27984:
Added challenger that does not create a challenge when the user is already
logged in.
Changed:
U Zope3/trunk/src/zope/app/pas/challengeplugins.zcml
A Zope3/trunk/src/zope/app/pas/generic.py
-=-
Modified: Zope3/trunk/src/zope/app/pas/challengeplugins.zcml
===================================================================
--- Zope3/trunk/src/zope/app/pas/challengeplugins.zcml 2004-10-12 07:55:19 UTC (rev 27983)
+++ Zope3/trunk/src/zope/app/pas/challengeplugins.zcml 2004-10-12 07:56:51 UTC (rev 27984)
@@ -3,23 +3,42 @@
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope">
+ <browser:tool
+ interface=".interfaces.IChallengePlugin"
+ title="PAS Challenge Plugin"
+ description="PAS Challenge Plugin"
+ />
+
<localUtility class=".httpplugins.HTTPBasicAuthChallenger">
<implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable" />
+
+ <require
+ permission="zope.ManageServices"
+ interface=".httpplugins.IHTTPBasicAuthRealm"
+ set_schema=".httpplugins.IHTTPBasicAuthRealm" />
</localUtility>
- <browser:tool
- interface=".interfaces.IChallengePlugin"
- title="PAS Challenge Plugin"
- description="PAS Challenge Plugin"
+ <browser:addMenuItem
+ title="PAS Basic Auth Challenge Plugin"
+ description="A PAS Basic Auth Challenge Plugin"
+ class=".httpplugins.HTTPBasicAuthChallenger"
+ permission="zope.ManageContent"
/>
+
+ <localUtility class=".generic.AlreadyAuthenticatedUserChallenger">
+
+ <implements
+ interface="zope.app.annotation.interfaces.IAttributeAnnotatable" />
+
+ </localUtility>
<browser:addMenuItem
- title="PAS HTTP Basic Auth Challenge Plugin"
- description="A PAS Challenge Plugin"
- class="zope.app.pas.httpplugins.HTTPBasicAuthChallenger"
+ title="PAS Authenticated User Challenge Plugin"
+ description="A PAS Authenticated User Challenge Plugin"
+ class=".generic.AlreadyAuthenticatedUserChallenger"
permission="zope.ManageServices"
/>
Added: Zope3/trunk/src/zope/app/pas/generic.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/generic.py 2004-10-12 07:55:19 UTC (rev 27983)
+++ Zope3/trunk/src/zope/app/pas/generic.py 2004-10-12 07:56:51 UTC (rev 27984)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Generic PAS Plugins
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+from persistent import Persistent
+from zope.interface import implements
+
+from zope.app.container.contained import Contained
+from zope.app.security.interfaces import IUnauthenticatedPrincipal
+
+from interfaces import IChallengePlugin
+
+
+class AlreadyAuthenticatedUserChallenger(Persistent, Contained):
+ """Authenticated User Challenger
+
+ Create no challenge, if the user is already authenticated.
+
+ >>> challenger = AlreadyAuthenticatedUserChallenger()
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> response = request.response
+
+ >>> challenger.challenge(request, response)
+ True
+
+ >>> class Principal(object):
+ ... implements(IUnauthenticatedPrincipal)
+ >>> request._principal = Principal()
+
+ >>> challenger.challenge(request, response) is None
+ True
+ """
+ implements(IChallengePlugin)
+
+ def challenge(self, request, response):
+ if not IUnauthenticatedPrincipal.providedBy(request.principal):
+ return True
+
+ return None
More information about the Zope3-Checkins
mailing list