Source code for useridresolver.UserIdResolver
'''
product: LinOTP2
module: useridresolver
tool: UserIdResolver
edition: Comunity Edition
Copyright (C) 2010 - 2013 LSE Leading Security Experts GmbH
License: AGPLv3
contact: http://www.linotp.org
http://www.lsexperts.de
linotp@lsexperts.de
Description: This module implements the communication interface
for resolvin user info to the user base
Dependencies: -
'''
"""UserIdResolver Interface class.
Defines the rough interface for a UserId Resolver
== a UserId Resolver is required to resolve the
Login Name to an unique User Identifier
- for /etc/passwd this will be the uid
- for ldap this might be the DN
- for SQL the unique index ( what's the right name here (tm))
"""
[docs]class UserIdResolver:
fields = {"username":1, "userid":1,
"description":0,
"phone":0,"mobile":0,"email":0,
"givenname":0,"surname":0,"gender":0
}
name = ""
id = ""
def __init(self):
""" init - usual bootstrap hook
"""
self.name = "UserIdResolver";
[docs] def getUserId(self, loginName):
""" getUserId(LoginName)
- returns the identifier string
- empty string if not exist
"""
return self.id
[docs] def getUsername(self, userid):
"""
getUsername(LoginId)
- returns the loginname string
- empty string if not exist
"""
return self.name
[docs] def getUserInfo(self, userid):
"""
getUserInfo(UserID)
This function returns all user information for a given user object identified
by UserID.
Return value is a dictionary, if no object is found, the dictionary is empty
"""
return ""
[docs] def getUserList(self, serachDict):
""" searchUserList(key, value)
This function finds the user objects, that have the term 'value' in the user object field 'key'
The key may be something like 'loginname' or 'email'.
The value is a regular expression.
Return value is a list of dictionaries (each dictionary contains a user object) or an
empty string if no object is found.
"""
return ""
[docs] def getResolverId(self):
""" getResolverId(LoginName)
- returns the resolver identifier string
- empty string if not exist
"""
""" print ">>" + LoginName; """
return self.name
def getResolverType(self):
return ''
def loadConfig(self, config, conf):
return self
[docs] def checkPass(self, uid, password):
'''
This function checks the password for a given uid.
- returns true in case of success
- false if password does not match
'''
return False
""" getResolverClass(packageName, className):
helper method to load the UserIdResolver class from a given
package in literal:
example:
getResolverClass("PasswdIdResolver", "IdResolver")()
check:
checks, if the getUserId method exists
if not an error is thrown
"""
def getResolverClass(packageName, className):
mod = __import__(packageName, globals(), locals(), [className])
klass = getattr(mod, className)
ret = ""
attribute = ""
try:
attrs = [ "getUserId","getUsername","getUserInfo","getUserList"
,"checkPass" ,"loadConfig"
,"getResolverId" ,"getResolverType" ,"getResolverDescriptor"
]
for att in attrs:
attribute = att
getattr(klass,att)
ret = klass
except:
raise NameError("IdResolver AttributeError: " + packageName + "." + \
className + " instance has no attribute '" + attribute + "'")
return ret