Beispiel #1
0
def ldap_process(request):
    """Initiate a ldap login"""
    config = request.registry.settings
    urls = splitlines(config['velruse.providers.ldapprovider.urls'])
    bdn = config['velruse.providers.ldapprovider.basedn']
    verified_login = False
    username = request.POST.get('ldap_username', request.POST.get('username', ''))
    password = request.POST.get('ldap_password', request.POST.get('password', ''))
    ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
    dn = bdn.replace('%LOGIN%', username)
    data = {}
    if urls:
        for url in urls:
            try:
                # We have suceed to connect, break the loop
                con = ldap.initialize(url)
                bind = con.simple_bind_s(dn, password)
                verified_login = True
                items = con.search_s(dn,ldap.SCOPE_SUBTREE)
                if items:
                    for item in items:
                        if item[0] == dn:
                            data = item[1]
                            break
            except Exception, e:
                pass
Beispiel #2
0
def includeme(config):
    """Configuration function to make a pyramid app a velruse one."""
    settings = config.registry.settings

    # setup application
    setup = settings.get("velruse.setup", default_setup)
    if setup:
        config.include(setup)

    if not settings.get("velruse.end_point"):
        raise ConfigurationError('missing required setting "velruse.end_point"')

    # setup backing storage
    store = settings.get("velruse.store")
    if store is None:
        raise ConfigurationError("invalid setting velruse.store: {0}".format(store))
    config.include(store)

    # include providers
    providers = settings.get("velruse.providers", "")
    providers = splitlines(providers)

    for provider in providers:
        config.include(provider)
    # add the error views
    config.scan(__name__)
Beispiel #3
0
def ldap_process(request):
    """Initiate a ldap login"""
    config = request.registry.settings
    urls = splitlines(config['velruse.providers.ldapprovider.urls'])
    bdn = config['velruse.providers.ldapprovider.basedn']
    verified_login = False
    username = request.POST.get('ldap_username',
                                request.POST.get('username', ''))
    password = request.POST.get('ldap_password',
                                request.POST.get('password', ''))
    ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
    dn = bdn.replace('%LOGIN%', username)
    data = {}
    if urls:
        for url in urls:
            try:
                # We have suceed to connect, break the loop
                con = ldap.initialize(url)
                bind = con.simple_bind_s(dn, password)
                verified_login = True
                items = con.search_s(dn, ldap.SCOPE_SUBTREE)
                if items:
                    for item in items:
                        if item[0] == dn:
                            data = item[1]
                            break
            except Exception, e:
                pass
Beispiel #4
0
def make_app(**settings):
    config = Configurator(settings=settings)

    # setup application
    setup = settings.get('velruse.setup', default_setup)
    config.include(setup)

    if not settings.get('velruse.endpoint'):
        raise ConfigurationError(
            'missing required setting "velruse.endpoint"')

    # setup backing storage
    store = settings.get('velruse.store')
    if store is None:
        raise ConfigurationError(
            'invalid setting velruse.store: {0}'.format(store))
    config.include(store)

    # include providers
    providers = settings.get('velruse.providers', '')
    providers = splitlines(providers)

    for provider in providers:
        config.include(provider)

    # add the error views
    config.scan(__name__)
    return config.make_wsgi_app()
Beispiel #5
0
def includeme(config):
    settings = config.registry.settings
    servers = splitlines(settings.get('velruse.store.servers', ''))
    key_prefix = settings.get('velruse.store.key_prefix', 'velruse_ustore')

    if not servers:
        raise ConfigurationError('Missing "velruse.store.servers" setting')

    store = MemcachedStore(servers=servers, key_prefix=key_prefix)
    config.registry.velruse_store = store
Beispiel #6
0
def includeme(config):
    settings = config.registry.settings
    servers = splitlines(settings.get('velruse.store.servers', ''))
    key_prefix = settings.get('velruse.store.key_prefix', 'velruse_ustore')

    if not servers:
        raise ConfigurationError('Missing "velruse.store.servers" setting')

    store = MemcachedStore(servers=servers, key_prefix=key_prefix)
    config.registry.velruse_store = store
Beispiel #7
0
def providers_lookup(config):
    """Lookup for the providers to activate
    Can be overridden by settings
    velruse.providers_lookup = mymodule.hook
    This can be useful for example if your authentication information
    is stored on a relational database.
    """
    settings = config.registry.settings
    providers_hook = settings.get('velruse.providers_hook', '')
    if providers_hook:
        providers_hook = config.maybe_dotted(providers_hook)
        providers_hook(config)
    providers = []
    for a in splitlines(
        settings.get('velruse.providers', '')
    ):
        providers.append(a)
        settings['velruse.providers_infos'][a] = {}
    return providers