* More fixes raised during tests

This commit is contained in:
Adolfo Gómez García 2014-10-30 07:25:33 +01:00
parent 6fbe86b218
commit 063f433696
4 changed files with 19 additions and 13 deletions

View File

@ -39,7 +39,7 @@ from uds.core.util import log
from uds.REST.model import ModelHandler from uds.REST.model import ModelHandler
from uds.REST import RequestError, ResponseError from uds.REST import RequestError, ResponseError
from uds.core.ui.UserInterface import gui from uds.core.ui.UserInterface import gui
from user_services import AssignedService, CachedService, Groups, Transports, Publications from uds.REST.methods.user_services import AssignedService, CachedService, Groups, Transports, Publications
import logging import logging
@ -165,11 +165,11 @@ class ServicesPools(ModelHandler):
fields['osmanager'] = osmanager fields['osmanager'] = osmanager
del fields['osmanager_id'] del fields['osmanager_id']
if serviceType.usesCache == False: if serviceType.usesCache is False:
for k in ('initial_srvs', 'cache_l1_srvs', 'cache_l2_srvs', 'max_srvs'): for k in ('initial_srvs', 'cache_l1_srvs', 'cache_l2_srvs', 'max_srvs'):
fields[k] = 0 fields[k] = 0
except: except Exception:
raise RequestError(ugettext('This service requires an os manager')) raise RequestError(ugettext('This service requires an os manager'))
except (RequestError, ResponseError): except (RequestError, ResponseError):

View File

@ -126,7 +126,7 @@ class MarshallerProcessor(ContentProcessor):
try: try:
if len(self._request.body) == 0: if len(self._request.body) == 0:
return self.processGetParameters() return self.processGetParameters()
logger.debug('Body: >>{}<< {}'.format(self._request.body, len(self._request.body))) # logger.debug('Body: >>{}<< {}'.format(self._request.body, len(self._request.body)))
res = self.marshaller.loads(self._request.body) res = self.marshaller.loads(self._request.body)
logger.debug("Unmarshalled content: {}".format(res)) logger.debug("Unmarshalled content: {}".format(res))
return res return res

View File

@ -108,7 +108,7 @@ class InternalDBAuth(Authenticator):
except Exception: except Exception:
return False return False
if usr.parent is not None and self.parent != '': # Direct auth not allowed for "derived" users if usr.parent is not None and usr.parent != '': # Direct auth not allowed for "derived" users
return False return False
# Internal Db Auth has its own groups, and if it active it is valid # Internal Db Auth has its own groups, and if it active it is valid

View File

