Package entropy :: Package services :: Module authenticators

Source Code for Module entropy.services.authenticators

  1  # -*- coding: utf-8 -*- 
  2  """ 
  3   
  4      @author: Fabio Erculiani <lxnay@sabayonlinux.org> 
  5      @contact: lxnay@sabayonlinux.org 
  6      @copyright: Fabio Erculiani 
  7      @license: GPL-2 
  8   
  9      B{Entropy Services Authenticators Interface}. 
 10   
 11  """ 
 12   
 13  from entropy.const import const_get_stringtype 
 14  from entropy.services.skel import Authenticator 
 15  from entropy.services.auth_interfaces import phpBB3Auth 
 16  from entropy.services.skel import SocketAuthenticator 
 17  from entropy.exceptions import * 
 18   
 19  # Authenticator that can be used by SocketHostInterface based instances 
20 -class phpBB3(phpBB3Auth, SocketAuthenticator):
21 22 import entropy.tools as entropyTools
23 - def __init__(self, HostInterface, *args, **kwargs):
24 SocketAuthenticator.__init__(self, HostInterface) 25 phpBB3Auth.__init__(self) 26 self.set_connection_data(kwargs) 27 self.connect()
28
29 - def set_session(self, session):
30 self.session = session 31 session_data = self.HostInterface.sessions.get(self.session) 32 if not session_data: 33 return 34 auth_id = session_data['auth_uid'] 35 if auth_id: 36 self.logged_in = True 37 # fill login_data with fake information 38 self.login_data = {'username': self.FAKE_USERNAME, 'password': 'look elsewhere, this is not a password', 'user_id': auth_id} 39 ip_address = session_data.get('ip_address') 40 if ip_address and self.do_update_session_table: 41 self._update_session_table(auth_id, ip_address)
42
43 - def docmd_login(self, arguments):
44 45 # filter n00bs 46 if not arguments or (len(arguments) != 2): 47 return False, None, None, 'wrong arguments' 48 49 ip_address = None 50 session_data = self.HostInterface.sessions.get(self.session) 51 if session_data: 52 ip_address = session_data.get('ip_address') 53 user = arguments[0] 54 password = arguments[1] 55 56 if ip_address: 57 if self._is_ip_banned(ip_address): 58 return False, user, None, "banned IP" 59 60 login_data = {'username': user, 'password': password} 61 self.set_login_data(login_data) 62 rc = False 63 try: 64 rc = self.login() 65 except PermissionDenied as e: 66 return rc, user, None, e.value 67 68 if rc: 69 uid = self.get_user_id() 70 is_admin = self.is_administrator() 71 is_dev = self.is_developer() 72 is_mod = self.is_moderator() 73 is_user = self.is_user() 74 self.HostInterface.sessions[self.session]['admin'] = is_admin 75 self.HostInterface.sessions[self.session]['developer'] = is_dev 76 self.HostInterface.sessions[self.session]['moderator'] = is_mod 77 self.HostInterface.sessions[self.session]['user'] = is_user 78 if ip_address and uid and self.do_update_session_table: 79 self._update_session_table(uid, ip_address) 80 return True, user, uid, "ok" 81 return rc, user, None, "login failed"
82 83 # if we get here it means we are logged in
84 - def docmd_userdata(self):
85 data = self.get_user_data() 86 return True, data, 'ok'
87
88 - def docmd_logout(self, myargs):
89 90 # filter n00bs 91 if (len(myargs) < 1) or (len(myargs) > 1): 92 return False, None, 'wrong arguments' 93 94 user = myargs[0] 95 # filter n00bs 96 if not user or not isinstance(user, const_get_stringtype()): 97 return False, None, "wrong user" 98 99 if not self.is_logged_in(): 100 return False, user, "already logged out" 101 102 return True, user, "ok"
103
104 - def set_exc_permissions(self, *args, **kwargs):
105 pass
106
107 - def hide_login_data(self, args):
108 myargs = args[:] 109 myargs[-1] = 'hidden' 110 return myargs
111
112 - def terminate_instance(self):
113 self.disconnect()
114