~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/web/_auth/digest.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- test-case-name: twisted.web.test.test_httpauth -*-
 
2
# Copyright (c) 2009 Twisted Matrix Laboratories.
 
3
# See LICENSE for details.
 
4
 
 
5
"""
 
6
Implementation of RFC2617: HTTP Digest Authentication
 
7
 
 
8
@see: U{http://www.faqs.org/rfcs/rfc2617.html}
 
9
"""
 
10
 
 
11
from zope.interface import implements
 
12
from twisted.cred import credentials
 
13
from twisted.web.iweb import ICredentialFactory
 
14
 
 
15
class DigestCredentialFactory(object):
 
16
    """
 
17
    Wrapper for L{digest.DigestCredentialFactory} that implements the
 
18
    L{ICredentialFactory} interface.
 
19
    """
 
20
    implements(ICredentialFactory)
 
21
 
 
22
    scheme = 'digest'
 
23
 
 
24
    def __init__(self, algorithm, authenticationRealm):
 
25
        """
 
26
        Create the digest credential factory that this object wraps.
 
27
        """
 
28
        self.digest = credentials.DigestCredentialFactory(algorithm,
 
29
                                                          authenticationRealm)
 
30
 
 
31
 
 
32
    def getChallenge(self, request):
 
33
        """
 
34
        Generate the challenge for use in the WWW-Authenticate header
 
35
 
 
36
        @param request: The L{IRequest} to with access was denied and for the
 
37
            response to which this challenge is being generated.
 
38
 
 
39
        @return: The C{dict} that can be used to generate a WWW-Authenticate
 
40
            header.
 
41
        """
 
42
        return self.digest.getChallenge(request.getClientIP())
 
43
 
 
44
 
 
45
    def decode(self, response, request):
 
46
        """
 
47
        Create a L{twisted.cred.digest.DigestedCredentials} object from the
 
48
        given response and request.
 
49
 
 
50
        @see: L{ICredentialFactory.decode}
 
51
        """
 
52
        return self.digest.decode(response,
 
53
                                  request.method,
 
54
                                  request.getClientIP())