Qt 4.8
Public Functions | Properties | Friends | List of all members
QAuthenticator Class Reference

The QAuthenticator class provides an authentication object. More...

#include <qauthenticator.h>

Public Functions

void detach ()
 
bool isNull () const
 Returns true if the authenticator is null. More...
 
bool operator!= (const QAuthenticator &other) const
 Returns true if this authenticator is different from other; otherwise returns false. More...
 
QAuthenticatoroperator= (const QAuthenticator &other)
 Assigns the contents of other to this authenticator. More...
 
bool operator== (const QAuthenticator &other) const
 Returns true if this authenticator is identical to other; otherwise returns false. More...
 
QVariant option (const QString &opt) const
 Returns the value related to option opt if it was set by the server. More...
 
QVariantHash options () const
 Returns all incoming options set in this QAuthenticator object by parsing the server reply. More...
 
QString password () const
 returns the password used for authentication. More...
 
 QAuthenticator ()
 Constructs an empty authentication object. More...
 
 QAuthenticator (const QAuthenticator &other)
 Constructs a copy of other. More...
 
QString realm () const
 returns the realm requiring authentication. More...
 
void setOption (const QString &opt, const QVariant &value)
 Sets the outgoing option opt to value value. More...
 
void setPassword (const QString &password)
 Sets the password used for authentication. More...
 
void setUser (const QString &user)
 Sets the user used for authentication. More...
 
QString user () const
 returns the user used for authentication. More...
 
 ~QAuthenticator ()
 Destructs the object. More...
 

Properties

QAuthenticatorPrivated
 

Friends

class QAuthenticatorPrivate
 

Detailed Description

The QAuthenticator class provides an authentication object.

Since
4.3
Note
This class or function is reentrant.
Attention
Module: QtNetwork

The QAuthenticator class is usually used in the QNetworkAccessManager::authenticationRequired() and QNetworkAccessManager::proxyAuthenticationRequired() signals of QNetworkAccessManager and QAbstractSocket. The class provides a way to pass back the required authentication information to the socket when accessing services that require authentication.

QAuthenticator supports the following authentication methods:

Options

In addition to the username and password required for authentication, a QAuthenticator object can also contain additional options. The options() function can be used to query incoming options sent by the server; the setOption() function can be used to set outgoing options, to be processed by the authenticator calculation. The options accepted and provided depend on the authentication type (see method()).

The following tables list known incoming options as well as accepted outgoing options. The list of incoming options is not exhaustive, since servers may include additional information at any time. The list of outgoing options is exhaustive, however, and no unknown options will be treated or sent back to the server.

Basic

Option Direction Description
realm Incoming Contains the realm of the authentication, the same as realm()

The Basic authentication mechanism supports no outgoing options.

NTLM version 2

The NTLM authentication mechanism currently supports no incoming or outgoing options.

Digest-MD5

Option Direction Description
realm Incoming Contains the realm of the authentication, the same as realm()

The Digest-MD5 authentication mechanism supports no outgoing options.

See also
QSslSocket

Definition at line 57 of file qauthenticator.h.

Constructors and Destructors

◆ QAuthenticator() [1/2]

QAuthenticator::QAuthenticator ( )

Constructs an empty authentication object.

Definition at line 137 of file qauthenticator.cpp.

138  : d(0)
139 {
140 }
QAuthenticatorPrivate * d

◆ ~QAuthenticator()

QAuthenticator::~QAuthenticator ( )

Destructs the object.

Definition at line 145 of file qauthenticator.cpp.

146 {
147  if (d)
148  delete d;
149 }
QAuthenticatorPrivate * d

◆ QAuthenticator() [2/2]

QAuthenticator::QAuthenticator ( const QAuthenticator other)

Constructs a copy of other.

Definition at line 154 of file qauthenticator.cpp.

155  : d(0)
156 {
157  if (other.d)
158  *this = other;
159 }
QAuthenticatorPrivate * d

Functions

◆ detach()

void QAuthenticator::detach ( )
Warning
This function is not part of the public interface.

Definition at line 252 of file qauthenticator.cpp.

Referenced by QHttpPrivate::_q_slotReadyRead(), QHttpNetworkConnectionChannel::ensureConnection(), QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(), operator=(), setOption(), setPassword(), and setUser().

253 {
254  if (!d) {
255  d = new QAuthenticatorPrivate;
256  return;
257  }
258 
261 }
QAuthenticatorPrivate * d
friend class QAuthenticatorPrivate

