def __reginit__(self, login, name, **kw): self.login = login self.name = name self.loaded = False self.s_tokens = ACLTags() self.l_tokens = ACLTags() self.load() self.set_tokens(**kw)
def __reginit__(self, username, **tokens): """ Create a new ClientInfo object, and set the username. @param username: the client's username @type username: str @param **kw: optional context information @type **kw: dict """ self.tokens = ACLTags(tokens) self.username = username self.load()
def __reginit__(self): self.authenticated = False self.authorized = False self.clientdb = ClientDB() self.acldb = ACLDB() # this one is to do operation on sites from the console # or the command line self._sitedb = SiteDB() self.tags = ACLTags()
def get_tags(self, strict=False): tags = ACLTags() if not strict or not self.login: tags.update(self.s_tokens) if not strict or self.login: tags.update(self.l_tokens) if self.login: tags['login'] = self.login tags['name'] = self.name return tags
def get_tags(self): tags = ACLTags() tags.update(self.siteinfo.get_tags()) return tags
def get_tags(self): tags = ACLTags(self.tokens) tags['username'] = self.username return tags
class ClientInfo(Registry): """ A UserInfo holds client context information. """ _class_id = 'ClientInfo' def __reginit__(self, username, **tokens): """ Create a new ClientInfo object, and set the username. @param username: the client's username @type username: str @param **kw: optional context information @type **kw: dict """ self.tokens = ACLTags(tokens) self.username = username self.load() def load(self): pass def save(self): pass def get_token(self, token, default=None): return self.tokens.get(token, default) def set_tokens(self, **tokens): """ Set the authentication or context token of the user. @param **tokens: the tokens to be set. @type **tokens: dict @return: None """ for token, value in tokens.items(): # XXX: how to encrypt the tokens ? encrypt them all ? self.tokens[token] = str(value) def get_tags(self): tags = ACLTags(self.tokens) tags['username'] = self.username return tags def auth_token_order(self): return ('password', ) def authenticate(self, **tokens): """ Authenticate the client with C{**tokens}. @param **tokens: authentication tokens (password, key, ...) @type **tokens: dict @return: True if the client was authenticated, False otherwise. @rtype: bool """ for token in self.auth_token_order(): if token in tokens and tokens[token] is not None: if self.get_token(token) == tokens[token]: return True return False def add_pubkey(self, pubkey, nbkey): ring = self.get_token('pubkey', self.get_token('pkey', '')) if pubkey in ring: return False ring = [k.strip() for k in ring.split('\n') if len(k.strip())] try: nbkey = int(nbkey) if len(ring) >= nbkey: return False except ValueError: # auto_add_key is not an integer, so an infinitie # number of keys is allowed pass ip_addr = self.get_token('ip_addr', 'unknown') ring = '\n'.join(ring + ['%s %s@%s' % (pubkey, self.username, ip_addr)]) self.set_tokens(pubkey=ring) self.save() return True
class ClientInfo(Registry): """ A UserInfo holds client context information. """ _class_id = 'ClientInfo' def __reginit__(self, username, **tokens): """ Create a new ClientInfo object, and set the username. @param username: the client's username @type username: str @param **kw: optional context information @type **kw: dict """ self.tokens = ACLTags(tokens) self.username = username self.load() def load(self): pass def save(self): pass def get_token(self, token, default=None): return self.tokens.get(token, default) def set_tokens(self, **tokens): """ Set the authentication or context token of the user. @param **tokens: the tokens to be set. @type **tokens: dict @return: None """ for token, value in tokens.items(): # XXX: how to encrypt the tokens ? encrypt them all ? self.tokens[token] = str(value) def get_tags(self): tags = ACLTags(self.tokens) tags['username'] = self.username return tags def auth_token_order(self): return ('password',) def authenticate(self, **tokens): """ Authenticate the client with C{**tokens}. @param **tokens: authentication tokens (password, key, ...) @type **tokens: dict @return: True if the client was authenticated, False otherwise. @rtype: bool """ for token in self.auth_token_order(): if token in tokens and tokens[token] is not None: if self.get_token(token) == tokens[token]: return True return False def add_pubkey(self, pubkey, nbkey): ring = self.get_token('pubkey', self.get_token('pkey', '')) if pubkey in ring: return False ring = [ k.strip() for k in ring.split('\n') if len(k.strip()) ] try: nbkey = int(nbkey) if len(ring) >= nbkey: return False except ValueError: # auto_add_key is not an integer, so an infinitie # number of keys is allowed pass ip_addr = self.get_token('ip_addr', 'unknown') ring = '\n'.join(ring + [ '%s %s@%s' % (pubkey, self.username, ip_addr) ]) self.set_tokens(pubkey=ring) self.save() return True