[Authentication] Some of the base class functions are not static

function, but - methods. Hence - 'self' should be used, and not 'cls'.

Also - use a constant for duplicate string literal in LDAP
authentication implementation.
This commit is contained in:
Ashesh Vashi 2020-04-08 18:35:45 +05:30
parent d226ffbd1f
commit 414e336852
2 changed files with 18 additions and 15 deletions

View File

@ -30,11 +30,11 @@ class BaseAuthentication(object):
}
@abstractproperty
def get_friendly_name(cls):
def get_friendly_name(self):
pass
@abstractmethod
def authenticate(cls):
def authenticate(self):
pass
def validate(self, form):
@ -80,7 +80,7 @@ class BaseAuthentication(object):
class InternalAuthentication(BaseAuthentication):
def get_friendly_name(cls):
def get_friendly_name(self):
return gettext("internal")
def validate(self, form):

View File

@ -19,7 +19,6 @@ from flask_babelex import gettext
from .internal import BaseAuthentication
from pgadmin.model import User, ServerGroup, db, Role
from flask_security import login_user
from flask import current_app
from pgadmin.tools.user_management import create_user
@ -29,6 +28,11 @@ except ImportError:
from urlparse import urlparse
ERROR_SEARCHING_LDAP_DIRECTORY = gettext(
"Error searching the LDAP directory: %s"
)
class LDAPAuthentication(BaseAuthentication):
"""Ldap Authentication Class"""
@ -161,21 +165,20 @@ class LDAPAuthentication(BaseAuthentication):
except LDAPInvalidScopeError as e:
current_app.logger.exception(
"Error searching the LDAP directory: %s\n" % e)
return False, "Error searching the LDAP directory:" \
" %s\n" % e.args[0]
gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e
)
return False, gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e.args[0]
except LDAPAttributeError as e:
current_app.logger.exception("Error searching the LDAP directory:"
" %s\n" % e)
return False, "Error searching the LDAP directory:" \
" %s\n" % e.args[0]
current_app.logger.exception(
gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e
)
return False, gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e.args[0]
except LDAPInvalidFilterError as e:
current_app.logger.exception(
"Error searching the LDAP directory: %s\n" % e)
return False, "Error searching the LDAP directory:" \
" %s\n" % e.args[0]
gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e
)
return False, gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e.args[0]
users = []
for entry in self.conn.entries:
user_email = None
if config.LDAP_USERNAME_ATTRIBUTE in entry and self.username == \