Пример #1
0
    def post(self, req, resp):
        request_object = req.json
        method = request_object.get('method', 'password')
        driver = g.app.config.get('auth', 'driver')
        driver = get_class(driver)()
        if hasattr(driver, method):
            method = getattr(driver, method)
        else:
            raise ValueError("'%s' authentication method not supported" %
                             method)

        credentials = request_object.get('credentials')
        username = request_object.get('username')
        domain = request_object.get('domain')
        if isinstance(credentials, dict):
            method(username, domain, credentials=credentials)
        elif credentials is None:
            raise ValueError("Require 'credentials'")
        else:
            raise ValueError("Invalid 'credentials' provided")

        # Creat User locally if not existing
        localize(self.realm, username, domain)
        # Get User_id
        user_id = get_user_id(self.realm, username, domain)
        # Get Roles
        roles = get_context_roles(user_id, domain)
        # Set roles in token
        req.credentials.new(user_id, username=username, domain=domain)
        req.credentials.roles = roles

        return req.credentials
Пример #2
0
    def session(self):
        if self._cached_session is None:
            expire = g.app.config.getint('sessions', 'expire', fallback=86400)
            backend = g.app.config.get(
                'sessions',
                'backend',
                fallback='luxon.core.session:SessionFile')
            backend = get_class(backend)
            session_id = g.app.config.get('sessions',
                                          'session',
                                          fallback='luxon.core.session:cookie')
            session_id = get_class(session_id)

            self._cached_session = Session(session_id,
                                           expire=expire,
                                           backend=backend)

        return self._cached_session
Пример #3
0
    def create_table(cls):
        if cls.primary_key is None:
            raise KeyError("Model %s:" % cls.name +
                           " No primary key") from None

        api = g.app.config.get('database', 'type')
        driver_cls = api.title()
        driver = get_class('luxon.structs.models.sql.%s:%s' %
                           (api, driver_cls,))(cls)
        driver.create()
Пример #4
0
    def create_table(cls):
        # NOTE(cfrademan):
        # This should not be a dependancy any more for models.
        # if cls.primary_key is None:
        #     raise KeyError("Model %s:" % cls.model_name +
        #                    " No primary key") from None

        api = g.app.config.get('database', 'type')
        driver_cls = api.title()
        driver = get_class('luxon.structs.models.sql.%s:%s' %
                           (api, driver_cls,))(cls)
        driver.create()
Пример #5
0
 def pre(self, req, resp):
     driver = g.app.config.get('tokens', 'driver')
     expire = g.app.config.getint('tokens', 'expire')
     req.context.token = get_class(driver)(expire)
     token = req.get_header('X-Auth-Token')
     if token is not None:
         req.context.token.parse_token(token)
         req.context.domain = req.context.token.token['domain']
         req.context.domain_id = req.context.token.token['domain_id']
         req.context.tenant_id = req.context.token.token['tenant_id']
         req.context.roles = req.context.token.token['roles']
     else:
         req.context.domain = None
         req.context.domain_id = None
         req.context.tenant_id = None
         req.context.roles = []
Пример #6
0
 def __init__(self):
     max_objects = g.app.config.getint('cache', 'max_objects')
     max_object_size = g.app.config.getint('cache', 'max_object_size')
     self._cached_backend = get_class(g.app.config.get('cache', 'backend'))(
         max_objects, max_object_size)