Commit 8f012082 authored by Robin Sonnabend's avatar Robin Sonnabend

Add working __repr__ to all backends

eval(repr(backend)) should be equivalent to backend
parent 82841588
......@@ -97,6 +97,13 @@ class StaticUserManager:
for (username, password, groups) in users
}
def __repr__(self):
users = [
(username, self.passwords[username], self.groups[username])
for username in self.passwords
]
return "StaticUserManager({})".format(users)
def authenticate(self, username, password):
return (username in self.passwords
and self.passwords[username] == password)
......@@ -118,6 +125,17 @@ try:
self.user_dn = user_dn
self.group_dn = group_dn
def __repr__(self):
return (
"LdapManager(host='{host}', user_dn='{user_dn}', "
"group_dn='{group_dn}', port={port}, use_ssl={use_ssl})"
.format(
host=self.server.host,
user_dn=self.user_dn,
group_dn=self.group_dn,
port=self.server.port,
use_ssl=self.server.ssl))
def authenticate(self, username, password):
try:
connection = ldap3.Connection(
......@@ -163,6 +181,24 @@ try:
self.domain = domain
self.user_dn = user_dn
self.group_dn = group_dn
self.ca_cert = ca_cert
self.host = host
self.port = port
self.use_ssl = use_ssl
def __repr__(self):
return (
"ADManager(host='{host}', domain='{domain}', "
"user_dn='{user_dn}', group_dn='{group_dn}', "
"port={port}, use_ssl={use_ssl}, ca_cert='{ca_cert}')"
.format(
host=self.host,
domain=self.domain,
user_dn=self.user_dn,
group_dn=self.group_dn,
port=self.port,
use_ssl=self.use_ssl,
ca_cert=self.ca_cert))
def prepare_connection(self, username=None, password=None):
if username is not None and password is not None:
......@@ -229,6 +265,9 @@ try:
def __init__(self):
self.pam = pam.pam()
def __repr__(self):
return "PAMManager()"
def authenticate(self, username, password):
return self.pam.authenticate(username, password)
......@@ -241,5 +280,6 @@ try:
def all_groups(self, username, password):
for group in grp.getgrall():
yield group.gr_name
except ImportError:
pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment