Beispiel #1
0
def router(conf, session_key, zcml, dsn, name):
    allowed = ('de',)
    register_allowed_languages(allowed)
    config.ALLOWED_LANGUAGES = None

    load_zcml(zcml)

    setSecurityPolicy(GenericSecurityPolicy)

    # We register our SQLengine under a given name
    engine = create_engine(dsn, name)
    # We use a declarative base, if it exists we bind it and create
    engine.bind(Base)
    metadata = Base.metadata
    metadata.create_all(engine.engine, checkfirst=True)

    # Router
    root = URLMap()
    admin_app = Admin(session_key, engine, name)
    root['/admin'] = localize(admin_app)
    root['/'] = localize(User(session_key, engine, name))

    root.__runner__ = admin_app.__runner__

    return root
Beispiel #2
0
    def create(cls, gc, session_key='session.key', dsn='sqlite://',
               name=None, base=None, store_root=None, store_prefix=None):

        if name is None:
            name = str(cls.__name__.lower())

        # We register our SQLengine under a given name
        engine = create_engine(dsn, name)

        # We use a declarative base, if it exists we bind it and create
        if base is not None:
            engine.bind(base)
            metadata = base.metadata
            metadata.create_all(engine.engine, checkfirst=True)

        if store_root is not None:
            fs_store = HttpExposedFileSystemStore(store_root, store_prefix)
        else:
            fs_store = None

        # Configuration object
        factory = namedtuple('Configuration', ('session_key', 'engine', 'name', 'fs_store'))
        configuration = factory(session_key, engine, name, fs_store)
        if cls.check_configuration is not None:
            errors = []
            for iface in cls.check_configuration:
                errors.extends(getValidationErrors(iface, configuration))
            if errors:
                raise RuntimeError('Errors occured: %s' % ', '.join(errors))

        app = cls(configuration)

        if store_root is not None:
            return fs_store.wsgi_middleware(app)
        return app
Beispiel #3
0
def messages_injector(app, global_conf, dburl, envkey):
    engine = create_engine(dburl, 'messages')
    Admin.metadata.create_all(engine.engine)

    def message_aware(environ, start_response):
        with SQLAlchemySession(engine) as session:
            messages = get_valid_messages(session)
        book = environ.setdefault(envkey, {})
        admin = book.setdefault('admin', [])
        admin.extend(messages)
        return app(environ, start_response)

    return message_aware
Beispiel #4
0
def routing(conf, files, **kwargs):
    languages = kwargs['langs']
    allowed = languages.strip().replace(',', ' ').split()
    allowed = ('de',)
    register_allowed_languages(allowed)

    load_zcml(kwargs['zcml'])

    setSecurityPolicy(GenericSecurityPolicy)
    name = kwargs.get('name', 'school')

    # We register our SQLengine under a given name
    if not 'engine' in kwargs:
        dsn = kwargs['dsn']    
        engine = create_engine(dsn, name)
    else:
        engine = EngineServer(kwargs['engine'], name)

    # We use a declarative base, if it exists we bind it and create
    engine.bind(Base)
    metadata = Base.metadata
    metadata.create_all(engine.engine, checkfirst=True)

    # Extract possible layer
    layer = kwargs.get('layer')
    if layer is not None:
        layer_iface = eval_loader(layer)
    else:
        layer_iface = None

    title = kwargs.get('title', 'BG ETEM')

    # We create the session wrappper
    session_key = "session"
    key = key_from_file(path.join(kwargs['root'], 'jwt.key'))
    session_wrapper = Session(key, 60, environ_key=session_key)

    # Applications configuration
    smtp = kwargs.get('smtp', '10.33.115.55')
    setup = Configuration(
        title, session_key, engine, name, None, layer_iface, smtp)

    # Router
    root = URLMap()
    quizz = localize(anonymous.Application(setup))
    root['/'] = localize(company.Application(setup))
    root['/register'] = localize(company.Registration(setup))
    root['/quizz'] = quizz
    root['/befragung'] = quizz
    root['/json'] = localize(remote.Application(setup))
    return session_wrapper(root.__call__)
