Authentication
elva.auth
Module providing authentication utilities.
Classes:
-
Password
–A container which stores a password behind an attribute and redacts its value.
-
LDAP3LogLevel
–The logging level specified by the LDAP3 Python library as enumeration.
-
Auth
–Base class for authentications.
-
DummyAuth
–Dummy
Basic Authentication
class where password equals user name. -
LDAPAuth
–Basic Authentication
using LDAP self-bind.
Functions:
-
basic_authorization_header
–Compose the Base64 encoded
Authorization
header forBasic
authentication
Password(value, redact='REDACTED')
A container which stores a password behind an attribute and redacts its value.
The purpose of this class is two-fold: A password's value needs to be requested explicitely and accidential leaking via printing and logging is prevented.
Parameters:
-
value
(str
) –the actual password.
-
redact
(str
, default:'REDACTED'
) –the string to mask the password.
Methods:
-
__str__
–The string conversion of this object.
-
__repr__
–The string representation of this object.
Attributes:
Source code in src/elva/auth.py
value = value
instance-attribute
The actual password.
redact = redact
instance-attribute
The string to mask the password.
__str__()
The string conversion of this object.
Returns:
__repr__()
The string representation of this object.
Returns:
LDAP3LogLevel
Bases: IntEnum
The logging level specified by the LDAP3 Python library as enumeration.
Intended as arguments for ldap3.utils.log.set_library_log_detail_level
.
See https://ldap3.readthedocs.io/en/latest/logging.html for details.
Attributes:
-
OFF
–Nothing is logged.
-
ERROR
–Only exceptions are logged.
-
BASIC
–Library activity is logged, only operation result is shownn
-
PROTOCOL
–LDAPv3 operations are logged, sent requests and received responses are shown.
-
NETWORK
–Socket activity is logged.
-
EXTENDED
–LDAP messages are decoded and properly printed.
OFF = OFF
class-attribute
instance-attribute
Nothing is logged.
ERROR = ERROR
class-attribute
instance-attribute
Only exceptions are logged.
BASIC = BASIC
class-attribute
instance-attribute
Library activity is logged, only operation result is shownn
PROTOCOL = PROTOCOL
class-attribute
instance-attribute
LDAPv3 operations are logged, sent requests and received responses are shown.
NETWORK = NETWORK
class-attribute
instance-attribute
Socket activity is logged.
EXTENDED = EXTENDED
class-attribute
instance-attribute
LDAP messages are decoded and properly printed.
Auth
Base class for authentications.
This class is intended to be used in the server
app module.
Methods:
__new__(*args, **kwargs)
Construct a new class.
check(username, password)
Decides whether the given credentials are valid or not.
This is required to be implemented in inheriting subclasses.
Parameters:
Returns:
-
bool
–True
if credentials are valid,False
if they are not.
Source code in src/elva/auth.py
DummyAuth()
Bases: Auth
Dummy Basic Authentication
class where password equals user name.
Danger
This class is intended for testing only. DO NOT USE IN PRODUCTION!
Methods:
-
check
–Checks whether username and password are identical.
Source code in src/elva/auth.py
check(username, password)
Checks whether username and password are identical.
Parameters:
Returns:
-
bool
–True
if username and password are identical,False
if they are not.
Source code in src/elva/auth.py
LDAPAuth(server, base, use_ssl=True, log_level=None)
Bases: Auth
Basic Authentication
using LDAP self-bind.
Parameters:
-
server
(str
) –address of the LDAP server.
-
base
(str
) –base for lookup on the LDAP server.
-
use_ssl
(bool
, default:True
) –flag whether to use SSL verification (
True
) or not (False
). -
log_level
(None | LDAP3LogLevel
, default:None
) –the logging level of the underlying LDAP3 library.
Methods:
-
check
–Perform a self-bind connection to the given LDAP server.
Source code in src/elva/auth.py
check(username, password)
Perform a self-bind connection to the given LDAP server.
Parameters:
-
username
(str
) –user name to use for the LDAP self-bind connection.
-
password
(str
) –password to use for the LDAP self-bind connection.
Returns:
-
bool
–True
if the LDAP self-bind connection could be established, i.e. was successful,False
otherwise.
Source code in src/elva/auth.py
basic_authorization_header(username, password, charset='utf-8')
Compose the Base64 encoded Authorization
header for Basic
authentication
according to The 'Basic' Authentication Scheme in RFC 7617.
Parameters:
-
username
(str
) –user name used for authentication.
-
password
(str
) –password used for authentication.
-
charset
(str
, default:'utf-8'
) –the character encoding the server expects the basic credentials to be encoded in.
Returns: