linotp.useridresolver.SQLIdResolver module

This module implements the communication and data mapping to SQL servers. The LinOTP server imports this module to use SQL databases as a userstore.

Dependencies: UserIdResolver

class linotp.useridresolver.SQLIdResolver.IdResolver[source]

Bases: linotp.useridresolver.UserIdResolver.UserIdResolver

checkMapping()[source]

check the given sql field map against the sql table definition

Returns:
checkPass(uid, password)[source]

checkPass - checks the password for a given uid.

Parameters:
  • uid (string) – userid to be checked
  • password (string) – user password

:return : true in case of success, false if password does not match :rtype : boolean

Todo:extend to support htpasswd passwords: http://httpd.apache.org/docs/2.2/misc/password_encryptions.html
close()[source]

close the db connection - will be called at the end of the request

connect(sqlConnect=None)[source]

create a db connection and preserve session in self.dbObj

critical_parameters = ['Driver', 'Server', 'Port', 'Database', 'User', 'Table']
crypted_parameters = ['Password']
db_prefix = 'useridresolver.SQLIdResolver.IdResolver'
classmethod getResolverClassDescriptor()[source]

return the descriptor of the resolver, which is - the class name and - the config description

Returns:resolver description dict
Return type:dict
classmethod getResolverClassType()[source]
getResolverDescriptor()[source]
getResolverId()[source]

getResolverId - provide the resolver identifier

Returns:returns the resolver identifier string or empty string if not exist

:rtype : string

getResolverType()[source]

getResolverType - return the type of the resolver

Returns:returns the string ‘sqlresolver’
Return type:string
getSearchFields()[source]

return all fields on which a search could be made

Returns:dictionary of the search fields and their types
Return type:dict
getUserId(loginName)[source]

return the userId which mappes to a loginname

Parameters:loginName (string) – login name of the user
Returns:userid - unique idenitfier for this unser
Return type:string
getUserInfo(userId, suppress_password=True)[source]

return all user related information

@param userId: specied user @type userId: string @return: dictionary, containing all user related info @rtype: dict

getUserList(searchDict)[source]

retrieve a list of users

Parameters:searchDict (dict) – dictionary of the search criterias
Returns:list of user descriptions (as dict)
getUsername(userId)[source]

get the loginname from the given userid

Parameters:userId (string) – userid descriptor
Returns:loginname
Return type:string
loadConfig(config, conf='')[source]

loadConfig - load the config for the resolver

Parameters:
  • config (dict) – configuration for the sqlresolver
  • conf (string) – configuration postfix
classmethod primary_key_changed(new_params, previous_params)[source]

check if during the parameter update the primary key has changed

Parameters:
  • new_params – the set of new parameters
  • previous_params – the set of previous parameters
Returns:

boolean

resolver_parameters = {'Database': (False, '', <function text at 0x7f55c832e398>), 'Server': (False, '', <function text at 0x7f55c832e398>), 'Limit': (False, '1000', <type 'int'>), 'Where': (False, '', <function text at 0x7f55c832e398>), 'conParams': (False, '', <function text at 0x7f55c832e398>), 'Map': (False, '', <function text at 0x7f55c832e398>), 'Encoding': (False, 'utf-8', <function text at 0x7f55c832e398>), 'Driver': (False, None, <function text at 0x7f55c832e398>), 'readonly': (False, False, <function boolean at 0x7f55c832e488>), 'Connect': (False, '', <function text at 0x7f55c832e398>), 'Table': (False, '', <function text at 0x7f55c832e398>), 'Password': (True, '', <function encrypted_data at 0x7f55c832e410>), 'Port': (False, '', <function text at 0x7f55c832e398>), 'User': (False, '', <function text at 0x7f55c832e398>)}
classmethod setup(config=None, cache_dir=None)[source]

this setup hook is triggered, when the server starts to serve the first request

Parameters:config (the linotp config dict) – the linotp config
classmethod testconnection(parameters)[source]

This is used to test if the given parameter set will do a successful SQL connection and return the number of found users params are:

  • Driver
  • Server
  • Port
  • Database
  • User
  • Password
  • Table
linotp.useridresolver.SQLIdResolver.build_simple_connect(driver, user=None, pass_=None, server=None, port=None, db=None, conParams=None)[source]

build from the parameters the sql connect url

Parameters:
  • driver – the url protocoll / prefix
  • user – the database accessing user
  • pass – the password of database accessing user
  • server – the hostname for the server could be empty
  • port – the port on th server host, could be empty
  • db – the database on the server
  • conParams – additional and otpional database parameter

return the connection string

linotp.useridresolver.SQLIdResolver.call_on_connect(dbapi_con, connection_record)[source]
linotp.useridresolver.SQLIdResolver.check_php_password(password, stored_hash)[source]

from phppass: check certain kinds of phppassowrds

Parameters:
  • password – the new, to be verified password
  • stored_hash – the previously used password in a hashed form
Returns:

boolean

class linotp.useridresolver.SQLIdResolver.dbObject[source]
close()[source]
connect(sqlConnect)[source]

create a db session with the sqlConnect string

Parameters:sqlConnect – sql url for the connection
count(table, where='')[source]
getTable(tableName)[source]
query(select)[source]
linotp.useridresolver.SQLIdResolver.make_connect(driver, user, pass_, server, port, db, conParams='')[source]

create a connect string from decicated parts - to build a SQLAlchemy Uri

Parameters:
  • driver (string) – mysql, postgres, ...
  • user (string) – database connection user
  • pass (string) – password of the database user
  • server (string) – servername
  • port (string or int) – database connection port
  • db (string) – database name
  • conParams (string) – additional connection parameters
linotp.useridresolver.SQLIdResolver.testconnection(params)[source]

provide the old interface for backward compatibility