Beispiel #5
0
def Application(conf, dsn, accesses, zcml_file, ticket_ttl):

    ### Database
    # Bootstrap the SQL connection
    engine = create_engine(dsn, 'trilith')
    Base.metadata.bind = engine.engine
    with SQLAlchemySession(engine) as s:
        Base.metadata.create_all()

    # Create storages
    users = Users(engine)
    tokens = Tokens(engine)
    grants = Grants(engine)
    clients = Clients(engine)

    ### OAuth2 Machinery
    # Request Validator & Endpoints
    validator = OAuth2RequestValidator(
        clients=clients,
        tokens=tokens,
        grants=grants,
        users=users,
    )

    ## Endpoints
    auth_grant = AuthorizationCodeGrant(validator)
    bearer = BearerToken(validator, uuid4_token, int(ticket_ttl), uuid4_token)
    credentials_grant = ClientCredentialsGrant(validator)
    implicit_grant = ImplicitGrant(validator)
    password_grant = ResourceOwnerPasswordCredentialsGrant(validator)
    refresh_grant = RefreshTokenGrant(validator)

    ### WSGI
    # Routing
    router = URLMap()
    router['/oauth2/cashier'] = ticket.ATM(
        auth_grant, password_grant, credentials_grant, refresh_grant, bearer)
    router['/oauth2/sentinel'] = check.Defender(bearer)
    router['/oauth2/shredder'] = discard.Discarder(validator)
    router['/oauth2/bouncer'] = authorization.Bouncer(
        auth_grant, implicit_grant, bearer)
    router['/manage'] = manager(
        accesses, zcml_file, users, clients, grants, tokens)

    return router
Beispiel #6
0
    def create(cls,
               gc,
               session_key='session.key',
               dsn='sqlite://',
               name=None,
               base=None,
               store_root=None,
               store_prefix=None):

        if name is None:
            name = str(cls.__name__.lower())

        # We register our SQLengine under a given name
        engine = create_engine(dsn, name)

        # We use a declarative base, if it exists we bind it and create
        if base is not None:
            engine.bind(base)
            metadata = base.metadata
            metadata.create_all(engine.engine, checkfirst=True)

        if store_root is not None:
            fs_store = HttpExposedFileSystemStore(store_root, store_prefix)
        else:
            fs_store = None

        # Configuration object
        factory = namedtuple('Configuration',
                             ('session_key', 'engine', 'name', 'fs_store'))
        configuration = factory(session_key, engine, name, fs_store)
        if cls.check_configuration is not None:
            errors = []
            for iface in cls.check_configuration:
                errors.extends(getValidationErrors(iface, configuration))
            if errors:
                raise RuntimeError('Errors occured: %s' % ', '.join(errors))

        app = cls(configuration)

        if store_root is not None:
            return fs_store.wsgi_middleware(app)
        return app
auth_users = {
    'admin': 'admin',
}

if not os.path.isfile(CONF):
    raise RuntimeError('Configuration file does not exist.')

with open(CONF, "r") as fd:
    config = json.load(fd)


# Database
from gatekeeper.admin import Messages
from cromlech.sqlalchemy import create_engine

engine = create_engine(config['db']['uri'], config['db']['key'])
engine.bind(Messages)
Messages.metadata.create_all()


# Login
from gatekeeper.login.models import LoginRoot

class LoginRoot(LoginRoot):
    displayMessages = True

    def __init__(self, engine, domain, pubkey, dest):
        self.engine = engine
        self.domain = domain
        self.pkey = pubkey
        self.dest = dest
Beispiel #8
0
CONF = 'config.json'
auth_users = {
    'admin': 'admin',
}

if not os.path.isfile(CONF):
    raise RuntimeError('Configuration file does not exist.')

with open(CONF, "r") as fd:
    config = json.load(fd)

# Database
from gatekeeper.admin import Messages
from cromlech.sqlalchemy import create_engine

engine = create_engine(config['db']['uri'], config['db']['key'])
engine.bind(Messages)
Messages.metadata.create_all()

# Login
from gatekeeper.login.models import LoginRoot


class LoginRoot(LoginRoot):
    displayMessages = True

    def __init__(self, engine, domain, pubkey, dest):
        self.engine = engine
        self.domain = domain
        self.pkey = pubkey
        self.dest = dest