@ -42,8 +42,9 @@ from uds.core.auths.Exceptions import AuthenticatorException
import ldap import ldap
import logging import logging
import six
__updated__ = '2014-09-11' __updated__ = '2014-10-30'
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -84,7 +85,7 @@ class SimpleLDAPAuthenticator(Authenticator):
def __init__(self, dbAuth, environment, values=None): def __init__(self, dbAuth, environment, values=None):
super(SimpleLDAPAuthenticator, self).__init__(dbAuth, environment, values) super(SimpleLDAPAuthenticator, self).__init__(dbAuth, environment, values)
if values != None: if values is not None:
self._host = values['host'] self._host = values['host']
self._port = values['port'] self._port = values['port']
self._ssl = gui.strToBool(values['ssl']) self._ssl = gui.strToBool(values['ssl'])
@ -125,13 +126,13 @@ class SimpleLDAPAuthenticator(Authenticator):
def __str__(self): def __str__(self):
return "Ldap Auth: {0}:{1}@{2}:{3}, base = {4}, userClass = {5}, groupClass = {6}, userIdAttr = {7}, groupIdAttr = {8}, memberAttr = {9}, userName attr = {10}".format( return "Ldap Auth: {0}:{1}@{2}:{3}, base = {4}, userClass = {5}, groupClass = {6}, userIdAttr = {7}, groupIdAttr = {8}, memberAttr = {9}, userName attr = {10}".format(
self._username, self._password, self._host, self._port, self._ldapBase, self._userClass, self._groupClass, self._userIdAttr, self._groupIdAttr, self._memberAttr, self._username, self._password, self._host, self._port, self._ldapBase, self._userClass, self._groupClass, self._userIdAttr, self._groupIdAttr, self._memberAttr,
self._userNameAttr) self._userNameAttr)
def marshal(self): def marshal(self):
return '\t'.join(['v1', return '\t'.join(['v1',
self._host, self._port, gui.boolToStr(self._ssl), self._username, self._password, self._timeout, self._host, self._port, gui.boolToStr(self._ssl), self._username, self._password, self._timeout,
self._ldapBase, self._userClass, self._groupClass, self._userIdAttr, self._groupIdAttr, self._memberAttr, self._userNameAttr]) self._ldapBase, self._userClass, self._groupClass, self._userIdAttr, self._groupIdAttr, self._memberAttr, self._userNameAttr])
def unmarshal(self, str_): def unmarshal(self, str_):
data = str_.split('\t') data = str_.split('\t')
@ -142,6 +143,10 @@ class SimpleLDAPAuthenticator(Authenticator):
def __connection(self, username=None, password=None): def __connection(self, username=None, password=None):
if self._connection is None or username is not None: # We want this method also to check credentials if self._connection is None or username is not None: # We want this method also to check credentials
if isinstance(username, six.text_type):
username = username.encode('utf8')
if isinstance(password, six.text_type):
password = password.encode('utf8')
l = None l = None
cache = False cache = False
try: try:
@ -199,7 +204,7 @@ class SimpleLDAPAuthenticator(Authenticator):
attrlist = [self._memberAttr.encode('utf-8')] attrlist = [self._memberAttr.encode('utf-8')]
logger.debug('Getgroup filter_: {0}, attr list {1}'.format(filter_, attrlist)) logger.debug('Getgroup filter_: {0}, attr list {1}'.format(filter_, attrlist))
res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE,
filterstr=filter_, attrlist=attrlist, sizelimit=LDAP_RESULT_LIMIT)[0] filterstr=filter_, attrlist=attrlist, sizelimit=LDAP_RESULT_LIMIT)[0]
grp = dict((k, ['']) for k in attrlist) grp = dict((k, ['']) for k in attrlist)
grp.update(res[1]) grp.update(res[1])
grp.update({'dn': res[0], '_id': groupName}) grp.update({'dn': res[0], '_id': groupName})
@ -214,8 +219,8 @@ class SimpleLDAPAuthenticator(Authenticator):
con = self.__connection() con = self.__connection()
filter_ = '(&(objectClass=%s)(|(%s=%s)(%s=%s)))' % (self._groupClass, self._memberAttr, usr['_id'], self._memberAttr, usr['dn']) filter_ = '(&(objectClass=%s)(|(%s=%s)(%s=%s)))' % (self._groupClass, self._memberAttr, usr['_id'], self._memberAttr, usr['dn'])
logger.debug('Filter: {0}'.format(filter_)) logger.debug('Filter: {0}'.format(filter_))
res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr=filter_, attrlist=[self._groupIdAttr], res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr=filter_, attrlist=[self._groupIdAttr.encode('utf8')],
sizelimit=LDAP_RESULT_LIMIT) sizelimit=LDAP_RESULT_LIMIT)
groups = {} groups = {}
for g in res: for g in res:
v = g[1][self._groupIdAttr] v = g[1][self._groupIdAttr]
@ -227,6 +232,7 @@ class SimpleLDAPAuthenticator(Authenticator):
return groups return groups
except Exception: except Exception:
logger.exception('Exception at __getGroups')
return {} return {}
def __getUserRealName(self, usr): def __getUserRealName(self, usr):