Ejemplo n.º 1
0
def create_provider_config():
    """
    not used but implemented to generate templates of provider configs
    'contents' contains the ini file
    """
    from linotp.provider import Provider_types
    from linotp.provider import get_all_new_providers

    provider_config = {}
    for provider_type in list(Provider_types.keys()):

        providers = get_all_new_providers(provider_type,
                                          show_managed_config=True)

        provider_config[provider_type] = providers

    ini = ConfigParser()

    for provider_type, providers in list(provider_config.items()):
        for provider in list(providers.keys()):
            section = '%s:%s' % (provider_type, provider)
            ini.add_section(section)

            provider_config = providers.get(provider)
            for key, value in list(provider_config.items()):
                ini.set(section, key, value)

    output = io.StringIO()
    ini.write(output)
    contents = output.getvalue()
    output.close()
    return contents
Ejemplo n.º 2
0
def create_provider_config():
    """
    not used but implemented to generate templates of provider configs
    'contents' contains the ini file
    """
    from linotp.provider import Provider_types
    from linotp.provider import get_all_new_providers

    provider_config = {}
    for provider_type in Provider_types.keys():

        providers = get_all_new_providers(provider_type,
                                          show_managed_config=True)

        provider_config[provider_type] = providers

    ini = UConfigParser()

    for provider_type, providers in provider_config.items():
        for provider in providers.keys():
            section = '%s:%s' % (provider_type, provider)
            ini.add_section(section)

            provider_config = providers.get(provider)
            for key, value in provider_config.items():
                if isinstance(value, unicode):
                    value = value.encode('utf-8')

                ini.set(section, key, value)

    output = cStringIO.StringIO()
    ini.write(output)
    contents = output.getvalue()
    output.close()
    return contents
Ejemplo n.º 3
0
    def create_context(self, request, environment):
        """
        create the request context for all controllers
        """

        linotp_config = getLinotpConfig()

        # make the request id available in the request context
        request_context['RequestId'] = environment['REQUEST_ID']

        # a request local cache to get the user info from the resolver
        request_context['UserLookup'] = {}

        # a request local cache to get the resolver from user and realm
        request_context['UserRealmLookup'] = {}

        request_context['Config'] = linotp_config
        request_context['Policies'] = parse_policies(linotp_config)
        request_context['translate'] = translate

        request_context['CacheManager'] = self.cache

        request_context['Path'] = request.path

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

        # setup the knowlege where we are

        request_context['action'] = None
        request_context['controller'] = None

        path = request.path.strip().strip('/').split('/')

        if path[0]:
            request_context['controller'] = path[0]

        request_context['action'] = 'index' if len(path) == 1 else path[-1]

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

        initResolvers()

        client = None
        try:
            client = get_client(request=request)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['Client'] = client

        Audit = config['audit']
        request_context['Audit'] = Audit
        request_context['audit'] = Audit.initialize(request, client=client)

        authUser = None
        try:
            authUser = getUserFromRequest(request)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['AuthUser'] = authUser
        request_context['UserLookup'] = {}

        # ------------------------------------------------------------------ --
        # get the current resolvers

        resolvers = []
        try:
            resolvers = getResolverList(config=linotp_config)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['Resolvers'] = resolvers

        # ------------------------------------------------------------------ --
        # get the current realms

        realms = {}
        try:
            realms = getRealms()
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['Realms'] = realms

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

        defaultRealm = ""
        try:
            defaultRealm = getDefaultRealm(linotp_config)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['defaultRealm'] = defaultRealm

        # ------------------------------------------------------------------ --
        # load the providers

        from linotp.provider import Provider_types
        from linotp.provider import getProvider

        provider = {}
        for provider_type in list(Provider_types.keys()):
            provider[provider_type] = getProvider(provider_type)

        request_context['Provider'] = provider

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

        # setup the SecretKey for the elliptic curve if it is not already done
        # elliptic curve are working with one partition (0) which is one
        # public / private key pair

        partition = 0
        if 'SecretKey.Partition.%d' % partition not in linotp_config:
            init_key_partition(linotp_config, partition=partition)
