Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to stop QNetworkAccessManager from caching NTLM credentials?
Forum Updated to NodeBB v4.3 + New Features

How to stop QNetworkAccessManager from caching NTLM credentials?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 305 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nerdan
    wrote on last edited by Nerdan
    #1

    Qt 5.15.2

    Hello, I'm using QNetworkAccessManager for NTLM authentication. After successful authentication, QNAM caches credentials, which I don't want.

    Is there any convenient way of clearing the cache or preventing QNAM from caching credentials? Or can I trick Qt into firing the authenticationRequired signal?

    I've tried setting the request attributes:

    • CacheLoadControlAttribute to AlwaysNetwork - didn't help
    • CacheSaveControlAttribute to false - didn't help
    • DoNotBufferUploadDataAttribute to true - didn't help
    • AutoDeleteReplyOnFinishAttribute to true - crashed the server
    • AuthenticationReuseAttribute to Manual - started caching wrong credentials

    I tried using clearAccessCache and clearConnectionCache - depending on the call place, calls crashed the server, slowed down the completion of requests, or returned a 401 error or a 5 Operation Cancelled error.

    I tried closing, aborting, and disconnecting replies in the authenticationRequired and finished signals:

    • abort() - didn't help
    • close() - sometimes returned a 5 Operation Cancelled error
    • disconnect() - led to an infinite loop

    I tried to manually get the cache before, inside, and after authenticationRequired - couldn't get (nullptr):

    QNetworkDiskCache *diskCache = qobject_cast<QNetworkDiskCache *>(manager.cache());
    QUrl url = request.url();
    if (diskCache) {
        QNetworkCacheMetaData metaData = diskCache->metaData(url);
        if (metaData.isValid()) {
            diskCache->remove(url);
        }
    }
    

    I tried to save a pointer to QAuthenticator inside a class derived from QNetworkReply and set the user and password to an empty string before and after authenticationRequired - didn't help.

    Is there something I'm missing?

    artwawA 1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Please provide a minimal compilable example that shows the issue.

      You should also check with the latest Qt 6 to see if there's a difference in the behaviour.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • N Nerdan

        Qt 5.15.2

        Hello, I'm using QNetworkAccessManager for NTLM authentication. After successful authentication, QNAM caches credentials, which I don't want.

        Is there any convenient way of clearing the cache or preventing QNAM from caching credentials? Or can I trick Qt into firing the authenticationRequired signal?

        I've tried setting the request attributes:

        • CacheLoadControlAttribute to AlwaysNetwork - didn't help
        • CacheSaveControlAttribute to false - didn't help
        • DoNotBufferUploadDataAttribute to true - didn't help
        • AutoDeleteReplyOnFinishAttribute to true - crashed the server
        • AuthenticationReuseAttribute to Manual - started caching wrong credentials

        I tried using clearAccessCache and clearConnectionCache - depending on the call place, calls crashed the server, slowed down the completion of requests, or returned a 401 error or a 5 Operation Cancelled error.

        I tried closing, aborting, and disconnecting replies in the authenticationRequired and finished signals:

        • abort() - didn't help
        • close() - sometimes returned a 5 Operation Cancelled error
        • disconnect() - led to an infinite loop

        I tried to manually get the cache before, inside, and after authenticationRequired - couldn't get (nullptr):

        QNetworkDiskCache *diskCache = qobject_cast<QNetworkDiskCache *>(manager.cache());
        QUrl url = request.url();
        if (diskCache) {
            QNetworkCacheMetaData metaData = diskCache->metaData(url);
            if (metaData.isValid()) {
                diskCache->remove(url);
            }
        }
        

        I tried to save a pointer to QAuthenticator inside a class derived from QNetworkReply and set the user and password to an empty string before and after authenticationRequired - didn't help.

        Is there something I'm missing?

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @Nerdan Disk cache (or AbstractNetworkCache you're casting to disk cache) has nothing to do with auth.

        I suppose you're looking for this? https://doc.qt.io/qt-6/qnetworkaccessmanager.html#clearAccessCache

        Please note, documentation is from Qt6.7, please check if your implementation is same.

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        1
        • N Offline
          N Offline
          Nerdan
          wrote on last edited by
          #4

          @SGaist It's very hard to provide a minimal compilable example because it's part of a big application. Also, I've tried upgrading from Qt 5.15.2 to Qt 6.7.2, but it leads to a crash of the application, unfortunately(I've resolved all compatibility errors and installed the Qt 5 Compatibility module)

          @artwaw I've tried using both clearAccessCache and clearConnectionCache without success.

          I greatly appreciate your time and attempts to help.

          JonBJ 1 Reply Last reply
          0
          • N Nerdan

            @SGaist It's very hard to provide a minimal compilable example because it's part of a big application. Also, I've tried upgrading from Qt 5.15.2 to Qt 6.7.2, but it leads to a crash of the application, unfortunately(I've resolved all compatibility errors and installed the Qt 5 Compatibility module)

            @artwaw I've tried using both clearAccessCache and clearConnectionCache without success.

            I greatly appreciate your time and attempts to help.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Nerdan
            clearAccessCache() seems to me clearly to be the way you are expected to do it. If you say that "crashes" for you but you can't provide a repro then it's difficult to address.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved