示例#1
0
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp()

    # Routing/Session/Cache Middleware
    app = RoutesMiddleware(app, config['routes.map'])
    app = SessionMiddleware(app, config)
    app = CacheMiddleware(app, config)

    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    from repoze.who.config import make_middleware_with_config
    app = make_middleware_with_config(app, global_conf,
            app_conf['who.config_file'], app_conf['who.log_file'],
            app_conf['who.log_level'])

    if asbool(full_stack):
        # Handle Python exceptions
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (and
        # 500 when debug is disabled)
        if asbool(config['debug']):
            app = StatusCodeRedirect(app)
        else:
            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])

    return app
示例#2
0
def make_auth_middleware(wrap, global_conf, **app_conf):
    from repoze.who.config import make_middleware_with_config
    wrap = make_middleware_with_config(wrap, global_conf,
            app_conf['who.config_file'],
            app_conf['who.log_file'],
            app_conf['who.log_level'])
    return wrap
示例#3
0
def make_auth_middleware(wrap, global_conf, **app_conf):
    from repoze.who.config import make_middleware_with_config
    wrap = make_middleware_with_config(wrap, global_conf,
                                       app_conf['who.config_file'],
                                       app_conf['who.log_file'],
                                       app_conf['who.log_level'])
    return wrap
示例#4
0
def make_app(global_conf, full_stack=True, **app_conf):
    """
    Set repoze-ldap-app up with the settings found in the PasteDeploy configuration
    file used.
    
    :param global_conf: The global settings for repoze-ldap-app (those
        defined under the ``[DEFAULT]`` section).
    :type global_conf: dict
    :param full_stack: Should the whole TG2 stack be set up?
    :type full_stack: str or bool
    :return: The repoze-ldap-app application with all the relevant middleware
        loaded.
    
    This is the PasteDeploy factory for the repoze-ldap-app application.
    
    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.
    
   
    """
    app = make_base_app(global_conf, full_stack=True, **app_conf)
    
    # Wrap your base TurboGears 2 application with custom middleware here
    app = make_middleware_with_config(
        app, global_conf,
        app_conf['who.config_file'],
        app_conf['who.log_stream'],
        app_conf['who.log_level'])

    
    return app
示例#5
0
def make_app(global_conf, full_stack=True, **app_conf):
    """
    Set turbotequila up with the settings found in the PasteDeploy configuration
    file used.
    
    :param global_conf: The global settings for turbotequila (those
        defined under the ``[DEFAULT]`` section).
    :type global_conf: dict
    :param full_stack: Should the whole TG2 stack be set up?
    :type full_stack: str or bool
    :return: The turbotequila application with all the relevant middleware
        loaded.
    
    This is the PasteDeploy factory for the turbotequila application.
    
    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.
    
   
    """
    app = make_base_app(global_conf, full_stack=True, **app_conf)
    
    # Wrap your base TurboGears 2 application with custom middleware here
    # This custom middleware is about authentication
    app = make_middleware_with_config(
        app,
        global_conf,
        app_conf.get('who.config_file','who.ini'),
        app_conf.get('who.log_file','auth.log'),
        app_conf.get('who.log_level','debug')
    )
    
    return app
示例#6
0
def make_app(global_conf, full_stack=True, **app_conf):
    """
    Set turbotequila up with the settings found in the PasteDeploy configuration
    file used.
    
    :param global_conf: The global settings for turbotequila (those
        defined under the ``[DEFAULT]`` section).
    :type global_conf: dict
    :param full_stack: Should the whole TG2 stack be set up?
    :type full_stack: str or bool
    :return: The turbotequila application with all the relevant middleware
        loaded.
    
    This is the PasteDeploy factory for the turbotequila application.
    
    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.
    
   
    """
    app = make_base_app(global_conf, full_stack=True, **app_conf)

    # Wrap your base TurboGears 2 application with custom middleware here
    # This custom middleware is about authentication
    app = make_middleware_with_config(
        app, global_conf, app_conf.get('who.config_file', 'who.ini'),
        app_conf.get('who.log_file', 'auth.log'),
        app_conf.get('who.log_level', 'debug'))

    return app
示例#7
0
def init_midgard_authentication(app, global_conf, app_conf):
    if config["midgard.authentication.enabled"]:
        from repoze.who.config import make_middleware_with_config
        
        app = make_middleware_with_config(app, global_conf, config['who.config_file'], config['who.log_file'], config['who.log_level'])
    
    return app
