22 |
# $Id$ |
# $Id$ |
23 |
|
|
24 |
import string |
import string |
25 |
|
from gnue.common.apps import GDebug |
26 |
|
|
27 |
# ============================================================================= |
# ============================================================================= |
28 |
# Basic Authentication Class ( abstract ) |
# Basic Authentication Class ( abstract ) |
45 |
# --------------------------------------------------------------------------- |
# --------------------------------------------------------------------------- |
46 |
|
|
47 |
def authenticate(self, session, user, auth): |
def authenticate(self, session, user, auth): |
48 |
|
GDebug.printMesg(1,"Fake authentication for user %s" % user) |
49 |
return 1 |
return 1 |
50 |
|
|
51 |
|
|
56 |
# --------------------------------------------------------------------------- |
# --------------------------------------------------------------------------- |
57 |
|
|
58 |
def hasAccess (self, session, user, classname): |
def hasAccess (self, session, user, classname): |
59 |
|
GDebug.printMesg(1,"Fake access check for class %s and user %s" % (classname,user)) |
60 |
return 1 |
return 1 |
61 |
|
|
62 |
|
|
70 |
# Initalize |
# Initalize |
71 |
# --------------------------------------------------------------------------- |
# --------------------------------------------------------------------------- |
72 |
|
|
73 |
def __init__ (self): |
def __init__ (self, internalSession): |
74 |
# creation and populating the user/password/tablelist list should be |
# creation and populating the user/password/tablelist list should be |
75 |
# moved here, when the management interface is implemented and an easy |
# moved here, when the management interface is implemented and an easy |
76 |
# way to update permissions is working |
# way to update permissions is working |
77 |
pass |
self._intSess=internalSession |
78 |
|
|
79 |
# --------------------------------------------------------------------------- |
# --------------------------------------------------------------------------- |
80 |
# authenticate an user |
# authenticate an user |
84 |
# --------------------------------------------------------------------------- |
# --------------------------------------------------------------------------- |
85 |
|
|
86 |
def authenticate(self, session, user, auth): |
def authenticate(self, session, user, auth): |
87 |
authList = session.createList ("appserver_users") |
authList = self._intSess.request ("gnue_useraccess", |
88 |
|
[['eq', ''],['field', 'gnue_username'],['const', user ]], |
89 |
|
[],["gnue_username", "gnue_password", "gnue_accesslist"]) |
90 |
|
|
91 |
authList.setPrefetch (["username", "password", "tablelist"]) |
authData = self._intSess.fetch(authList,0,10) |
|
authList.setConditions ([['eq', ''], |
|
|
['field', 'username'], |
|
|
['const', user ]]) |
|
|
authList.populate () |
|
92 |
|
|
93 |
instance = authList.firstInstance () |
if len(authData)==0: |
|
|
|
|
# no such user |
|
|
if instance==None: |
|
94 |
# log something |
# log something |
95 |
print _("User '%s' does not exist.") % user |
GDebug.printMesg(1, _("User '%s' does not exist.") % user) |
96 |
|
|
97 |
return 0 # = no access |
return 0 # = no access |
98 |
|
|
99 |
if instance.get('password')!=auth['password']: |
if len(authData)>1: |
100 |
|
# log something |
101 |
|
GDebug.printMesg(1,_("Internal Error: More than one (%s) record for user '%s'.") % (len(authData),user)) |
102 |
|
|
103 |
|
if authData[0][2]!=auth['password']: |
104 |
# log something |
# log something |
105 |
print _("User '%s' didn't provide right authentication information"+ |
GDebug.printMesg(1, _("User '%s' didn't provide correct authentication information"+ |
106 |
" (password).") % user |
" (password).") % user) |
107 |
|
|
108 |
return 0 # = no access |
return 0 # = no access |
109 |
|
|
110 |
print _("User '%s' logged in.") % user |
GDebug.printMesg(1, _("User '%s' logged in.") % user) |
111 |
|
|
112 |
# possibly not the best solution |
# possibly not the best solution |
113 |
session._tablelist=string.split(instance.get('tablelist'),',') |
session._tablelist=string.split(authData[0][3],',') |
114 |
|
|
115 |
return 1 # = has access |
return 1 # = has access |
116 |
|
|
126 |
if hasattr(session,"_tablelist") and (classname in session._tablelist): |
if hasattr(session,"_tablelist") and (classname in session._tablelist): |
127 |
return 1 |
return 1 |
128 |
else: |
else: |
129 |
|
GDebug.printMesg(1, _("User '%s' has no access to class %s.") % (user,classname)) |
130 |
return 0 |
return 0 |
131 |
|
|
132 |
# ============================================================================= |
# ============================================================================= |