このページでは

QAuthenticator Class

QAuthenticator クラスは、認証オブジェクトを提供します。詳細...

ヘッダー: #include <QAuthenticator>
CMake: find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network

注:このクラスのすべての関数は再入可能です。

パブリック関数

QAuthenticator()
QAuthenticator(const QAuthenticator &other)
~QAuthenticator()
(since 6.11) void clear()
bool isNull() const
QVariant option(const QString &opt) const
QVariantHash options() const
QString password() const
QString realm() const
void setOption(const QString &opt, const QVariant &value)
void setPassword(const QString &password)
void setUser(const QString &user)
QString user() const
bool operator!=(const QAuthenticator &other) const
QAuthenticator &operator=(const QAuthenticator &other)
bool operator==(const QAuthenticator &other) const

詳細な説明

QAuthenticator クラスは通常、QNetworkAccessManager およびQAbstractSocket のauthenticationRequired() およびproxyAuthenticationRequired() シグナルで使用されます。このクラスは、認証を必要とするサービスにアクセスする際に、必要な認証情報をソケットに返送する手段を提供します。

QAuthenticator は、以下の認証方式をサポートしています:

  • Basic
  • NTLM バージョン 2
  • Digest-MD5
  • SPNEGO/Negotiate

オプション

認証に必要なユーザー名とパスワードに加え、QAuthenticatorオブジェクトには追加のオプションを含めることもできます。options()関数を使用すると、サーバーから送信された受信オプションを照会できます。また、setOption()関数を使用すると、認証計算で処理される送信オプションを設定できます。 受け入れられるオプションおよび提供されるオプションは、認証タイプによって異なります(method()を参照)。

以下の表には、既知の受信オプションおよび受け入れられる送信オプションが記載されています。サーバーはいつでも追加情報を含める可能性があるため、受信オプションのリストは網羅的なものではありません。一方、送信オプションのリストは網羅的であり、未知のオプションが処理されたり、サーバーに送信されたりすることはありません。

Basic

オプション方向タイプ説明
realm受信QString認証の対象となるレルムを含みます。realm() と同様です。

Basic認証メカニズムでは、送信オプションはサポートされていません。

NTLM バージョン 2

NTLM認証メカニズムは、現在、受信および送信のいずれのオプションもサポートしていません。Windowsでは、user が設定されていない場合、シングルサインオン機能を有効にするために、ローカルシステム上でドメイン\user の認証情報が検索されます。

Digest-MD5

オプション方向タイプ説明
realm受信QString認証の対象となるレルムを含みます。realm() と同様です。

Digest-MD5 認証メカニズムは、送信オプションをサポートしていません。

SPNEGO/Negotiate

オプション方向タイプ説明
spn送信QStringカスタムSPNを提供します。

この認証メカニズムは、現時点では着信オプションをサポートしていません。

spn プロパティは、SSPIライブラリが使用される場合、Windowsクライアントで使用されます。このプロパティが設定されていない場合、デフォルトのSPNが使用されます。WindowsにおけるデフォルトのSPNはHTTP/<hostname> です。

その他のオペレーティングシステムでは、GSSAPI ライブラリが使用されます。その場合、KDC が設定されており、そこから認証情報を取得できることが想定されています。バックエンドは常にHTTPS@<hostname> を SPN として使用します。

セキュリティに関する考慮事項

QAuthenticator は、ユーザー名やパスワードなどの認証情報を、汎用データ型 (QString 、QByteArray) を使用して内部的に保存します。これらのデータ型では、破棄時にメモリからその内容が安全に消去されることは保証されません。QAuthenticator オブジェクトが破棄またはクリアされた後も、認証情報が解放されたヒープページ、コアダンプ、スワップファイル、またはプロセスメモリに残存する可能性があります。

Basic認証がネゴシエートされる場合、認証情報はBase64エンコーディングを使用して送信されますが、これは容易に復号可能です。Basic認証は、TLSで暗号化された接続上でのみ使用すべきです。QAuthenticatorはこの要件を強制しません。Basic認証を使用する際、トランスポートのセキュリティを確保するのはアプリケーションの責任です。

QAuthenticator は、サーバーが提供する認証方式の中から、内部で固定された優先順位(Negotiate (Kerberos/SPNEGO)、NTLM、Digest-MD5、Basic)に基づいて、最も強固な認証方式を選択します。 現在、アプリケーションはこの選択に影響を与えたり、許容される認証方式を制限したりすることはできません。サーバーやプロキシが脆弱な認証方式しか提供していない場合、通知なしにその方式が使用されます。

認証情報の衛生管理に厳しい要件を課すアプリケーションは、QAuthenticatorをどのように、どこで使用するかを決定する際、この点を考慮に入れる必要があります。

「QSslSocket」も参照してください 。

メンバ関数のドキュメント

QAuthenticator::QAuthenticator()

空の認証オブジェクトを作成します。

QAuthenticator::QAuthenticator(const QAuthenticator &other)

other のコピーを作成します。

[noexcept] QAuthenticator::~QAuthenticator()

オブジェクトを破棄します。

[since 6.11] void QAuthenticator::clear()

すべての認証情報を消去し、オブジェクトを初期化されていないデフォルトの状態にリセットします。

この関数は Qt 6.11 で導入されました。

bool QAuthenticator::isNull() const

オブジェクトが初期化されていない場合は、true を返します。非const メンバー関数が呼び出された場合、または内容が別の初期化済みのQAuthenticator オブジェクトから生成またはコピーされた場合は、false を返します。

QVariant QAuthenticator::option(const QString &opt) const

サーバーによってオプション `opt ` が設定されている場合、その値が返されます。受信オプションの詳細については、Options section を参照してください。オプション `opt ` が見つからない場合は、無効な `QVariant ` が返されます。

setOption()、options()、およびQAuthenticator optionsも参照してください 。

QVariantHash QAuthenticator::options() const

サーバーの応答を解析し、このQAuthenticator オブジェクトに設定されたすべての受信オプションを返します。受信オプションの詳細については、Options section を参照してください。

option() およびQAuthenticator optionsも参照してください 。

QString QAuthenticator::password() const

認証に使用されたパスワードを返します。

setPassword()も参照してください 。

QString QAuthenticator::realm() const

認証が必要なレルムを返します。

void QAuthenticator::setOption(const QString &opt, const QVariant &value)

送信オプション「opt 」を「value 」に設定します。送信オプションの詳細については、Options section を参照してください。

options()、option()、およびQAuthenticator optionsも参照してください 。

void QAuthenticator::setPassword(const QString &password)

認証に使用されるpassword を設定します。

password() およびQNetworkAccessManager::authenticationRequired()も参照してください 。

void QAuthenticator::setUser(const QString &user)

認証に使用されるuser を設定します。

user() およびQNetworkAccessManager::authenticationRequired()も参照してください 。

QString QAuthenticator::user() const

認証に使用されたユーザーを返します。

setUser()も参照してください 。

bool QAuthenticator::operator!=(const QAuthenticator &other) const

この認証子が `other` と異なる場合は `true ` を返し、そうでない場合は `false` を返します。

QAuthenticator &QAuthenticator::operator=(const QAuthenticator &other)

other の内容をこの認証情報に割り当てます。

bool QAuthenticator::operator==(const QAuthenticator &other) const

この認証子がother と一致する場合は `true ` を返し、そうでない場合は `false` を返します。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.