示例#8
0
文件: app.py 项目: reuben/treestatus
def wsgiapp(config, **kwargs):
    config.update(kwargs)
    model.setup(config)
    status.setup(config)
    app.debug = config.get("debug")
    configfile = my_dir + "/who.ini"
    app.wsgi_app = make_middleware_with_config(app.wsgi_app, config, config.get("who_config", configfile))
    logging.basicConfig(level=logging.DEBUG)
    return app
示例#9
0
文件: app.py 项目: catlee/treestatus
def wsgiapp(config, **kwargs):
    config.update(kwargs)
    model.setup(config)
    status.setup(config)
    app.debug = config.get('debug')
    configfile = my_dir + "/who.ini"
    app.wsgi_app = make_middleware_with_config(
        app.wsgi_app, config, config.get('who_config', configfile))
    logging.basicConfig(level=logging.DEBUG)
    return app
示例#10
0
def make_app(global_conf, **app_conf):
    """
    PasteDeploy WSGI application factory.

    Called by PasteDeply (or a compatable WSGI application host) to create the
    example WSGI application.
    """
    app = RestishApp(root.Root())
    app = make_middleware_with_config(app, global_conf, 'who.ini')
    app = setup_environ(app, global_conf, app_conf)
    return app
示例#11
0
def main(global_conf, root, **settings):
    initdb(settings)
    setup_template_loader()

    app = get_matching_app(settings)

    # weiwei.auth
    setup_hasher(settings['weiwei.auth.hasher'])

    # repoze.who
    config_file = settings['who.config_file']
    return make_middleware_with_config(app, global_conf, config_file)
示例#12
0
def make_app(global_conf, full_stack=True, **app_conf):
    """
    Set biorepo up with the settings found in the PasteDeploy configuration
    file used.

    @param global_conf: The global settings for biorepo (those
        defined under the ``[DEFAULT]`` section).
    @type global_conf: dict
    @param full_stack: Should the whole TG2 stack be set up?
    @type full_stack: str or bool
    @return: The biorepo application with all the relevant middleware
        loaded.

    This is the PasteDeploy factory for the biorepo application.

    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.


    """
    #app = make_base_app(global_conf, full_stack=True, **app_conf)

    ####begin test
    inject_resources = True
    serve_resources = True
    if 'prefix' in app_conf:
        custom = lambda app: twc.make_middleware(
            app,
            serve_resources=serve_resources,
            inject_resources=inject_resources,
            script_name=app_conf['prefix'])
        print app_conf['prefix'], "------- prefix"
    else:
        custom = lambda app: twc.make_middleware(
            app,
            serve_resources=serve_resources,
            inject_resources=inject_resources)
        print "------ no prefix found"
    app = make_base_app(global_conf,
                        wrap_app=custom,
                        full_stack=True,
                        **app_conf)
    ####end test

    # Wrap your base TurboGears 2 application with custom middleware here
    # This custom middleware is about authentication
    app = make_middleware_with_config(
        app, global_conf, app_conf.get('who.config_file', 'who.ini'),
        app_conf.get('who.log_file', 'auth.log'),
        app_conf.get('who.log_level', 'debug'))

    return app
示例#13
0
def middleware_factory(app, realapp, configfile=None, **repozekw):
    if configfile is not None:
        from repoze.who.config import make_middleware_with_config
        global_config = dict(
            here = realapp.instance_dir
        )
        middleware = make_middleware_with_config(app, global_config, configfile)
    elif repozekw:
        from repoze.who.middleware import PluggableAuthenticationMiddleware
        middleware = PluggableAuthenticationMiddleware(app, **repozekw)
    else:
        raise ValueError('Must either provide a configuration file, or kw')
    return middleware
