Source code for linotp.controllers.system

'''

  product:  LinOTP2
  module:   linotpd
  edition:  Community 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 file is part of the linotpd service
                 
  Dependencies: -
  

'''

import simplejson
import re

from pylons import request, response, config,  tmpl_context as c
from linotp.model.meta import Session

from linotp.lib.base import BaseController

from linotp.lib.config  import storeConfig
from linotp.lib.config  import getLinotpConfig
from linotp.lib.config  import getFromConfig
from linotp.lib.config  import initLinotpConfig
from linotp.lib.config  import updateConfig
from linotp.lib.config  import removeFromConfig

from linotp.lib.realm  import setDefaultRealm
from linotp.lib.realm  import isRealmDefined


from linotp.lib.util  import check_session
        
from linotp.lib.resolver import Resolver
from linotp.lib.resolver import splitResolver
from linotp.lib.resolver import getResolverList 
from linotp.lib.resolver import getResolver 
from linotp.lib.resolver import deleteResolver
from linotp.lib.resolver import reloadResolverConfig

from linotp.lib.error   import ParameterError

from linotp.lib.util    import getParam, getLowerParams
from linotp.lib.reply   import sendResult, sendError
from linotp.lib.realm   import getRealms
from linotp.lib.realm   import getDefaultRealm
from linotp.lib.user    import setRealm 
from linotp.lib.user    import getUserFromRequest

from linotp.lib.realm   import deleteRealm

from linotp.lib.policy  import checkPolicyPre
from linotp.lib.policy  import checkPolicyPost
from linotp.lib.policy  import PolicyException
 
from linotp.lib.policy  import getPolicy
from linotp.lib.policy  import deletePolicy 
from linotp.lib.policy  import getPolicyDefinitions


audit = config.get('audit')

import traceback
import logging
log = logging.getLogger(__name__)

optional = True
required = False


