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 UserDict
import UserDict
25 # this should be moved from zope.app.authentication to zope.authentication
26 from zope
.app
.authentication
.interfaces
import IAuthenticatorPlugin
27 from zope
.app
.authentication
.principalfolder
import PrincipalInfo
29 from zope
.interface
import implements
, alsoProvides
30 from zope
.publisher
.interfaces
import IRequest
32 FAKE_LOGIN
= 'fakelogin'
33 FAKE_PASSWORD
= 'fakepassword'
34 FAKE_CREDS
= {'login':FAKE_LOGIN
, 'password':FAKE_PASSWORD
}
35 FAKE_REQUEST
= UserDict(FAKE_CREDS
)
36 alsoProvides(FAKE_REQUEST
, IRequest
)
38 AUTHPLUG_NAME
= "Paula: Fake PAU AuthenticatorPlugin - Do not use!"
41 class AuthenticatorPlugin(object):
42 """Authenticate a fixed fake user
44 >>> ap = AuthenticatorPlugin()
46 >>> p = ap.authenticateCredentials(None)
51 ... 'login': FAKE_LOGIN,
53 >>> p = ap.authenticateCredentials(credentials)
58 ... 'password': FAKE_PASSWORD,
60 >>> p = ap.authenticateCredentials(credentials)
65 ... 'login': FAKE_LOGIN+'wrong',
66 ... 'password': FAKE_PASSWORD,
68 >>> p = ap.authenticateCredentials(credentials)
72 >>> credentials['login'] = FAKE_LOGIN
73 >>> p = ap.authenticateCredentials(credentials)
74 >>> from zope.app.authentication.interfaces import IPrincipalInfo
75 >>> IPrincipalInfo.providedBy(p)
77 >>> p.id == FAKE_LOGIN
80 >>> credentials['password'] = FAKE_PASSWORD+'wrong'
81 >>> p = ap.authenticateCredentials(credentials)
85 implements(IAuthenticatorPlugin
)
87 def authenticateCredentials(self
, creds
):
89 if not (creds
.has_key('login') and creds
.has_key('password')):
91 except AttributeError:
94 if not (creds
['login'] == FAKE_LOGIN
95 and creds
['password'] == FAKE_PASSWORD
):
100 title
= description
= u
"I am a fake user"
101 return PrincipalInfo( id, login
, title
, description
)
103 def principalInfo(self
, id):
104 if not id == FAKE_LOGIN
:
108 title
= description
= u
"I am a fake user"
109 return PrincipalInfo( id, login
, title
, description
)