Esempio n. 1
0
    def authenticate(self, user, password):
        if user is None:  # The user is already in DB, just need the password
            prev_user = self._localdb.get_username(self._remote.url)
            if prev_user is None:
                raise ConanException("User for remote '%s' is not defined" %
                                     self._remote.name)
            else:
                user = prev_user

        # Create a connection to the org
        organization_url, _ = self._get_organization_url_and_feed(self._remote)
        credentials = BasicAuthentication(user, password)
        connection = Connection(base_url=organization_url, creds=credentials)

        # Authenticate the connection
        try:
            connection.authenticate()
        except Exception as ex:
            raise AuthenticationException(ex)

        # Generate token
        token_raw_bytes = password.encode()
        token_bytes = base64.b64encode(token_raw_bytes)

        # Store result in DB
        remote_name, prev_user, user = update_localdb(
            self._local_db, user, token_bytes.decode(),
            self._sxor(user, password), self._remote)

        return remote_name, prev_user, user
Esempio n. 2
0
    def authenticate(self, user, password):
        if user is None:  # The user is already in DB, just need the passwd
            prev_user = self._localdb.get_username(self._remote.url)
            if prev_user is None:
                raise ConanException("User for remote '%s' is not defined" % self._remote.name)
            else:
                user = prev_user

        try:
            token = self._rest_client.authenticate(user, password)
        except UnicodeDecodeError:
            raise ConanException("Password contains not allowed symbols")

        # Store result in DB
        update_localdb(self._localdb, user, token, self._remote, self._user_io.out)
        return token
Esempio n. 3
0
    def authenticate(self, user, password):
        if user is None:  # The user is already in DB, just need the passwd
            prev_user = self._localdb.get_username(self._remote.url)
            if prev_user is None:
                raise ConanException("User for remote '%s' is not defined" %
                                     self._remote.name)
            else:
                user = prev_user

        try:
            token = self._rest_client.authenticate(user, password)
        except UnicodeDecodeError:
            raise ConanException("Password contains not allowed symbols")

        # Store result in DB
        update_localdb(self._localdb, user, token, self._remote,
                       self._user_io.out)
        return token
Esempio n. 4
0
    def _authenticate(self, remote, user, password):
        rest_client = self._get_rest_client(remote)
        if user is None:  # The user is already in DB, just need the password
            prev_user = self._localdb.get_username(remote.url)
            if prev_user is None:
                raise ConanException("User for remote '%s' is not defined" % remote.name)
            else:
                user = prev_user
        try:
            token, refresh_token = rest_client.authenticate(user, password)
        except UnicodeDecodeError:
            raise ConanException("Password contains not allowed symbols")

        # Store result in DB
        remote_name, prev_user, user = update_localdb(self._localdb, user, token, refresh_token,
                                                      remote)
        return remote_name, prev_user, user