本文整理汇总了Python中privacyidea.model.meta.Session.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Session.commit方法的具体用法?Python Session.commit怎么用?Python Session.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类privacyidea.model.meta.Session
的用法示例。
在下文中一共展示了Session.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __before__
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def __before__(self, action, **params):
'''
'''
try:
c.audit['success'] = False
c.audit['client'] = get_client()
self.Policy = PolicyClass(request, config, c,
get_privacyIDEA_config(),
tokenrealms=request.params.get('serial'),
token_type_list=get_token_type_list())
self.set_language()
self.before_identity_check(action)
Session.commit()
return request
except webob.exc.HTTPUnauthorized as acc:
# the exception, when an abort() is called if forwarded
log.info("%r: webob.exception %r" % (action, acc))
log.info(traceback.format_exc())
Session.rollback()
Session.close()
raise acc
except Exception as exx:
log.error("exception %r" % (action, exx))
log.error(traceback.format_exc())
Session.rollback()
Session.close()
return sendError(response, exx, context='before')
finally:
pass
示例2: delete
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def delete(self, action, **params):
'''
Delete an existing client machine entry
:param name: the unique name of the machine
:return: value is either true (success) or false (fail)
'''
try:
res = {}
param = {}
# check machine authorization
self.Policy.checkPolicyPre('machine', 'delete')
param.update(request.params)
machine_name = getParam(param, "name", required)
res = delete_machine(machine_name)
Session.commit()
c.audit["success"] = True
return sendResult(response, res, 1)
except PolicyException as pe:
log.error("policy failed: %r" % pe)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(pe))
except Exception as exx:
log.error("failed: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(exx), 0)
finally:
Session.close()
示例3: getResolvers
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def getResolvers(self, action, **params):
"""
method:
system/getResolvers
descriptions:
returns a json list of all useridresolvers
arguments:
returns:
a json result with a list of all available resolvers
exception:
if an error occurs an exception is serialized and returned
"""
res = {}
try:
res = getResolverList()
c.audit['success'] = True
Session.commit()
return sendResult(response, res, 1)
except Exception as exx:
log.error("error getting resolvers: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, exx)
finally:
Session.close()
示例4: show
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def show(self, action, **params):
'''
Returns a list of the client machines.
:param name: Optional parameter to only show this single machine
:return: JSON details
'''
try:
res = {}
param = {}
# check machine authorization
self.Policy.checkPolicyPre('machine', 'show')
param.update(request.params)
machine_name = getParam(param, "name", optional)
res = show_machine(machine_name)
Session.commit()
c.audit["success"] = True
return sendResult(response, res, 1)
except PolicyException as pe:
log.error("policy failed: %r" % pe)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(pe))
except Exception as exx:
log.error("failed: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(exx), 0)
finally:
Session.close()
示例5: delResolver
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def delResolver(self, action, **params):
"""
method:
system/delResolver
description:
this function deletes an existing resolver
All config keys of this resolver get deleted
arguments:
resolver - the name of the resolver to delete.
returns:
success state
exception:
if an error occurs an exception is serialized and returned
"""
res = {}
try:
param = getLowerParams(request.params)
resolver = getParam(param, "resolver", required)
### only delete a resolver, if it is not used by any realm
found = False
fRealms = []
realms = getRealms()
for realm in realms:
info = realms.get(realm)
reso = info.get('useridresolver')
for idRes in reso:
if resolver == get_resolver_name(idRes):
fRealms.append(realm)
found = True
if found == True:
c.audit['failed'] = res
err = 'Resolver %r still in use by the realms: %r' % \
(resolver, fRealms)
c.audit['info'] = err
raise Exception('%r !' % err)
res = deleteResolver(resolver)
c.audit['success'] = res
c.audit['info'] = resolver
Session.commit()
return sendResult(response, res, 1)
except Exception as exx:
log.error("error deleting resolver: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, exx)
finally:
Session.close()
示例6: setResolver
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def setResolver(self, action, **params):
"""
method:
system/setResolver
description:
creates or updates a useridresolver
arguments:
name - the name of the resolver
type - the type of the resolver [ldapsersolver, sqlresolver]
LDAP:
LDAPURI
LDAPBASE
BINDDN
BINDPW
TIMEOUT
SIZELIMIT
LOGINNAMEATTRIBUTE
LDAPSEARCHFILTER
LDAPFILTER
USERINFO
NOREFERRALS - True|False
SQL:
Database
Driver
Server
Port
User
Password
Table
Map
returns:
a json result with the found value
exception:
if an error occurs an exception is serialized and returned
"""
res = {}
param = {}
try:
param.update(request.params)
res = defineResolver(param)
Session.commit()
return sendResult(response, res, 1)
except Exception as exx:
log.error("error saving config: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, exx)
finally:
Session.close()
示例7: delConfig
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def delConfig(self, action, **params):
"""
delete a configuration key
* if an error occurs an exception is serializedsetConfig and returned
:param key: configuration key name
:returns: a json result with the deleted value
"""
res = {}
try:
param = getLowerParams(request.params)
key = getParam(param, "key", required)
ret = removeFromConfig(key)
string = "delConfig " + key
res[string] = ret
c.audit['success'] = ret
c.audit['info'] = key
Session.commit()
return sendResult(response, res, 1)
except Exception as exx:
log.error("error deleting config: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, exx)
finally:
Session.close()
示例8: __after__
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def __after__(self, action, **params):
'''
'''
params = {}
try:
params.update(request.params)
c.audit['administrator'] = getUserFromRequest(request).get("login")
if 'serial' in params:
c.audit['serial'] = request.params['serial']
c.audit['token_type'] = getTokenType(params.get('serial'))
self.audit.log(c.audit)
Session.commit()
return request
except Exception as e:
log.error("unable to create a session cookie: %r" % e)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, e, context='after')
finally:
Session.close()
示例9: deltoken
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def deltoken(self, action, **params):
'''
delete a token and a application from a machine
:param name: Name of the machine
:param serial: serial number of the token
:param application: name of the application
'''
try:
res = False
param = {}
# check machine authorization
self.Policy.checkPolicyPre('machine', 'deltoken')
param.update(request.params)
machine_name = getParam(param, "name", required)
serial = getParam(param, "serial", required)
application = getParam(param, "application", required)
res = deltoken(machine_name, serial, application)
Session.commit()
c.audit["success"] = True
return sendResult(response, res, 1)
except PolicyException as pe:
log.error("policy failed: %r" % pe)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(pe))
except Exception as exx:
log.error("failed: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(exx), 0)
示例10: check_yubikey
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def check_yubikey(self, action, **params):
'''
This function is used to validate the output of a yubikey
method:
validate/check_yubikey
:param pass: The password that consist of the static yubikey prefix and the otp
:type pass: string
:return: JSON Object
returns:
JSON response::
{
"version": "privacyIDEA 2.4",
"jsonrpc": "2.0",
"result": {
"status": true,
"value": false
},
"detail" : {
"username": username,
"realm": realm
},
"id": 0
}
'''
param = request.params
passw = getParam(param, "pass", required)
try:
ok = False
try:
ok, opt = checkYubikeyPass(passw)
c.audit['success'] = ok
except AuthorizeException as exx:
log.warning("authorization failed for validate/check_yubikey: %r"
% exx)
c.audit['success'] = False
c.audit['info'] = unicode(exx)
ok = False
Session.commit()
return sendResult(response, ok, 0, opt=opt)
except Exception as exx:
log.error("validate/check_yubikey failed: %r" % exx)
log.error(traceback.format_exc())
c.audit['info'] = unicode(exx)
Session.rollback()
return sendError(response, u"validate/check_yubikey failed: %s"
% unicode(exx), 0)
finally:
Session.close()
示例11: addtoken
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def addtoken(self, action, **params):
'''
Add a token and a application to a machine
:param name: Name of the machine
:param serial: serial number of the token
:param application: name of the application
:param option_*: parameter is passed as additional option to
the machinetoken to be stored in
machine_t_options table.
In case of LUKS application this can be
"option_slot"
'''
try:
res = False
param = {}
options = {}
# check machine authorization
self.Policy.checkPolicyPre('machine', 'addtoken')
param.update(request.params)
machine_name = getParam(param, "name", required)
serial = getParam(param, "serial", required)
application = getParam(param, "application", required)
if application.lower() not in config.get("applications").keys():
log.error("Unknown application %r. Available applications: "
"%r" % (application,
config.get("applications").keys()))
raise Exception("Unkown application!")
for p in param.keys():
if p.startswith("option_"):
options[p] = param.get(p)
mt = addtoken(machine_name,
serial,
application,
options=options)
if mt:
res = True
Session.commit()
c.audit["success"] = True
return sendResult(response, res, 1)
except PolicyException as pe:
log.error("policy failed: %r" % pe)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(pe))
except Exception as exx: # pragma: no cover
log.error("failed: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(exx), 0)
finally:
Session.close()
示例12: setRealm
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def setRealm(self, action, **params):
"""
method:
system/setRealm
description:
this function is used to define a realm with the given
useridresolvers
arguments:
realm - name of the realm
resolvers - comma seperated list of resolvers, that should be
in this realm
returns:
a json result with a list of Realms
exception:
if an error occurs an exception is serialized and returned
"""
res = False
err = ""
realm = ""
param = {}
try:
param.update(request.params)
realm = getParam(param, "realm", required)
resolvers = getParam(param, "resolvers", required)
realm_resolvers = []
for resolver in resolvers.split(','):
# check resolver returns the correct resolver description
(res, realm_resolver) = checkResolverType(resolver)
if res is False:
raise Exception("Error in resolver %r please check the"
" logfile!" % resolver)
realm_resolvers.append(realm_resolver)
resolvers = ",".join(realm_resolvers)
res = setRealm(realm, resolvers)
c.audit['success'] = res
c.audit['info'] = "realm: %r, resolvers: %r" % (realm, resolvers)
Session.commit()
return sendResult(response, res, 1)
except Exception as exx:
err = ("Failed to set realm with %r " % param)
log.error("%r %r" % (err, exx))
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, exx)
finally:
Session.close()
示例13: addoption
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def addoption(self, action, **params):
'''
Add an option to a machinetoken definition
:param mtid: id of the machine token definition
:param name: machine_name
:param serial: serial number of the token
:param application: application
:param option_*: name of the option.
In case of LUKS application this can be
"option_slot"
You either need to provide the machine-token-id (mtid) directly or
you need to provide the tuple (name, serial, application)
'''
try:
num = -1
param = {}
options = {}
# check machine authorization
self.Policy.checkPolicyPre('machine', 'addtoken')
param.update(request.params)
mtid = getParam(param, "mtid", optional)
machine_name = getParam(param, "name", optional)
serial = getParam(param, "serial", optional)
application = getParam(param, "application", optional)
if not (mtid or (machine_name and serial and application)):
raise ParameterError("You need to specify either mtid or"
"the tuple name, serial, application",
id=201)
for p in param.keys():
if p.startswith("option_"):
options[p] = param.get(p)
num = addoption(mtid,
name=machine_name,
serial=serial,
application=application,
options=options)
Session.commit()
c.audit["success"] = True
return sendResult(response, num, 1)
except PolicyException as pe:
log.error("policy failed: %r" % pe)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(pe))
except Exception as exx: # pragma: no cover
log.error("failed: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(exx), 0)
finally:
Session.close()
示例14: __init__
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def __init__(self, machinetoken_id, key, value):
log.debug("setting %r to %r for MachineToken %s" % (key,
value,
machinetoken_id))
self.machinetoken_id = machinetoken_id
self.mt_key = key
self.mt_value = value
Session.add(self)
Session.commit()
示例15: getRealms
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import commit [as 别名]
def getRealms(self, action, **params):
'''
method:
system/getRealms
description:
returns all realm definitinos as a json result.
arguments:
returns:
a json result with a list of Realms
exception:
if an error occurs an exception is serialized and returned
Either the admin has the policy scope=system, action=read
or he is rights in scope=admin for some realms.
If he does not have the system-read-right, then he will only
see the realms, he is admin of.
'''
### config settings from here
try:
param = getLowerParams(request.params)
res = getRealms()
c.audit['success'] = True
# If the admin is not allowed to see all realms, (policy scope=system, action=read)
# the realms, where he has no administrative rights need, to be stripped.
polPost = self.Policy.checkPolicyPost('system', 'getRealms', { 'realms' : res })
res = polPost['realms']
Session.commit()
return sendResult(response, res, 1)
except PolicyException as pex:
log.error("policy exception: %r" % pex)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, pex)
except Exception as exx:
log.error("error getting realms: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, exx)
finally:
Session.close()