Package flumotion :: Package common :: Module keycards
[hide private]

Source Code for Module flumotion.common.keycards

  1  # -*- Mode: Python; test-case-name: flumotion.test.test_keycards -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  """ 
 23  serializable keycards used for authentication inside Flumotion 
 24  """ 
 25   
 26  from twisted.cred import credentials as tcredentials 
 27  from twisted.spread import pb 
 28   
 29  from flumotion.twisted import credentials 
 30  from flumotion.twisted.compat import implements 
 31  from flumotion.common import common 
 32   
 33  # state enum values 
 34  REFUSED = 0 
 35  REQUESTING = 1 
 36  AUTHENTICATED = 2 
 37  _statesEnum=['REFUSED', 'REQUESTING', 'AUTHENTICATED'] 
 38   
39 -class Keycard(pb.Copyable, pb.RemoteCopy):
40 """ 41 I am the base class for keycards which together with credentials are 42 a serializable object used in authentication inside Flumotion. 43 """ 44 implements(common.mergeImplements(pb.Copyable, pb.RemoteCopy) + (tcredentials.ICredentials, ))
45 - def __init__(self):
46 self.bouncerName = None # set by requester,decides which bouncer 47 self.requesterId = None # who is requesting auth ? 48 self.avatarId = None # avatarId prefered by requester 49 self.id = None # set by bouncer when authenticated 50 self.duration = 0 # means unlimited 51 self.domain = None # requester can pass this to bouncer 52 self.state = REQUESTING
53
54 - def setDomain(self, domain):
55 """ 56 Set the domain of the requester on the keycard. 57 58 @type domain: string 59 """ 60 self.domain = domain
61
62 - def getData(self):
63 """ 64 Return a dictionary of the viewable data on the keycard that can be 65 used to identify the keycard. 66 It doesn't include sensitive information though. 67 68 Subclasses should override to add additional information. 69 """ 70 return { 71 'id': self.id, 72 'requester': self.requesterId, 73 'domain': self.domain 74 }
75
76 - def __repr__(self):
77 return "<%s for requesterId %r in state %s>" % (self.__class__.__name__, 78 self.requesterId, _statesEnum[self.state])
79
80 -class KeycardGeneric(Keycard, object):
81 pass
82 83 pb.setUnjellyableForClass(KeycardGeneric, KeycardGeneric) 84 # class KeycardUACCP: username, address, crypt password 85 # from UsernameCryptPasswordCrypt 86 87 UCPP = credentials.UsernameCryptPasswordPlaintext
88 -class KeycardUACPP(Keycard, UCPP):
89 """ 90 I am a keycard with a username, plaintext password and IP address. 91 I get authenticated against a crypt password. 92 """ 93 implements(common.mergeImplements(Keycard, UCPP))
94 - def __init__(self, username, password, address):
95 UCPP.__init__(self, username, password) 96 Keycard.__init__(self) 97 self.address = address
98
99 - def getData(self):
100 d = Keycard.getData(self) 101 d['username'] = self.username 102 d['address'] = self.address 103 return d
104
105 - def __repr__(self):
106 return "<%s %s@%s for requesterId %r in state %s>" % ( 107 self.__class__.__name__, self.username, self.address, 108 self.requesterId, _statesEnum[self.state])
109 110 pb.setUnjellyableForClass(KeycardUACPP, KeycardUACPP) 111 112 #: username, address, crypt password 113 # from UsernameCryptPasswordCrypt 114 115 UCPCC = credentials.UsernameCryptPasswordCryptChallenger
116 -class KeycardUACPCC(Keycard, UCPCC):
117 """ 118 I am a keycard with a username and IP address. 119 I get authenticated through challenge/response on a crypt password. 120 """ 121 implements(common.mergeImplements(Keycard, UCPCC))
122 - def __init__(self, username, address):
123 UCPCC.__init__(self, username) 124 Keycard.__init__(self) 125 self.address = address
126
127 - def getData(self):
128 d = Keycard.getData(self) 129 d['username'] = self.username 130 d['address'] = self.address 131 return d
132
133 - def __repr__(self):
134 return "<%s %s@%s for requesterId %r in state %s>" % ( 135 self.__class__.__name__, self.username, self.address, 136 self.requesterId, _statesEnum[self.state])
137 138 pb.setUnjellyableForClass(KeycardUACPCC, KeycardUACPCC) 139
140 -class KeycardToken(Keycard, credentials.Token):
141 """ 142 I am a keycard with a token and IP address. 143 I get authenticated by token and maybe IP address. 144 """ 145 implements(common.mergeImplements(Keycard,credentials.Token)) 146
147 - def __init__(self, token, address):
148 credentials.Token.__init__(self, token) 149 Keycard.__init__(self) 150 self.address = address
151
152 - def getData(self):
153 d = Keycard.getData(self) 154 d['token'] = self.token 155 d['address'] = self.address 156 return d
157
158 - def __repr__(self):
159 return "<%s token %s @%s for requesterId %r in state %s>" % ( 160 self.__class__.__name__, self.token, self.address, 161 self.requesterId, _statesEnum[self.state])
162 163 pb.setUnjellyableForClass(KeycardToken, KeycardToken) 164 165 USPCC = credentials.UsernameSha256PasswordCryptChallenger
166 -class KeycardUASPCC(Keycard, USPCC):
167 """ 168 I am a keycard with a username and IP address. 169 I get authenticated through challenge/response on a SHA-256 password. 170 """ 171 implements(common.mergeImplements(Keycard, USPCC))
172 - def __init__(self, username, address):
173 USPCC.__init__(self, username) 174 Keycard.__init__(self) 175 self.address = address
176
177 - def getData(self):
178 d = Keycard.getData(self) 179 d['username'] = self.username 180 d['address'] = self.address 181 return d
182
183 - def __repr__(self):
184 return "<%s %s@%s for requesterId %r in state %s>" % ( 185 self.__class__.__name__, self.username, self.address, 186 self.requesterId, _statesEnum[self.state])
187 188 pb.setUnjellyableForClass(KeycardUASPCC, KeycardUASPCC) 189