1
# Copyright (c) 2008 Twisted Matrix Laboratories.
2
# See LICENSE for details.
6
from zope.interface import implements
8
from twisted.python import log
9
from twisted.internet import reactor
10
from twisted.web import server, resource, guard
11
from twisted.cred.portal import IRealm, Portal
12
from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
15
class GuardedResource(resource.Resource):
17
A resource which is protected by guard and requires authentication in order
20
def getChild(self, path, request):
24
def render(self, request):
29
class SimpleRealm(object):
31
A realm which gives out L{GuardedResource} instances for authenticated
36
def requestAvatar(self, avatarId, mind, *interfaces):
37
if resource.IResource in interfaces:
38
return resource.IResource, GuardedResource(), lambda: None
39
raise NotImplementedError()
44
log.startLogging(sys.stdout)
45
checkers = [InMemoryUsernamePasswordDatabaseDontUse(joe='blow')]
46
wrapper = guard.HTTPAuthSessionWrapper(
47
Portal(SimpleRealm(), checkers),
48
[guard.DigestCredentialFactory('md5', 'example.com')])
49
reactor.listenTCP(8889, server.Site(
53
if __name__ == '__main__':