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