Ejemplo n.º 4
0
    def create_context(self, request, environment):
        """
        create the request context for all controllers
        """

        linotp_config = getLinotpConfig()

        # make the request id available in the request context
        request_context['RequestId'] = environment['REQUEST_ID']

        # a request local cache to get the user info from the resolver
        request_context['UserLookup'] = {}

        # a request local cache to get the resolver from user and realm
        request_context['UserRealmLookup'] = {}

        request_context['Config'] = linotp_config
        request_context['Policies'] = parse_policies(linotp_config)
        request_context['translate'] = translate
        request_context['CacheManager'] = environment['beaker.cache']

        routes = environment.get('pylons.routes_dict', {})
        path = "/%s/%s" % (routes['controller'], routes['action'])
        request_context['Path'] = path

        request_context['hsm'] = self.hsm

        initResolvers()

        client = None
        try:
            client = get_client(request=request)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['Client'] = client

        request_context['Audit'] = Audit
        request_context['audit'] = Audit.initialize(request, client=client)

        authUser = None
        try:
            authUser = getUserFromRequest(request)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['AuthUser'] = authUser
        request_context['UserLookup'] = {}

        # ------------------------------------------------------------------ --
        # get the current resolvers

        resolvers = []
        try:
            resolvers = getResolverList(config=linotp_config)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['Resolvers'] = resolvers

        # ------------------------------------------------------------------ --
        # get the current realms

        realms = {}
        try:
            realms = getRealms()
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['Realms'] = realms

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

        defaultRealm = ""
        try:
            defaultRealm = getDefaultRealm(linotp_config)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r" % exx)

        request_context['defaultRealm'] = defaultRealm

        # ------------------------------------------------------------------ --
        # load the requesting user

        from linotp.useridresolver.UserIdResolver import (
            ResolverNotAvailable)

        requestUser = None
        try:
            requestUser = getUserFromParam(self.request_params)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r", exx)
        except (ResolverNotAvailable, NoResolverFound) as exx:
            log.error("Failed to connect to server %r", exx)

        request_context['RequestUser'] = requestUser

        # ------------------------------------------------------------------ --
        # load the providers

        from linotp.provider import Provider_types
        from linotp.provider import getProvider

        provider = {}
        for provider_type in Provider_types.keys():
            provider[provider_type] = getProvider(provider_type)

        request_context['Provider'] = provider

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

        # for the setup of encrypted data, we require the hsm is instatiated
        # and available in the request context

        if not self.secret_key:
            init_key_partition(linotp_config, partition=0)

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

        # copy some system entries from pylons
        syskeys = {
            "radius.nas_identifier": "LinOTP",
            "radius.dictfile": "/etc/linotp2/dictionary"
        }

        sysconfig = {}
        for key, default in syskeys.items():
            sysconfig[key] = config.get(key, default)

        request_context['SystemConfig'] = sysconfig
Ejemplo n.º 5
0
    def create_context(self, request, environment):
        """
        create the request context for all controllers
        """

        linotp_config = getLinotpConfig()  # SQL-based configuration

        # make the request id available in the request context
        request_context["RequestId"] = environment["REQUEST_ID"]

        # a request local cache to get the user info from the resolver
        request_context["UserLookup"] = {}

        # a request local cache to get the resolver from user and realm
        request_context["UserRealmLookup"] = {}

        request_context["Config"] = linotp_config
        request_context["Policies"] = parse_policies(linotp_config)
        request_context["PolicyDefinitions"] = {}

        request_context["CacheManager"] = self.cache

        request_context["Path"] = request.path

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

        # setup the knowlege where we are

        request_context["action"] = None
        request_context["controller"] = None

        path = request.path.strip().strip("/").split("/")

        if path[0]:
            request_context["controller"] = path[0]

        request_context["action"] = "index" if len(path) == 1 else path[-1]

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

        initResolvers()

        client = None
        try:
            client = get_client(request=request)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r", exx)

        request_context["Client"] = client

        flask_g.audit = self.audit_obj.initialize(request, client=client)

        authUser = None
        try:
            c_identity = get_jwt_identity()
            if c_identity:
                authUser = User(
                    login=c_identity["username"],
                    realm=c_identity.get("realm"),
                    resolver_config_identifier=c_identity[
                        "resolver"
                    ].rpartition(".")[-1],
                )
        except Exception as exx:
            log.error("Failed to identify jwt user: %r", exx)

        request_context["AuthUser"] = authUser

        request_context["UserLookup"] = {}

        # ------------------------------------------------------------------ --
        # get the current resolvers

        resolvers = []
        try:
            resolvers = getResolverList(config=linotp_config)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r", exx)

        request_context["Resolvers"] = resolvers

        # ------------------------------------------------------------------ --
        # get the current realms

        realms = {}
        try:
            realms = getRealms()
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r", exx)

        request_context["Realms"] = realms

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

        defaultRealm = ""
        try:
            defaultRealm = getDefaultRealm(linotp_config)
        except UnicodeDecodeError as exx:
            log.error("Failed to decode request parameters %r", exx)

        request_context["defaultRealm"] = defaultRealm

        # ------------------------------------------------------------------ --
        # load the providers

        from linotp.provider import Provider_types, getProvider

        provider = {}
        for provider_type in list(Provider_types.keys()):
            provider[provider_type] = getProvider(provider_type)

        request_context["Provider"] = provider

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

        # setup the SecretKey for the elliptic curve if it is not already done
        # elliptic curve are working with one partition (0) which is one
        # public / private key pair

        partition = 0
        if "SecretKey.Partition.%d" % partition not in linotp_config:
            init_key_partition(linotp_config, partition=partition)