Пример #1
0
def set_logging_level(name, level):

    """
    sets the logging level in the database as well as
    in the current running logger

    :param name: Name of the logger
    :param level: New level (must be integer)
    """

    # --------------------------------------------------------------------------

    logger = logging.getLogger(name)
    logger.setLevel(level)

    # --------------------------------------------------------------------------

    config_entry = Session.query(LoggingConfig).get(name)

    if config_entry is None:
        new_config_entry = LoggingConfig(name, level)
        Session.add(new_config_entry)
        return

    config_entry.level = level
Пример #2
0
 def storeToken(self):
     log.debug('storeToken()')
     Session.add(self)
     Session.flush()
     Session.commit()
     log.debug('store token success')
     return True
Пример #3
0
def token_reporting(event, tokenrealms):
    """
    log token events into reporting table

    :param event: the event that happened, e.g. init token, delete token
    :param tokenrealms: the realm on which the event happened
    :return: nothing
    """
    realms = tokenrealms
    if not tokenrealms or len(tokenrealms) == 0:
        realms = ['/:no realm:/']
    elif not isinstance(tokenrealms, (list, tuple)):
        realms = [tokenrealms]

    for realm in realms:
        action = check_token_reporting(realm)
        mh = MonitorHandler()
        counters = mh.token_count(realm, action[:])
        for key, val in counters.items():
            report = Reporting(
                event=event, realm=realm, parameter=key, count=val)
            try:
                Session.add(report)
            except Exception as exce:
                log.exception('[save]Error during saving Report: %r' % exce)
Пример #4
0
def _storeConfigEntryDB(key, value, typ=None, desc=None):
    """
    lowest level for storing database entries in the config table
    """

    confEntries = Session.query(Config).filter(Config.Key == unicode(key))
    theConf = None

    # update
    if confEntries.count() == 1:
        theConf = confEntries[0]
        theConf.Value = unicode(value)
        if (typ is not None):
            theConf.Type = unicode(typ)
        if (desc is not None):
            theConf.Description = unicode(desc)

    # insert
    elif confEntries.count() == 0:
        theConf = Config(
                        Key=unicode(key),
                        Value=unicode(value),
                        Type=unicode(typ),
                        Description=unicode(desc)
                        )
    if theConf is not None:
        Session.add(theConf)

    return 101
Пример #5
0
def token_reporting(event, tokenrealms):
    """
    log token events into reporting table

    :param event: the event that happened, e.g. init token, delete token
    :param tokenrealms: the realm on which the event happened
    :return: nothing
    """
    realms = tokenrealms
    if not tokenrealms or len(tokenrealms) == 0:
        realms = ['/:no realm:/']
    elif not isinstance(tokenrealms, (list, tuple)):
        realms = [tokenrealms]

    for realm in realms:
        action = check_token_reporting(realm)
        mh = MonitorHandler()
        counters = mh.token_count(realm, action[:])
        for key, val in counters.items():
            report = Reporting(event=event,
                               realm=realm,
                               parameter=key,
                               count=val)
            try:
                Session.add(report)
            except Exception as exce:
                log.exception('Error during saving report. Exception was: '
                              '%r' % exce)
Пример #6
0
def _storeConfigEntryDB(key, value, typ=None, desc=None):
    """
    lowest level for storing database entries in the config table
    """

    confEntries = Session.query(Config).filter(Config.Key == unicode(key))
    theConf = None

    # update
    if confEntries.count() == 1:
        theConf = confEntries[0]
        theConf.Value = unicode(value)
        if (typ is not None):
            theConf.Type = unicode(typ)
        if (desc is not None):
            theConf.Description = unicode(desc)

    # insert
    elif confEntries.count() == 0:
        theConf = Config(
                        Key=unicode(key),
                        Value=unicode(value),
                        Type=unicode(typ),
                        Description=unicode(desc)
                        )
    if theConf is not None:
        Session.add(theConf)

    return 101
