예제 #1
0
def perform_auth_for_handler(protocol, manager, host, port, session_token):
    # Before actually communicating with the server,
    # we need to check authentication first.
    auth_client = authentication_helper.ThriftAuthHelper(
        protocol, host, port, '/v' + CLIENT_API + '/Authentication',
        session_token)
    check_api_version(auth_client)

    try:
        auth_response = auth_client.getAuthParameters()
    except TApplicationException:
        auth_response = AuthTypes.HandshakeInformation()
        auth_response.requiresAuthentication = False

    if auth_response.requiresAuthentication and \
            not auth_response.sessionStillActive:
        print_err = False

        if manager.is_autologin_enabled():
            auto_auth_string = manager.get_auth_string(host, port)
            if auto_auth_string:
                LOG.info("Logging in using pre-configured credentials...")

                username = auto_auth_string.split(':')[0]
                check_preconfigured_username(username, host, port)

                LOG.debug("Trying to login as '%s' to '%s:%s'", username, host,
                          port)

                # Try to automatically log in with a saved credential
                # if it exists for the server.
                try:
                    session_token = auth_client.performLogin(
                        "Username:Password", auto_auth_string)
                    manager.save_token(host, port, session_token)
                    LOG.info("Authentication successful.")
                    return session_token
                except shared.ttypes.RequestFailed:
                    print_err = True
            else:
                print_err = True
        else:
            print_err = True

        if print_err:
            if manager.is_autologin_enabled():
                LOG.error("Invalid pre-configured credentials.")
                LOG.error("Your password has been changed or personal access "
                          "token has been removed which is used by your "
                          "\"~/.codechecker.passwords.json\" file. Please "
                          "remove or change invalid credentials.")
            else:
                LOG.error("Access denied. This server requires "
                          "authentication.")
                LOG.error("Please log in onto the server using 'CodeChecker "
                          "cmd login'.")
            sys.exit(1)
예제 #2
0
def perform_auth_for_handler(protocol, manager, host, port, session_token):
    # Before actually communicating with the server,
    # we need to check authentication first.
    auth_client = authentication_helper.ThriftAuthHelper(
        protocol, host, port, '/v' + CLIENT_API + '/Authentication',
        session_token)
    check_api_version(auth_client)

    try:
        auth_response = auth_client.getAuthParameters()
    except TApplicationException:
        auth_response = AuthTypes.HandshakeInformation()
        auth_response.requiresAuthentication = False

    if auth_response.requiresAuthentication and \
            not auth_response.sessionStillActive:
        print_err = False

        if manager.is_autologin_enabled():
            auto_auth_string = manager.get_auth_string(host, port)
            if auto_auth_string:
                # Try to automatically log in with a saved credential
                # if it exists for the server.
                try:
                    session_token = auth_client.performLogin(
                        "Username:Password", auto_auth_string)
                    manager.save_token(host, port, session_token)
                    LOG.info("Authenticated using pre-configured "
                             "credentials.")
                    return session_token
                except shared.ttypes.RequestFailed:
                    print_err = True
            else:
                print_err = True
        else:
            print_err = True

        if print_err:
            LOG.error("Access denied. This server requires authentication.")
            LOG.error("Please log in onto the server using 'CodeChecker cmd "
                      "login'.")
            sys.exit(1)