def update_policies(self):
     top_tenant_uuid = self._dao.tenant.find_top_tenant()
     logger.debug(
         'default_policies: found %s policies to apply',
         len(self._default_policies),
     )
     self.update_policies_for_tenant(top_tenant_uuid)
     commit_or_rollback()
Exemple #2
0
 def _on_message(self, event, success_cb, ws, msg):
     logger.debug('ws message received: %s', msg)
     try:
         msg = json.loads(msg)
         success_cb(msg)
         commit_or_rollback()
         self._bus_publisher.publish(event)
     finally:
         ws.close()
 def _on_message(self, message):
     logger.debug(
         "Confirmation has been received on websocketOAuth, message : {}.".
         format(message))
     msg = json.loads(message)
     if self.ws:
         self.ws.close()
         self.ws = None
     self.create_first_token(self.user_uuid, msg.get('code'))
     commit_or_rollback()
Exemple #4
0
 def _on_message(self, event, success_cb, ws, msg):
     logger.debug('ws message received: %s', msg)
     try:
         msg = json.loads(msg)
         success_cb(msg)
         commit_or_rollback()
         headers = {'tenant_uuid': event.tenant_uuid}
         self._bus_publisher.publish(event, headers=headers)
     finally:
         ws.close()
Exemple #5
0
 def _on_message(self, message):
     try:
         logger.debug(
             "Confirmation has been received on websocketOAuth, message : %s",
             message,
         )
         msg = json.loads(message)
         self.ws.close()
         self.create_first_token(self.user_uuid, msg.get('code'))
         commit_or_rollback()
     except Exception as e:
         logger.error('error when receiving websocket event %s', e)
Exemple #6
0
    def get_token(self):
        # get_token MUST be called before any DB operations during the HTTP request
        # otherwise previous changes will be committed event if an error occurs later
        if self._need_new_token():
            self._renew_time = time.time() + self._delay - self._threshold
            self._token = self._token_service.new_token_internal(
                expiration=self._delay,
                acl=self._acl,
            )
            commit_or_rollback()

        return self._token.token
Exemple #7
0
    def update_policies(self):
        top_tenant_uuid = self._dao.tenant.find_top_tenant()
        tenants = self._dao.tenant.list_visible_tenants(top_tenant_uuid)
        tenant_uuids = [tenant.uuid for tenant in tenants]
        logger.debug(
            'all_users: found %s policies to apply to all users of %s tenants',
            len(self._all_users_policies),
            len(tenants),
        )
        policies = self.find_policies()
        for tenant_uuid in tenant_uuids:
            self.associate_policies_for_tenant(tenant_uuid, policies)

        commit_or_rollback()
Exemple #8
0
    def get_token(self):
        # get_token MUST be called before any DB operations during the HTTP request
        # otherwise previous changes will be commited event if an error occurs later
        if self._need_new_token():
            if not self._user_exists(self._username):
                logger.info('%s user not found no local token will be created',
                            self._username)
                return

            self._renew_time = time.time() + self._delay - self._threshold
            self._token = self._new_token({
                'expiration': 3600,
                'backend': 'wazo_user',
                'user_agent': '',
                'remote_addr': '127.0.0.1',
            })
            commit_or_rollback()

        return self._token.token
Exemple #9
0
def create_initial_user(db_uri, username, password, purpose, policy_name):
    init_db(db_uri)
    dao = queries.DAO.from_defaults()
    tenant_tree = services.helpers.TenantTree(dao.tenant)
    policy_service = services.PolicyService(dao, tenant_tree)
    user_service = services.UserService(dao, tenant_tree)
    if user_service.verify_password(username, password):
        # Already bootstrapped, just skip
        return
    else:
        users = user_service.list_users(username=username)
        if users:
            raise Exception(
                "User {} already exists with different credential".format(username)
            )
        else:
            user = user_service.new_user(
                enabled=True, username=username, password=password, purpose=purpose
            )
            policy_uuid = policy_service.list(name=policy_name)[0]['uuid']
            user_service.add_policy(user['uuid'], policy_uuid)
    commit_or_rollback()
Exemple #10
0
def init_top_tenant(dao):
    top_tenant_uuid = dao.tenant.find_top_tenant()
    commit_or_rollback()
    app.config['top_tenant_uuid'] = top_tenant_uuid
    logger.debug('Initiated top tenant UUID: %s', top_tenant_uuid)
 def delete_orphan_policies(self):
     policies = self._dao.policy.list_(read_only=True)
     for policy in policies:
         if policy.slug not in self._default_policies:
             self._delete_policy(policy.uuid)
     commit_or_rollback()