Пример #7
0
    def save(self):
        log.debug('save ocra challenge')

        Session.add(self)
        Session.flush()

        log.debug('save ocra challenge : success')
        return self.transid
Пример #8
0
    def storeRealm(self):
        if self.name is None:
            self.name = ''
        self.name = self.name.lower()

        Session.add(self)
        Session.flush()

        return True
Пример #9
0
    def storeRealm(self):
        if self.name is None:
            self.name = ''
        self.name = self.name.lower()

        Session.add(self)
        Session.flush()

        return True
Пример #10
0
 def storeRealm(self):
     if self.name is None:
         self.name = ''
     self.name = self.name.lower()
     log.debug('storeRealm()')
     Session.add(self)
     Session.commit()
     log.debug('store realm success')
     return True
Пример #11
0
 def storeRealm(self):
     if self.name is None:
         self.name = ''
     self.name = self.name.lower()
     log.debug('storeRealm()')
     Session.add(self)
     Session.commit()
     log.debug('store realm success')
     return True
Пример #12
0
    def storeToken(self):
        if self.LinOtpUserid is None:
            self.LinOtpUserid = u''
        if self.LinOtpIdResClass is None:
            self.LinOtpIdResClass = ''
        if self.LinOtpIdResolver is None:
            self.LinOtpIdResolver = ''

        Session.add(self)
        Session.flush()

        return True
Пример #13
0
    def storeToken(self):
        if self.LinOtpUserid is None:
            self.LinOtpUserid = u''
        if self.LinOtpIdResClass is None:
            self.LinOtpIdResClass = ''
        if self.LinOtpIdResolver is None:
            self.LinOtpIdResolver = ''

        Session.add(self)
        Session.flush()

        return True
Пример #14
0
    def storeToken(self):
        if self.LinOtpUserid is None:
            self.LinOtpUserid = u''
        if self.LinOtpIdResClass is None:
            self.LinOtpIdResClass = ''
        if self.LinOtpIdResolver is None:
            self.LinOtpIdResolver = ''

        log.debug('storeToken()')
        Session.add(self)
        Session.flush()
        Session.commit()
        log.debug('store token success')
        return True
Пример #15
0
    def storeToken(self):
        if self.LinOtpUserid is None:
            self.LinOtpUserid = u''
        if self.LinOtpIdResClass is None:
            self.LinOtpIdResClass = ''
        if self.LinOtpIdResolver is None:
            self.LinOtpIdResolver = ''

        log.debug('storeToken()')
        Session.add(self)
        Session.flush()
        Session.commit()
        log.debug('store token success')
        return True
Пример #16
0
    def save(self):
        '''
        enforce the saving of a challenge
        - will guarantee the uniqness of the transaction id

        :return: transaction id of the stored challenge
        '''
        try:
            Session.add(self)
            Session.flush()

        except Exception as exce:
            log.exception('[save]Error during saving challenge')

        return self.transid
Пример #17
0
    def save(self):
        '''
        enforce the saving of a challenge
        - will guarantee the uniqness of the transaction id

        :return: transaction id of the stored challenge
        '''
        try:
            Session.add(self)
            Session.flush()

        except Exception as exce:
            log.exception('[save]Error during saving challenge')

        return self.transid
Пример #18
0
    def storeToken(self):
        log.debug('storeToken()')

        if self.LinOtpUserid is None:
            self.LinOtpUserid = u''
        if self.LinOtpTokenDesc is None:
            self.LinOtpTokenDesc = u''
        if self.LinOtpTokenInfo is None:
            self.LinOtpTokenInfo = u''

        Session.add(self)
        Session.flush()
        Session.commit()
        log.debug('store token success')
        return True
Пример #19
0
    def save(self):
        '''
        enforce the saveing of a challenge
        - will guarentee the uniqness of the transaction id

        :return: transaction id of the stored challeng
        '''
        log.debug('[save] save challenge')
        try:
            Session.add(self)
            Session.commit()
            log.debug('save challenge : success')

        except Exception as exce:
            log.exception('[save]Error during saving challenge: %r' % exce)

        return self.transid