◆ isNull()

bool QAuthenticator::isNull ( ) const

Returns true if the authenticator is null.

Definition at line 324 of file qauthenticator.cpp.

Referenced by QHttpPrivate::_q_slotReadyRead(), QNetworkAccessFtpBackend::ftpDone(), and QHttpNetworkConnectionPrivate::handleAuthenticateChallenge().

325 {
326  return !d;
327 }
QAuthenticatorPrivate * d

◆ operator!=()

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

Returns true if this authenticator is different from other; otherwise returns false.

Definition at line 67 of file qauthenticator.h.

67 { return !operator==(other); }
bool operator==(const QAuthenticator &other) const
Returns true if this authenticator is identical to other; otherwise returns false.

◆ operator=()

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

Assigns the contents of other to this authenticator.

Definition at line 164 of file qauthenticator.cpp.

165 {
166  if (d == other.d)
167  return *this;
168 
169  // Do not share the d since challenge reponse/based changes
170  // could corrupt the internal store and different network requests
171  // can utilize different types of proxies.
172  detach();
173  if (other.d) {
174  d->user = other.d->user;
175  d->userDomain = other.d->userDomain;
176  d->workstation = other.d->workstation;
177  d->extractedUser = other.d->extractedUser;
178  d->password = other.d->password;
179  d->realm = other.d->realm;
180  d->method = other.d->method;
181  d->options = other.d->options;
182  } else if (d->phase == QAuthenticatorPrivate::Start) {
183  delete d;
184  d = 0;
185  }
186  return *this;
187 }
QAuthenticatorPrivate * d

◆ operator==()

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

Returns true if this authenticator is identical to other; otherwise returns false.

Definition at line 193 of file qauthenticator.cpp.

194 {
195  if (d == other.d)
196  return true;
197  return d->user == other.d->user
198  && d->password == other.d->password
199  && d->realm == other.d->realm
200  && d->method == other.d->method
201  && d->options == other.d->options;
202 }
QAuthenticatorPrivate * d

◆ option()

QVariant QAuthenticator::option ( const QString opt) const

Returns the value related to option opt if it was set by the server.

Since
4.7

See QAuthenticator#Options for more information on incoming options. If option opt isn't found, an invalid QVariant will be returned.

See also
options(), QAuthenticator::Options

Definition at line 282 of file qauthenticator.cpp.

283 {
284  return d ? d->options.value(opt) : QVariant();
285 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QAuthenticatorPrivate * d

◆ options()

QVariantHash QAuthenticator::options ( ) const

Returns all incoming options set in this QAuthenticator object by parsing the server reply.

Since
4.7 See QAuthenticator#Options for more information on incoming options.
See also
option(), QAuthenticator::Options

Definition at line 298 of file qauthenticator.cpp.

299 {
300  return d ? d->options : QVariantHash();
301 }
QHash< QString, QVariant > QVariantHash
Definition: qvariant.h:445
QAuthenticatorPrivate * d

◆ password()

QString QAuthenticator::password ( ) const

◆ realm()

QString QAuthenticator::realm ( ) const

returns the realm requiring authentication.

Definition at line 266 of file qauthenticator.cpp.

Referenced by QNetworkAccessAuthenticationManager::cacheCredentials(), QNetworkAccessAuthenticationManager::cacheProxyCredentials(), QNetworkAccessAuthenticationManager::fetchCachedCredentials(), and QNetworkAccessAuthenticationManager::fetchCachedProxyCredentials().

267 {
268  return d ? d->realm : QString();
269 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QAuthenticatorPrivate * d

◆ setOption()

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

Sets the outgoing option opt to value value.

Since
4.7

See QAuthenticator#Options for more information on outgoing options.

See also
options(), option(), QAuthenticator::Options

Definition at line 314 of file qauthenticator.cpp.

315 {
316  detach();
317  d->options.insert(opt, value);
318 }
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QAuthenticatorPrivate * d

◆ setPassword()

void QAuthenticator::setPassword ( const QString password)

◆ setUser()

void QAuthenticator::setUser ( const QString user)

◆ user()

QString QAuthenticator::user ( ) const

Friends and Related Functions

◆ QAuthenticatorPrivate

Definition at line 84 of file qauthenticator.h.

Referenced by detach().

Properties

◆ d

QAuthenticatorPrivate* QAuthenticator::d
private

The documentation for this class was generated from the following files: