Esempio n. 1
0
    def authenticate(self, request=None, username=None, password=None, controller_url=None):

        url = controller_url + settings.AUTH_PATH
        try:
            response = requests.get(url, auth=(username, password))
        except r_exceptions.ConnectionError as e:
            raise exceptions.BackendError("Backend unavailable")

        if response.status_code == 401:
            LOG.warning("Authentication failure...")
            raise exceptions.AuthError(
                "Invalid username or password. " "Please check your credentials " "and try again."
            )

        try:
            jsessionid = response.cookies.get("JSESSIONID")
            jsessionidsso = response.cookies.get("JSESSIONIDSSO")
            user = create_user_from_jsessionid(
                username=username, controller=controller_url, jsessionid=jsessionid, jsessionidsso=jsessionidsso
            )
        except Exception as e:
            print(e)
            raise

        if request is not None:
            request.user = user

        return user
Esempio n. 2
0
 def get_user(self, user_id):
     if hasattr(self, "request") and user_id == self.request.session["user_id"]:
         jsessionid = self.request.session["jsessionid"]
         jsessionidsso = self.request.session["jsessionidsso"]
         controller = self.request.session["controller_endpoint"]
         user = create_user_from_jsessionid(user_id, jsessionid, jsessionidsso, controller)
         return user
     else:
         return None