Пример #20
0
    def save(self):
        '''
        enforce the saving of a challenge
        - will guarantee the uniqness of the transaction id

        :return: transaction id of the stored challenge
        '''
        log.debug('[save] save challenge')
        try:
            Session.add(self)
            Session.commit()
            log.debug('save challenge : success')

        except Exception as exce:
            log.exception('[save]Error during saving challenge: %r' % exce)

        return self.transid
Пример #21
0
def set_config(key, value, typ, description=None):
    '''
    create an intial config entry, if it does not exist

    :param key: the key
    :param value: the value
    :param description: the description of the key

    :return: nothing
    '''

    count = Session.query(model.Config).filter(
                        model.Config.Key == "linotp." + key).count()

    if count == 0:
        config_entry = model.Config(key, value, Type=typ, Description=description)
        Session.add(config_entry)

    return
Пример #22
0
def set_config(key, value, typ, description=None):
    '''
    create an intial config entry, if it does not exist

    :param key: the key
    :param value: the value
    :param description: the description of the key

    :return: nothing
    '''

    count = Session.query(model.Config).filter(
                        model.Config.Key == "linotp." + key).count()

    if count == 0:
        config_entry = model.Config(key, value, Type=typ, Description=description)
        Session.add(config_entry)

    return
Пример #23
0
def _storeConfigDB(key, val, typ=None, desc=None):
    value = val
    log.debug('storeConfigDB: key %r : value %r' % (key, value))

    if (not key.startswith("linotp.")):
        key = "linotp." + key

    confEntries = Session.query(Config).filter(Config.Key == unicode(key))
    theConf = None

    if typ is not None and typ == 'password':
        value = encryptPassword(val)
        en = decryptPassword(value)
        if (en != val):
            raise Exception("StoreConfig: Error during encoding password type!")

    # # update
    if confEntries.count() == 1:
        theConf = confEntries[0]
        theConf.Value = unicode(value)
        if (typ is not None):
            theConf.Type = unicode(typ)
        if (desc is not None):
            theConf.Description = unicode(desc)

    # # insert
    elif confEntries.count() == 0:
        theConf = Config(
                        Key=unicode(key),
                        Value=unicode(value),
                        Type=unicode(typ),
                        Description=unicode(desc)
                        )
    if theConf is not None:
        Session.add(theConf)

    return 101
Пример #24
0
def _storeConfigDB(key, val, typ=None, desc=None):
    value = val
    log.debug('storeConfigDB: key %r : value %r' % (key, value))

    if (not key.startswith("linotp.")):
        key = "linotp." + key

    confEntries = Session.query(Config).filter(Config.Key == unicode(key))
    theConf = None

    if typ is not None and typ == 'password':
        value = encryptPassword(val)
        en = decryptPassword(value)
        if (en != val):
            raise Exception(
                "StoreConfig: Error during encoding password type!")

    # # update
    if confEntries.count() == 1:
        theConf = confEntries[0]
        theConf.Value = unicode(value)
        if (typ is not None):
            theConf.Type = unicode(typ)
        if (desc is not None):
            theConf.Description = unicode(desc)

    # # insert
    elif confEntries.count() == 0:
        theConf = Config(Key=unicode(key),
                         Value=unicode(value),
                         Type=unicode(typ),
                         Description=unicode(desc))
    if theConf is not None:
        Session.add(theConf)

    return 101
Пример #25
0
    def save(self):

        Session.add(self)
        Session.flush()

        return self.transid
Пример #26
0
    def save(self):

        Session.add(self)
        Session.flush()

        return self.transid
Пример #27
0
 def storeRealm(self):
     log.debug('storeRealm()')
     Session.add(self)
     Session.commit()
     log.debug('store realm success')
     return True
Пример #28
0
 def save(self):
     log.debug('save ocra challenge')
     Session.add(self)
     Session.commit()
     log.debug('save ocra challenge : success')
     return self.transid