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 Globals
import Acquisition
24 from UserDict
import UserDict
26 # this should be moved from zope.app.authentication to zope.authentication
27 from zope
.app
.authentication
.interfaces
import IAuthenticatorPlugin
28 from zope
.app
.authentication
.principalfolder
import PrincipalInfo
30 from zope
.interface
import implements
, alsoProvides
31 from zope
.publisher
.interfaces
import IRequest
33 FAKE_LOGIN
= 'fakelogin'
34 FAKE_PASSWORD
= 'fakepassword'
35 FAKE_CREDS
= {'login':FAKE_LOGIN
, 'password':FAKE_PASSWORD
}
36 FAKE_REQUEST
= UserDict(FAKE_CREDS
)
37 alsoProvides(FAKE_REQUEST
, IRequest
)
39 AUTHPLUG_NAME
= "Paula: Fake PAU AuthenticatorPlugin - Do not use!"
42 class AuthenticatorPlugin(Acquisition
.Explicit
):
43 """Authenticate a fixed fake user
45 >>> ap = AuthenticatorPlugin()
47 >>> p = ap.authenticateCredentials(None)
52 ... 'login': FAKE_LOGIN,
54 >>> p = ap.authenticateCredentials(credentials)
59 ... 'password': FAKE_PASSWORD,
61 >>> p = ap.authenticateCredentials(credentials)
66 ... 'login': FAKE_LOGIN+'wrong',
67 ... 'password': FAKE_PASSWORD,
69 >>> p = ap.authenticateCredentials(credentials)
73 >>> credentials['login'] = FAKE_LOGIN
74 >>> p = ap.authenticateCredentials(credentials)
75 >>> from zope.app.authentication.interfaces import IPrincipalInfo
76 >>> IPrincipalInfo.providedBy(p)
78 >>> p.id == FAKE_LOGIN
81 >>> credentials['password'] = FAKE_PASSWORD+'wrong'
82 >>> p = ap.authenticateCredentials(credentials)
86 implements(IAuthenticatorPlugin
)
88 def authenticateCredentials(self
, creds
):
90 if not (creds
.has_key('login') and creds
.has_key('password')):
92 except AttributeError:
95 if not (creds
['login'] == FAKE_LOGIN
96 and creds
['password'] == FAKE_PASSWORD
):
101 title
= description
= u
"I am a fake user"
102 return PrincipalInfo( id, login
, title
, description
)
104 def principalInfo(self
, id):
105 if not id == FAKE_LOGIN
:
109 title
= description
= u
"I am a fake user"
110 return PrincipalInfo( id, login
, title
, description
)
113 #XXX: not part of any interface at the moment
114 def addUser(self
, login
, password
):
115 return login
== FAKE_LOGIN
117 def delPrincipal(self
, id):
118 return id == FAKE_LOGIN
120 def allowDeletePrincipal(self
, id):
121 return id == FAKE_LOGIN
123 def allowPasswordSet(self
, id):
124 return id == FAKE_LOGIN
126 def doChangeUser(self
, login
, password
, **kws
):
127 return login
== FAKE_LOGIN
129 def setPropertiesForUser(self
, login
, **props
):
130 return login
== FAKE_LOGIN