Exemple #1
0
def getLinotpConfig():

    '''
    return the thread local dict with all entries

    :return: local config dict
    :rtype: dict
    '''

    global linotp_config
    global linotp_config_tree

    # TODO: replication

    if linotp_config is None:
        refresh_config()

    if linotp_config_tree is None:
        linotp_config_tree = parse_config(linotp_config)

    ret = {}
    try:
        if not hasattr(c, 'linotpConfig'):
            c.linotpConfig = LinOtpConfig()

        ty = type(c.linotpConfig).__name__
        if ty != 'LinOtpConfig':
            try:
                c.linotpConfig = LinOtpConfig()
            except Exception as exx:
                log.exception("Could not add LinOTP configuration to pylons "
                              "tmpl_context. Exception was: %r", exx)
                raise exx
        ret = c.linotpConfig

        if ret.delay is True:
            if hasattr(c, 'hsm') is True and isinstance(c.hsm, dict):
                hsm = c.hsm.get('obj')
                if hsm is not None and hsm.isReady() is True:
                    ret = LinOtpConfig()
                    c.linotpConfig = ret

    except Exception as exx:
        log.debug("Bad Hack: Retrieving LinotpConfig without "
                  "controller context")
        ret = LinOtpConfig()

        if ret.delay is True:
            if hasattr(c, 'hsm') is True and isinstance(c.hsm, dict):
                hsm = c.hsm.get('obj')
                if hsm is not None and hsm.isReady() is True:
                    ret = LinOtpConfig()

    return ret
Exemple #2
0
def getLinotpConfig():

    '''
    return the thread local dict with all entries

    :return: local config dict
    :rtype: dict
    '''

    global linotp_config
    global linotp_config_tree

    # TODO: replication

    if linotp_config is None:
        refresh_config()

    if linotp_config_tree is None:
        linotp_config_tree = parse_config(linotp_config)

    ret = {}
    try:
        if not hasattr(c, 'linotpConfig'):
            c.linotpConfig = LinOtpConfig()

        ty = type(c.linotpConfig).__name__
        if ty != 'LinOtpConfig':
            try:
                c.linotpConfig = LinOtpConfig()
            except Exception as exx:
                log.exception("Could not add LinOTP configuration to pylons "
                              "tmpl_context. Exception was: %r", exx)
                raise exx
        ret = c.linotpConfig

        if ret.delay is True:
            if hasattr(c, 'hsm') is True and isinstance(c.hsm, dict):
                hsm = c.hsm.get('obj')
                if hsm is not None and hsm.isReady() is True:
                    ret = LinOtpConfig()
                    c.linotpConfig = ret

    except Exception as exx:
        log.debug("Bad Hack: Retrieving LinotpConfig without "
                  "controller context")
        ret = LinOtpConfig()

        if ret.delay is True:
            if hasattr(c, 'hsm') is True and isinstance(c.hsm, dict):
                hsm = c.hsm.get('obj')
                if hsm is not None and hsm.isReady() is True:
                    ret = LinOtpConfig()

    return ret
Exemple #3
0
def getLinotpConfig():
    """
    Get the complete configuration and store in context

    Calling this function results in a number of operations:
    * Retrieve the complete configuration from the database
    * Parse into a hierarchical format
    * Make available in application context (flap.config)

    The resulting class can be found under c.linotpConfig,
    but is more generally accessed using the symbol `config`:

    from linotp.flap import config
    foo = config['foo']

    :return: local config dict
    :rtype: dict
    """

    global linotp_config
    global linotp_config_tree

    # TODO: replication

    if linotp_config is None:
        # Read all the configuration from the database
        refresh_config()

    if linotp_config_tree is None:
        linotp_config_tree = parse_config(linotp_config)

    ret = {}
    try:
        if not hasattr(c, "linotpConfig"):
            c.linotpConfig = LinOtpConfig()

        ty = type(c.linotpConfig).__name__
        if ty != "LinOtpConfig":
            try:
                c.linotpConfig = LinOtpConfig()
            except Exception as exx:
                log.error(
                    "Could not add LinOTP configuration to Flask "
                    "application context. Exception was: %r",
                    exx,
                )
                raise exx
        ret = c.linotpConfig

        if ret.delay is True:
            if hasattr(c, "hsm") is True and isinstance(c.hsm, dict):
                hsm = c.hsm.get("obj")
                if hsm is not None and hsm.isReady() is True:
                    ret = LinOtpConfig()
                    c.linotpConfig = ret

    except Exception as exx:
        log.debug(
            "Bad Hack: Retrieving LinotpConfig without controller context")
        ret = LinOtpConfig()

        if ret.delay is True:
            if hasattr(c, "hsm") is True and isinstance(c.hsm, dict):
                hsm = c.hsm.get("obj")
                if hsm is not None and hsm.isReady() is True:
                    ret = LinOtpConfig()

    return ret