1 # Copyright (c) 2008 by Florian Friesdorf
3 # GNU Affero General Public License (AGPL)
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation; either version 3 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public
16 # License along with this program. If not, see
17 # <http://www.gnu.org/licenses/>.
20 __author__
= "Florian Friesdorf <flo@chaoflow.net>"
21 __docformat__
= "plaintext"
23 from zope
.component
import adapts
24 from zope
.interface
import alsoProvides
, implements
, Interface
25 from zope
.interface
import providedBy
27 from paula
.authentication
.interfaces
import IAuthProvider
29 from paula
.grouputil
.interfaces
import IMembershipProvider
31 from paula
.properties
.interfaces
import IPropertyProvider
32 from paula
.properties
.interfaces
import IPropertyInterface
34 from paula
.examples
.interfaces
import IBasicUser
35 from paula
.examples
.interfaces
import IBasicGroup
38 class AuthProviderFromBasicUser(object):
39 """Basically a read-only wrapper demonstrating the concept
41 >>> content = Mock(title='user', password='correct')
42 >>> adapter = AuthProviderFromBasicUser(content)
43 >>> adapter.id == content.title
45 >>> adapter.validate(login='foo', password='correct')
47 >>> adapter.validate(login='foo', password='wrong')
51 implements(IAuthProvider
)
55 return self
.context
.title
57 def __init__(self
, context
):
58 self
.context
= context
60 def validate(self
, login
=u
"", password
=u
""):
61 return password
== self
.context
.password
64 class BasicPropertyProvider(object):
65 """This provides the same IPropertyInterface-providing interfaces as the
66 adpated context provides, and all attributes not defined on self,
67 are passed on to the context.
69 >>> from zope.interface import alsoProvides, Attribute
76 >>> class IA(Interface):
77 ... email = Attribute('email')
79 >>> alsoProvides(content, IA)
80 >>> alsoProvides(IA, IPropertyInterface)
82 >>> adapter = BasicPropertyProvider(content)
83 >>> adapter.id == content.title
85 >>> adapter.email == content.email
87 >>> getattr(adapter, 'password', 'foo')
89 >>> IPropertyProvider.providedBy(adapter)
91 >>> IA.providedBy(adapter)
95 implements(IPropertyProvider
)
99 return self
.context
.title
101 def __init__(self
, context
):
105 IPropertyInterface
.providedBy
,
106 list(providedBy(context
)),
108 alsoProvides(self
, propifs
)
109 self
.context
= context
111 def __getattr__(self
, name
):
113 for x
in list(providedBy(self
)):
115 if name
not in props
:
117 return getattr(self
.context
, name
)
120 class MembershipProviderFromBasicGroup(object):
124 implements(IMembershipProvider
)
126 def __init__(self
, context
):
127 self
.context
= context
131 return (self
.context
.title
,)
135 return tuple(self
.context
.members
)