OSM Internal Authentication Backend and leverages the RBAC model
"""
-__author__ = "Pedro de la Cruz Ramos <pdelacruzramos@altran.com>"
+__author__ = "Pedro de la Cruz Ramos <pdelacruzramos@altran.com>, " \
+ "Alfonso Tierno <alfonso.tiernosepulveda@telefoncia.com"
__date__ = "$06-jun-2019 11:16:08$"
-from authconn import Authconn, AuthException # , AuthconnOperationException
+from osm_nbi.authconn import Authconn, AuthException # , AuthconnOperationException
from osm_common.dbbase import DbException
-from base_topic import BaseTopic
+from osm_nbi.base_topic import BaseTopic
import logging
import re
self.logger = logging.getLogger("nbi.authenticator.internal")
- # Get Configuration
- # self.xxx = config.get("xxx", "default")
-
self.db = db
self.token_cache = token_cache
else:
raise
except AuthException:
- if self.config["global"].get("test.user_not_authorized"):
- return {"id": "fake-token-id-for-test",
- "project_id": self.config["global"].get("test.project_not_authorized", "admin"),
- "username": self.config["global"]["test.user_not_authorized"], "admin": True}
- else:
- raise
+ raise
except Exception:
self.logger.exception("Error during token validation using internal backend")
raise AuthException("Error during token validation using internal backend",
pass
except ValueError:
pass
- self.db.set_one("users", {BaseTopic.id_field("users", uid): uid}, user_data) # CONFIRM
+ idf = BaseTopic.id_field("users", uid)
+ self.db.set_one("users", {idf: uid}, user_data)
+ if user_info.get("remove_project_role_mappings"):
+ self.db.del_list("tokens", {"user_id" if idf == "_id" else idf: uid})
+ self.token_cache.clear()
def delete_user(self, user_id):
"""
:raises AuthconnOperationException: if user deletion failed.
"""
self.db.del_one("users", {"_id": user_id})
+ self.db.del_list("tokens", {"user_id": user_id})
+ self.token_cache.clear()
return True
def get_user_list(self, filter_q=None):