Package entropy :: Package services :: Module authenticators

Source Code for Module entropy.services.authenticators

  1  # -*- coding: utf-8 -*- 
  2  ''' 
  3      # DESCRIPTION: 
  4      # Entropy Object Oriented Interface 
  5   
  6      Copyright (C) 2007-2009 Fabio Erculiani 
  7   
  8      This program is free software; you can redistribute it and/or modify 
  9      it under the terms of the GNU General Public License as published by 
 10      the Free Software Foundation; either version 2 of the License, or 
 11      (at your option) any later version. 
 12   
 13      This program is distributed in the hope that it will be useful, 
 14      but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16      GNU General Public License for more details. 
 17   
 18      You should have received a copy of the GNU General Public License 
 19      along with this program; if not, write to the Free Software 
 20      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 21  ''' 
 22   
 23  from __future__ import with_statement 
 24   
 25  from entropy.services.skel import Authenticator 
 26  from entropy.services.auth_interfaces import phpBB3Auth 
 27  from entropy.services.skel import SocketAuthenticator 
 28  from entropy.exceptions import * 
 29   
 30  # Authenticator that can be used by SocketHostInterface based instances 
31 -class phpBB3(phpBB3Auth,SocketAuthenticator):
32 33 import entropy.tools as entropyTools
34 - def __init__(self, HostInterface, *args, **kwargs):
35 SocketAuthenticator.__init__(self, HostInterface) 36 phpBB3Auth.__init__(self) 37 self.set_connection_data(kwargs) 38 self.connect()
39
40 - def set_session(self, session):
41 self.session = session 42 session_data = self.HostInterface.sessions.get(self.session) 43 if not session_data: 44 return 45 auth_id = session_data['auth_uid'] 46 if auth_id: 47 self.logged_in = True 48 # fill login_data with fake information 49 self.login_data = {'username': self.FAKE_USERNAME, 'password': 'look elsewhere, this is not a password', 'user_id': auth_id} 50 ip_address = session_data.get('ip_address') 51 if ip_address and self.do_update_session_table: 52 self._update_session_table(auth_id, ip_address)
53
54 - def docmd_login(self, arguments):
55 56 # filter n00bs 57 if not arguments or (len(arguments) != 2): 58 return False,None,None,'wrong arguments' 59 60 ip_address = None 61 session_data = self.HostInterface.sessions.get(self.session) 62 if session_data: 63 ip_address = session_data.get('ip_address') 64 user = arguments[0] 65 password = arguments[1] 66 67 if ip_address: 68 if self._is_ip_banned(ip_address): 69 return False,user,None,"banned IP" 70 71 login_data = {'username': user, 'password': password} 72 self.set_login_data(login_data) 73 rc = False 74 try: 75 rc = self.login() 76 except PermissionDenied, e: 77 return rc,user,None,e.value 78 79 if rc: 80 uid = self.get_user_id() 81 is_admin = self.is_administrator() 82 is_dev = self.is_developer() 83 is_mod = self.is_moderator() 84 is_user = self.is_user() 85 self.HostInterface.sessions[self.session]['admin'] = is_admin 86 self.HostInterface.sessions[self.session]['developer'] = is_dev 87 self.HostInterface.sessions[self.session]['moderator'] = is_mod 88 self.HostInterface.sessions[self.session]['user'] = is_user 89 if ip_address and uid and self.do_update_session_table: 90 self._update_session_table(uid, ip_address) 91 return True,user,uid,"ok" 92 return rc,user,None,"login failed"
93 94 # if we get here it means we are logged in
95 - def docmd_userdata(self):
96 data = self.get_user_data() 97 return True, data, 'ok'
98
99 - def docmd_logout(self, myargs):
100 101 # filter n00bs 102 if (len(myargs) < 1) or (len(myargs) > 1): 103 return False,None,'wrong arguments' 104 105 user = myargs[0] 106 # filter n00bs 107 if not user or not isinstance(user,basestring): 108 return False,None,"wrong user" 109 110 if not self.is_logged_in(): 111 return False,user,"already logged out" 112 113 return True,user,"ok"
114
115 - def set_exc_permissions(self, *args, **kwargs):
116 pass
117
118 - def hide_login_data(self, args):
119 myargs = args[:] 120 myargs[-1] = 'hidden' 121 return myargs
122
123 - def terminate_instance(self):
124 self.disconnect()
125