[docs]class SystemController(BaseController): ''' The linotp.controllers are the implementation of the web-API to talk to the LinOTP server. The SystemController is used to configure the LinOTP server. The functions of the SystemController are invoked like this https://server/system/<functionname> The functions are described below in more detail. ''' def __before__(self, action, **params): ''' Here we see, what action is to be called and check the authorization ''' # check authorization # FIXME: Although we return sendError, the actions are called! :-/ #try: # if "getRealms" != action: # checkPolicyPre('system', action ) #except PolicyException as pe: # log.debug("send error") # return sendError(response, str(pe)) log.debug("[__before__] done") audit.initialize() c.audit['success'] = False check_session() def __after__(self): c.audit['administrator'] = getUserFromRequest(request).get("login") audit.log(c.audit) ########################################################
[docs] def setDefault(self): """ method: system/set description: define default settings for tokens. These default settings are used when new tokens are generated. The default settings will not affect already enrolled tokens. arguments: DefaultMaxFailCount - Default value for the maximum allowed authentication failures DefaultSyncWindow - Default value for the synchronization window DefaultCountWindow - Default value for the coutner window DefaultOtpLen - Default value for the OTP value length -- usuall 6 or 8 DefaultResetFailCount - Default value, if the FailCounter should be reset on successful authentication [True|False] returns: a json result with a boolean "result": true exception: if an error occurs an exception is serialized and returned """ res = {} count = 0 description = "setDefault: parameters are\ DefaultMaxFailCount\ DefaultSyncWindow\ DefaultCountWindow\ DefaultOtpLen\ DefaultResetFailCount\ " keys = [ "DefaultMaxFailCount", "DefaultSyncWindow", "DefaultCountWindow", "DefaultOtpLen", "DefaultResetFailCount"] param = getLowerParams(request.params) log.info("[setDefault] saving default configuration: %s" % str(param)) ### config settings from here try: checkPolicyPre('system', "setDefault" ) for k in keys: if param.has_key(k.lower()): value = getParam(param,k.lower(),required) ret = storeConfig(k,value) des = "set " + k res[des]=ret count = count +1 c.audit['success'] = count c.audit['info'] += "%s=%s, " % (k, value) if count == 0 : log.warning("[setDefault] Failed saving config. Could not find any known parameter. %s" % description) raise ParameterError(77,"Usage:" + description) Session.commit() except Exception, e : log.error('[setDefault] commit failed') Session.rollback() Session.close() return sendResult(response,"Commit failed: " + str(e),0) Session.close() return sendResult(response,res,1) ########################################################
[docs] def setConfig(self): """ method: system/setConfig description: set a configuration key arguments: key - generic Configuration entry name value - generic Configuration value returns: a json result with a boolean "result": true exception: if an error occurs an exception is serialized and returned """ res = {} param = request.params log.info("[setConfig] saving configuration: %s" % str(param)) try: checkPolicyPre('system', "setConfig" ) reloadResolvers = False if param.has_key("key"): key = getParam(param,"key", optional = False) val = getParam(param,"value",optional = False) typ = getParam(param,"type") des = getParam(param,"description") if val.find('resolver') > 0 : reloadResolvers = True ret = storeConfig(key,val,typ,des) string = "setConfig " + key res[string]=ret c.audit['success'] = True c.audit['info'] = "%s=%s" % (key, val) else: conf = {} for key in param: if key == 'session': continue val = getParam(param,key) if key.find('resolver') > 0 : reloadResolvers = True if key.startswith('linotp') == False: Key = 'linotp.' + key string = "setConfig " + key + ":" + val res[string]= True ## in case we have a resolver c.audit['success'] = True c.audit['info'] += "%s=%s, " % (key, val) conf[Key] = val updateConfig(conf) if reloadResolvers == True: reloadResolverConfig() Session.commit() except Exception, e: log.error("[setConfig] error saving config: %s" % str(e)) log.error("[setConfig] %s" % traceback.format_exc()) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ########################################################
[docs] def delConfig(self): """ method: system/delConfig description: delete a configuration key arguments: key - generic Configuration entry name returns: a json result with the deleted value exception: if an error occurs an exception is serialized and returned """ res = {} param = getLowerParams(request.params) log.info("[delConfig] with params: %s" % str(param) ) try: checkPolicyPre('system', "delConfig" ) key = getParam(param,"key",required) ret = removeFromConfig(key) string = "delConfig " + key res[string]=ret c.audit['success'] = ret c.audit['info'] = key Session.commit() except Exception, e: log.error("[delConfig] error deleting config: %s" % str(e)) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ######################################################## ########################################################
[docs] def getConfig(self): """ method: system/getConfig description: retrieve a configuration key. If no key is given, the complete configuration is returned arguments: key - generic Configuration entry name returns: a json result with the found value exception: if an error occurs an exception is serialized and returned """ res = {} param = getLowerParams(request.params) log.debug("[getConfig] with params: %s" % str(param) ) try: checkPolicyPre('system', "getConfig" ) ## if there is no parameter, we return them all if len(param) == 0: conf = getLinotpConfig() keys = conf.keys() keys.sort() for key in keys: if key.startswith("enclinotp."): continue if key.startswith("linotp."): Key = key[len("linotp."):] ty = type(conf.get(key)).__name__ if ty != 'str' and ty != 'unicode': if ty == 'datetime': res[Key] = str(conf.get(key)) else: res[Key] = conf.get(key) else: res[Key] = conf.get(key) c.audit['success'] = True c.audit['info'] = "complete config" else: key = getParam(param,"key",required) ret = getFromConfig(key) string = "getConfig " + key res[string]=ret c.audit['success'] = ret c.audit['info'] = "config key %s" % key Session.commit() except Exception, e: log.error("[getConfig] error getting config: %s" % str(e)) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ########################################################
[docs] def getRealms(self): ''' 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. ''' param = getLowerParams(request.params) log.debug("[getRealms] with params: %s" % str(param) ) ### config settings from here try: 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 = checkPolicyPost('system', 'getRealms', { 'realms' : res } ) res = polPost['realms'] Session.commit() except Exception, e: log.error("[getRealms] error getting realms: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ########################################################
[docs] def setResolver(self): """ 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 = request.params log.info("[setResolver] saving configuration: %s" % str(param)) try: checkPolicyPre('system', "setResolver" ) resolver = Resolver() resolver.setDefinition(param) res = resolver.saveConfig() Session.commit() except Exception, e: log.error("[setResolver] error saving config: %s" % str(e)) log.error("[setRealm] %s" % traceback.format_exc()) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ########################################################
[docs] def getResolvers(self): """ 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 = {} log.debug("[getResolvers] calling functions getResolvers") #param = getLowerParams(request.params) ### config settings from here try: checkPolicyPre('system', "getResolvers" ) res = getResolverList() c.audit['success'] = True Session.commit() except Exception, e: log.error("[getResolvers] error getting resolvers: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ########################################################
[docs] def delResolver(self): """ 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 = {} param = getLowerParams(request.params) log.info("[delResolver] deleting resolver: %s" % str(param) ) try: checkPolicyPre('system', "delResolver" ) resolver = getParam(param,"resolver",required) ''' only delete a resolver, if it is not used by any realm ''' found = False fRealms = [] realms = getRealms() for r in realms: info = realms.get(r) reso = info.get('useridresolver') '''print str(reso) ''' for idRes in reso: parts = idRes.split('.') if len(parts) == 4 and resolver == parts[3]: fRealms.append(r) found = True if found == True: c.audit['failed'] = res c.audit['info'] = 'Resolver ' + resolver + " still in use by the realms: " + str(fRealms) raise Exception('Resolver ' + resolver + ' still in use by the realms ' + str(fRealms) + ' !') res = deleteResolver(resolver) c.audit['success'] = res c.audit['info'] = resolver Session.commit() except Exception, e: log.error("[delResolver] error deleting resolver: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ########################################################
[docs] def getResolver(self): """ method: system/getResolver description: this function retrieves the definition of the resolver arguments: resolver - the name of the resolver returns: a json result with the configuration of a specified resolver exception: if an error occurs an exception is serialized and returned """ res = {} param = getLowerParams(request.params) log.debug("[getResolver] with param: %s" % str(param) ) ### config settings from here try: checkPolicyPre('system', "getResolver" ) resolver = getParam(param,"resolver",required) if (len(resolver) == 0): raise Exception ("[getResolver] missing resolver name") res = getResolver(resolver) c.audit['success'] = True c.audit['info'] = resolver Session.commit() except Exception, e: log.error("[getResolver] error getting resolver: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ######################################################## ########################################################
[docs] def setDefaultRealm(self): """ method: system/setDefaultRealm description: this function sets the given realm to the default realm arguments: realm - the name of the realm, that should be the default realm returns: a json result with a list of Realms exception: if an error occurs an exception is serialized and returned """ res = False param = getLowerParams(request.params) log.info("[setDefaultRealm] with param: %s" % str(param) ) try: checkPolicyPre('system', "setDefaultRealm" ) defRealm = getParam(param,"realm",optional) if None == defRealm: defRealm = "" defRealm = defRealm.lower().strip() res = setDefaultRealm(defRealm) if res == False and defRealm != "" : c.audit['info'] = "The realm %s does not exist" % defRealm c.audit['success'] = True c.audit['info'] = defRealm Session.commit() except Exception, e: log.error("[setDefaultRealm] setting default realm failed: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1)
[docs] def getDefaultRealm(self): """ method: system/getDefaultRealm description: this function returns the default realm arguments: ./. returns: a json description of the default realm exception: if an error occurs an exception is serialized and returned """ res = False try: checkPolicyPre('system', "setDefaultRealm" ) defRealm = getDefaultRealm() res = getRealms(defRealm) c.audit['success'] = True c.audit['info'] = defRealm Session.commit() except Exception, e: log.error("[getDefaultRealm] return default realm failed: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ########################################################
[docs] def setRealm(self): """ 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 = "" param = request.params log.info("[setRealm] setting a realm: %s" % str(param) ) try: checkPolicyPre('system', "setRealm" ) realm = getParam(param,"realm",required) resolv = getParam(param,"resolvers",required) splitResolver(resolv) res = setRealm(realm,resolv) c.audit['success'] = res c.audit['info'] = "realm: %s, resolvers: %s" % ( realm, resolv) Session.commit() except Exception, e: log.error("[setRealm] setting realm failed: %s" % str(e) ) log.error("[setRealm] %s" % traceback.format_exc()) Session.rollback() Session.close() err = "Failed to set realm realm " + realm + " with resolvers "+resolv +" : " + str(e) return sendError(response,err,0) Session.close() return sendResult(response,res,1) ########################################################
[docs] def delRealm(self): """ method: system/delRealm description: this function deletes the given realm arguments: realm - the name of the realm to be deleted returns: a json result if deleting the realm was successful exception: if an error occurs an exception is serialized and returned """ res = {} param = request.params log.info("[delRealm] deleting realm: %s " % str(param) ) try: checkPolicyPre('system', "delRealm" ) realm = getParam(param,"realm",required) ''' we test if before delete there has been a default if yes - check after delete, if still one there and set the last available to default ''' defRealm = getDefaultRealm() hadDefRealmBefore = False if defRealm != "": hadDefRealmBefore = True ## now test if realm is defined if isRealmDefined(realm) == True: if realm.lower() == defRealm.lower(): setDefaultRealm("") if realm == "_default_": realmConfig = "useridresolver" else: realmConfig = "useridresolver.group." + realm res["delRealm"] = {"result":removeFromConfig(realmConfig,iCase=True)} ret = deleteRealm( realm ) if hadDefRealmBefore == True: defRealm = getDefaultRealm() if defRealm == "": realms = getRealms() if len(realms) == 1: for k in realms: setDefaultRealm(k) c.audit['success'] = ret c.audit['info'] = realm Session.commit() except Exception, e: log.error("[delRealm] error deleting realm: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ########################################################
[docs] def setPolicy(self): """ method: system/setPolicy description: Stores a policy that define ACL or behaviour of several different actions in LinOTP. The policy is stored as configuration values like this: Policy.<NAME>.action Policy.<NAME>.scope Policy.<NAME>.realm arguments: name: name of the policy action: which action may be executed scope: selfservice realm: This polcy holds for this realm user: (optional) This polcy binds to this user time: (optional) on which time does this policy hold client: (optional) for which requesting client this should be returns: a json result with success or error exception: if an error occurs an exception is serialized and returned """ log.debug("[setPolicy] params: %s" % request.params) res = {} param = request.params log.info("[setPolicy] setting policy: %s" % str(param) ) try: # check authorization checkPolicyPre('system', "setPolicy" ) name = getParam(param,"name",required) # check that the name does not contain a . if not re.match('^[a-zA-Z0-9_]*$',name): raise Exception ("The name of the policy may only contain the characters a-zA-Z0-9_") if ""==name: raise Exception ("The name of the policy must not be empty!") action = getParam(param,"action",required) scope = getParam(param,"scope",required) realm = getParam(param,"realm",required) user = getParam(param,"user",optional) time = getParam(param,"time",optional) client = getParam(param,"client",optional) log.debug("[setPolicy] saving policy %s: %s, %s, %s, %s, %s, %s" % (name, action, scope, realm, user, time, client) ) ret = {} ret["action"] = storeConfig("Policy.%s.action" % name,action,"","a policy defintion") ret["scope"] = storeConfig("Policy.%s.scope" % name,scope,"","a policy defintion") ret["realm"] = storeConfig("Policy.%s.realm" % name,realm,"","a policy defintion") ret["user"] = storeConfig("Policy.%s.user" % name,user,"","a policy defintion") ret["time"] = storeConfig("Policy.%s.time" % name,time,"","a policy defintion") ret["client"] = storeConfig("Policy.%s.client" % name,client,"","a policy defintion") log.debug("[setPolicy] policy %s successfully saved." % name) string = "setPolicy " + name res[string]=ret c.audit['action_detail'] = str(param) c.audit['success'] = True Session.commit() except Exception, e: log.error("[setPolicy] error saving policy: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1) ########################################################
[docs] def policies_flexi(self): ''' This function is used to fill the policies tab Unlike the complex /system/getPolcies function, it only returns a simple array of the tokens. ''' pol = {} param = getLowerParams(request.params) log.debug("[policies_flexi] viewing policies with params: %s" % str(param) ) ### config settings from here try: checkPolicyPre('system', "policies_flexi" ) name = getParam(param,"name",optional) realm = getParam(param,"realm",optional) scope = getParam(param,"scope",optional) sortname = getParam(param,"sortname",optional) sortorder = getParam(param,"sortorder",optional) log.debug("[policies_flexi] retrieving policy name: %s, realm: %s, scope: %s, sort:%s by %s" % (name, realm, scope, sortorder, sortname) ) pol = getPolicy({'name':name, 'realm':realm, 'scope': scope}) lines = [] for u in pol: lines.append( { 'id' : u, 'cell': [ u, (pol[u]['user']) if pol[u].has_key('user') else "", (pol[u]['scope']) if pol[u].has_key('scope') else "", (pol[u]['action']) if pol[u].has_key('action') else "", (pol[u]['realm']) if pol[u].has_key('realm') else "", (pol[u]['client']) if pol[u].has_key('client') else "", (pol[u]['time']) if pol[u].has_key('time') else "" ] } ) # sorting reverse=False sortnames = { 'name' : 0, 'user' : 1, 'scope' : 2, 'action' : 3, 'realm' : 4, 'client':5, 'time' : 6 } if sortorder == "desc": reverse= True lines = sorted( lines, key=lambda policy: policy['cell'][sortnames[sortname]] , reverse=reverse ) # end: sorting # We need to return 'page', 'total', 'rows' res = { "page": 1, "total": len(lines), "rows": lines } c.audit['success'] = True c.audit['info'] = "name = %s, realm = %s, scope = %s" % (name, realm, scope) Session.commit() except Exception, e: Session.rollback() Session.close() return sendError(response,e) Session.close() response.content_type = 'application/json' return simplejson.dumps(res,indent=3)
[docs] def getPolicyDef(self): ''' method: system/getPolicyDef description: This is a helper function that returns the POSSIBLE policy definitions, that can be used to define your policies. arguments: scope - optional - if given, the function will only return policy definitions for the given scope. returns: the policy definitions of - allowed scopes - allowed actions in scopes - type of actions exception: if an error occurs an exception is serialized and returned ''' pol= {} param = getLowerParams(request.params) log.debug("[getPolicy] getting policy defintions") ### config settings from here try: scope = getParam(param,"scope",optional) pol = getPolicyDefinitions( scope ) c.audit['success'] = True c.audit['info'] = scope Session.commit() except Exception, e: log.error("[getPolicyDef] error getting policy definitions: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,pol,1)
[docs] def getPolicy(self): """ method: system/getPolicy decsription: this function is used to retrieve the policies that you defined. arguments: realm - (optional) will return all policies in the given realm name - (optional) will only return the policy with the given name scope - (optional) will only return the policies within the given scope returns: a json result with the configuration of the specified policies exception: if an error occurs an exception is serialized and returned """ pol = {} param = getLowerParams(request.params) log.debug("[getPolicy] getting policy: %s" % str(param) ) ### config settings from here try: # check authorization checkPolicyPre('system', "getPolicy" ) name = getParam(param,"name",optional) realm = getParam(param,"realm",optional) scope = getParam(param,"scope",optional) log.debug("[getPolicy] retrieving policy name: %s, realm: %s, scope: %s" % (name, realm, scope) ) pol = getPolicy({'name':name, 'realm':realm, 'scope': scope}) c.audit['success'] = True c.audit['info'] = "name = %s, realm = %s, scope = %s" % (name, realm, scope) Session.commit() except Exception, e: log.error("[getPolicy] error getting policy: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,pol,1) ########################################################
[docs] def delPolicy(self): """ method: system/delPolicy description: this function deletes the policy with the given name arguments: name - the policy with the given name returns: a json result about the delete success exception: if an error occurs an exception is serialized and returned """ res = {} param = getLowerParams(request.params) log.info("[delPolicy] deleting policy: %s" % str(param)) ### config settings from here try: checkPolicyPre('system', "delPolicy" ) name = getParam(param,"name",required) log.debug("[delPolicy] trying to delete policy %s" % name ) ret = deletePolicy(name) res["delPolicy"] = {"result": ret } c.audit['success'] = ret c.audit['info'] = name Session.commit() except Exception, e: log.error("[delPolicy] error deleting policy: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1)
[docs] def registerResolverClass(self): """ method: system/registerResolverClass description: not yet implemented arguments: name - the resolver class name returns: a json result about the success exception: if an error occurs an exception is serialized and returned """ __methodName__ = 'registerResolverClass' # check authorization try: checkPolicyPre('system', __methodName__) except PolicyException as pe: return sendError(response, str(pe)) res = {} param = getLowerParams(request.params) log.info("[" + __methodName__ + "] parameters: %s" % str(param)) ### config settings from here try: className = getParam(param,"class",required) packageName = getParam(param,"package",required) log.debug("[" + __methodName__ + "] start register %s" % className ) ret = Resolver.registerClass(packageName,className) res[__methodName__] = {"result": ret } c.audit['success'] = ret c.audit['info'] = packageName + "." + className Session.commit() except Exception, e: log.error("[" + __methodName__ + "] error deleting policy: %s" % str(e) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1)
def setupSecurityModule(self): __methodName__ = 'setupSecurityModule' # check authorization try: #checkPolicyPre('system', __methodName__) pass except PolicyException as pe: return sendError(response, str(pe)) res = {} params = getLowerParams(request.params) log.debug("[" + __methodName__ + "] parameters: %s" % str(params)) ### config settings from here try: log.debug("[%s] : start setup" % ( __methodName__) ) hsm_id = params.get('hsm_id',None) from linotp.lib.config import getGlobalObject glo = getGlobalObject() sep = glo.security_provider if hsm_id == None: hsm_id = sep.activeOne hsm = c.hsm.get('obj') error = c.hsm.get('error') if hsm == None or len(error) != 0: raise Exception ('current activeSecurityModule >%s< is not initialized::%s:: - Please check your security module configuration and connection!' % (str(hsm_id),error)) ready = hsm.isReady() res[__methodName__] = {'activeSecurityModule': hsm_id , 'connected' : ready } ret = ready else: if hsm_id != sep.activeOne: raise Exception ('current activeSecurityModule >%s< could only be changed through the configuration!' % (str(sep.activeOne))) ret = sep.setupModule(hsm_id, config=params) hsm = c.hsm.get('obj') ready = hsm.isReady() res[__methodName__] = {'activeSecurityModule': hsm_id , 'connected' : ready , 'result' : ret} #res[__methodName__] = {"result": ret } c.audit['success'] = ret Session.commit() except Exception, e: log.error("[%s] : settup failed: %s" % (str(__methodName__),str(e)) ) Session.rollback() Session.close() return sendError(response,e) Session.close() return sendResult(response,res,1)