示例#14
0
def make_app(global_conf, full_stack=True, **app_conf):
    """
    Set biorepo up with the settings found in the PasteDeploy configuration
    file used.

    @param global_conf: The global settings for biorepo (those
        defined under the ``[DEFAULT]`` section).
    @type global_conf: dict
    @param full_stack: Should the whole TG2 stack be set up?
    @type full_stack: str or bool
    @return: The biorepo application with all the relevant middleware
        loaded.

    This is the PasteDeploy factory for the biorepo application.

    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.


    """
    #app = make_base_app(global_conf, full_stack=True, **app_conf)

    ####begin test
    inject_resources = True
    serve_resources = True
    if 'prefix' in app_conf:
        custom = lambda app: twc.make_middleware(app, serve_resources=serve_resources, inject_resources=inject_resources, script_name=app_conf['prefix'])
        print app_conf['prefix'], "------- prefix"
    else:
        custom = lambda app: twc.make_middleware(app, serve_resources=serve_resources, inject_resources=inject_resources)
        print "------ no prefix found"
    app = make_base_app(global_conf, wrap_app=custom, full_stack=True, **app_conf)
    ####end test

    # Wrap your base TurboGears 2 application with custom middleware here
    # This custom middleware is about authentication
    app = make_middleware_with_config(
        app,
        global_conf,
        app_conf.get('who.config_file', 'who.ini'),
        app_conf.get('who.log_file', 'auth.log'),
        app_conf.get('who.log_level', 'debug')
    )

    return app
示例#15
0
文件: sp.py 项目: datopian/pysaml2
    #logger.info(logging.Logger.manager.loggerDict)
    for regex, callback in urls:
        if user:
            match = re.search(regex, path)
            if match is not None:
                try:
                    environ['myapp.url_args'] = match.groups()[0]
                except IndexError:
                    environ['myapp.url_args'] = path
                return callback(environ, start_response, user)
        else:
            return not_authn(environ, start_response)
    return not_found(environ, start_response)


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

from repoze.who.config import make_middleware_with_config

app_with_auth = make_middleware_with_config(application, {"here": "."},
                                            './who.ini',
                                            log_file="repoze_who.log")

# ----------------------------------------------------------------------------
PORT = 8087

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    srv = make_server('localhost', PORT, app_with_auth)
    print "SP listening on port: %s" % PORT
    srv.serve_forever()
示例#16
0
文件: idp.py 项目: baijum/pysaml2
                try:
                    environ['myapp.url_args'] = match.groups()[0]
                except IndexError:
                    environ['myapp.url_args'] = path
                if logger: logger.info("callback: %s" % (callback,))
                return callback(environ, start_response, user, logger)
        else:
            if logger: logger.info("-- No USER --")
            return not_authn(environ, start_response, logger)
    return not_found(environ, start_response, logger)

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

from repoze.who.config import make_middleware_with_config

APP_WITH_AUTH = make_middleware_with_config(application, {"here":"."}, 
                        './who.ini', log_file="app.log")

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

if __name__ == '__main__':
    import sys
    from wsgiref.simple_server import make_server
    import logging
    LOG_FILENAME = "./idp.log"
    PORT = 8088
    
    logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG)    
    
    IDP = server.Server(sys.argv[1], log=logging, debug=1)
    SRV = make_server('localhost', PORT, APP_WITH_AUTH)
    print "IdP listening on port: %s" % PORT
示例#17
0
文件: sp.py 项目: howow/pysaml2
        logger.info("<application> PATH: %s" % path)
    for regex, callback in urls:
        if user:
            match = re.search(regex, path)
            if match is not None:
                try:
                    environ["myapp.url_args"] = match.groups()[0]
                except IndexError:
                    environ["myapp.url_args"] = path
                return callback(environ, start_response, user, logger)
        else:
            return not_authn(environ, start_response)
    return not_found(environ, start_response)


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

from repoze.who.config import make_middleware_with_config

app_with_auth = make_middleware_with_config(application, {"here": "."}, "./who.ini", log_file="sp.log")

# ----------------------------------------------------------------------------
PORT = 8087

if __name__ == "__main__":
    from wsgiref.simple_server import make_server

    srv = make_server("localhost", PORT, app_with_auth)
    print "SP listening on port: %s" % PORT
    srv.serve_forever()
示例#18
0
文件: sp.py 项目: Ratler/pysaml2
                try:
                    environ['myapp.url_args'] = match.groups()[0]
                except IndexError:
                    environ['myapp.url_args'] = path
                return callback(environ, start_response, user)
        else:
            return not_authn(environ, start_response)

    return not_found(environ, start_response)

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

from repoze.who.config import make_middleware_with_config

app_with_auth = make_middleware_with_config(application, {"here": "."},
                                            './who.ini',
                                            log_file="repoze_who.log")

# ----------------------------------------------------------------------------
PORT = 8087


if __name__ == '__main__':
    #make_metadata arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', dest='path', help='Path to configuration file.')
    parser.add_argument('-v', dest='valid', default="4",
                        help="How long, in days, the metadata is valid from the time of creation")
    parser.add_argument('-c', dest='cert', help='certificate')
    parser.add_argument('-i', dest='id',
                        help="The ID of the entities descriptor in the metadata")
示例#19
0
文件: idp.py 项目: evansd/pysaml2
                except IndexError:
                    environ["myapp.url_args"] = path
                if logger:
                    logger.info("callback: %s" % (callback,))
                return callback(environ, start_response, user, logger)
        else:
            if logger:
                logger.info("-- No USER --")
            return not_authn(environ, start_response, logger)
    return not_found(environ, start_response, logger)


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

from repoze.who.config import make_middleware_with_config

APP_WITH_AUTH = make_middleware_with_config(application, {"here": "."}, "./who.ini", log_file="repoze_who.log")

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

if __name__ == "__main__":
    import sys
    from wsgiref.simple_server import make_server

    PORT = 8088

    IDP = server.Server(sys.argv[1])
    SRV = make_server("localhost", PORT, APP_WITH_AUTH)
    print "IdP listening on port: %s" % PORT
    SRV.serve_forever()
示例#20
0
    def initAuthApp(self, application, metadataList, conf, secretFile, configfilePath=None):
        """
        Will add authentication middleware to the WSGI application.

        :param self:
        :param application: Function for main WSGI application
        :rtype : PluggableAuthenticationMiddleware
        :return:
        """

        self.CONST_SETUP = "/setup"
        self.CONST_SETUPSERVICE = "/setup/service"
        self.CONST_SETUPSTYLES = "/setup/styles"
        self.CONST_SAVESECRET = "/setup/SaveSecret"
        self.CONST_SETUPABOUT = "/setup/about"
        self.CONST_SETUPLOGUT = "/setup/logout"
        self.CONST_SESSION_USER = "******"

        self.CONST_KEY = "key"
        self.CONST_SECRET = "secret"

        if configfilePath is None:
            self.CONST_ROOT = os.path.dirname(os.path.abspath(__file__))
        else:
            self.CONST_ROOT = configfilePath

        self.CONST_AUTH_FILE = IdpSetupSp._instance.CONST_ROOT + "/auth.json"
        self.CONST_STATIC_FILE = IdpSetupSp._instance.CONST_ROOT + "/files/static/"
        self.CONST_STATIC_MAKO = IdpSetupSp._instance.CONST_ROOT + "/files/mako/"
        self.CONST_LOOKUP = TemplateLookup(directories=[self.CONST_STATIC_MAKO + 'templates', self.CONST_STATIC_MAKO + 'htdocs'],
                                           module_directory=self.CONST_STATIC_MAKO + 'modules',
                                           input_encoding='utf-8', output_encoding='utf-8')

        self.CONST_ONTS = {
            saml.NAMESPACE: saml,
            mdui.NAMESPACE: mdui,
            mdattr.NAMESPACE: mdattr,
            dri.NAMESPACE: dri,
            ui.NAMESPACE: ui,
            idpdisc.NAMESPACE: idpdisc,
            md.NAMESPACE: md,
            xmldsig.NAMESPACE: xmldsig,
            xmlenc.NAMESPACE: xmlenc
        }

        self.CONST_ATTRCONV = attribute_converter.ac_factory("attributemaps")


        try:
            xmlsec_path = get_xmlsec_binary(["/opt/local/bin"])
        except:
            try:
                xmlsec_path = get_xmlsec_binary(["/usr/local/bin"])
            except:
                xmlsec_path = '/usr/bin/xmlsec1'

        for metadata in metadataList:
            mds = MetadataStore(self.CONST_ONTS.values(), self.CONST_ATTRCONV, xmlsec_path,
                                disable_ssl_certificate_validation=True)
            mds.imp(metadata)
            for entityId in mds.keys():
                self.spKeyList.append(entityId)

        for key in conf:
            self.socialServiceKeyList.append(conf[key]["name"])

        self.secretFile = secretFile

        currentPath = os.path.dirname(os.path.abspath(__file__))
        lib_path = os.path.abspath(self.CONST_ROOT)
        sys.path.append(lib_path)
        DeclarativeAuth.getInstance(self.CONST_AUTH_FILE)
        app_with_auth = make_middleware_with_config(application, {"here": "."},
                                                    self.CONST_ROOT+'/who.ini',
                                                    log_file=self.CONST_ROOT+"/repoze_who.log")
        return app_with_auth
示例#21
0
 def filter(app):
     app.wsgi_app = make_middleware_with_config(
         app.wsgi_app, global_config, config_file, log_file=log_file)
     return app