2
* Copyright 2005-2012 Restlet S.A.S.
4
* The contents of this file are subject to the terms of one of the following
5
* open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
6
* 1.0 (the "Licenses"). You can select the license that you prefer but you may
7
* not use this file except in compliance with one of these Licenses.
9
* You can obtain a copy of the Apache 2.0 license at
10
* http://www.opensource.org/licenses/apache-2.0
12
* You can obtain a copy of the LGPL 3.0 license at
13
* http://www.opensource.org/licenses/lgpl-3.0
15
* You can obtain a copy of the LGPL 2.1 license at
16
* http://www.opensource.org/licenses/lgpl-2.1
18
* You can obtain a copy of the CDDL 1.0 license at
19
* http://www.opensource.org/licenses/cddl1
21
* You can obtain a copy of the EPL 1.0 license at
22
* http://www.opensource.org/licenses/eclipse-1.0
24
* See the Licenses for the specific language governing permissions and
25
* limitations under the Licenses.
27
* Alternatively, you can obtain a royalty free commercial license with less
28
* limitations, transferable or non-transferable, directly at
29
* http://www.restlet.com/products/restlet-framework
31
* Restlet is a registered trademark of Restlet S.A.S.
34
package org.restlet.data;
36
import org.restlet.engine.util.SystemUtils;
39
* Preemptive authentication information. Sent by an origin server to a client
40
* after a successful digest authentication attempt.<br>
42
* Note that when used with HTTP connectors, this class maps to the
43
* "Authentication-Info" header.
45
* @see <a href="http://tools.ietf.org/html/rfc2617#section-3.2.3">HTTP
46
* Authentication - The Authentication-Info Header</a>
48
* @author Kelly McLaughlin
49
* @author Jerome Louvel
51
public class AuthenticationInfo {
53
/** The next nonce value. */
54
private volatile String nextServerNonce;
56
/** The nonce-count value. */
57
private volatile int nonceCount;
59
/** The client nonce. */
60
private volatile String clientNonce;
62
/** The quality of protection. */
63
private volatile String quality;
65
/** The optional response digest for mutual authentication. */
66
private volatile String responseDigest;
69
* Default constructor.
72
* The next nonce value.
74
// public AuthenticationInfo(String nextNonce) {
75
// this(nextNonce, 0, );
82
* The next nonce value.
84
* The nonce-count value.
88
* The quality of protection.
89
* @param responseDigest
90
* The optional response digest for mutual authentication.
92
public AuthenticationInfo(String nextNonce, int nonceCount, String cnonce,
93
String quality, String responseDigest) {
94
this.nextServerNonce = nextNonce;
95
this.nonceCount = nonceCount;
96
this.clientNonce = cnonce;
97
this.quality = quality;
98
this.responseDigest = responseDigest;
103
public final boolean equals(final Object obj) {
104
boolean result = (obj == this);
106
// if obj == this no need to go further
108
// if obj isn't a challenge request or is null don't evaluate
110
if (obj instanceof AuthenticationInfo) {
111
final AuthenticationInfo that = (AuthenticationInfo) obj;
112
if (getNextServerNonce() != null) {
113
result = getNextServerNonce().equals(
114
that.getNextServerNonce());
116
result = (that.getNextServerNonce() == null);
120
result = (getNonceCount() == that.getNonceCount());
124
if (getClientNonce() != null) {
125
result = getClientNonce().equals(that.getClientNonce());
127
result = (that.getClientNonce() == null);
132
if (getQuality() != null) {
133
result = getQuality().equals(that.getQuality());
135
result = (that.getQuality() == null);
140
if (getResponseDigest() != null) {
141
result = getResponseDigest().equals(
142
that.getResponseDigest());
144
result = (that.getResponseDigest() == null);
154
* Returns the client nonce.
156
* @return The client nonce.
158
public String getClientNonce() {
159
return this.clientNonce;
163
* Returns the next server nonce. This is the nonce the server wishes the
164
* client to use for a future authentication response
166
* @return The next nonce value.
168
public String getNextServerNonce() {
169
return this.nextServerNonce;
173
* Returns the nonce-count value.
175
* @return The nonce-count value.
177
public int getNonceCount() {
178
return this.nonceCount;
182
* Returns the quality of protection. The value can be
183
* {@link ChallengeMessage#QUALITY_AUTHENTICATION} for authentication or
184
* {@link ChallengeMessage#QUALITY_AUTHENTICATION_INTEGRITY} for
185
* authentication with integrity protection.
187
* @return The quality of protection.
189
public String getQuality() {
194
* Returns the optional response digest for mutual authentication. Note that
195
* when used with HTTP connectors, this property maps to the
196
* "response-digest" value in the "response-auth" directive of the
197
* "Authentication-Info" header.
199
* @return The optional response digest for mutual authentication.
201
public String getResponseDigest() {
202
return this.responseDigest;
207
public int hashCode() {
208
return SystemUtils.hashCode(getNextServerNonce(), getNonceCount(),
209
getClientNonce(), getQuality(), getResponseDigest());
213
* Sets the client nonce.
218
public void setClientNonce(String clientNonce) {
219
this.clientNonce = clientNonce;
223
* Sets the next server nonce. This is the nonce the server wishes the
224
* client to use for a future authentication response
229
public void setNextServerNonce(String nextNonce) {
230
this.nextServerNonce = nextNonce;
234
* Sets the nonce-count value.
237
* The nonceCount value.
239
public void setNonceCount(int nonceCount) {
240
this.nonceCount = nonceCount;
244
* Sets the quality of protection. The value can be
245
* {@link ChallengeMessage#QUALITY_AUTHENTICATION} for authentication or
246
* {@link ChallengeMessage#QUALITY_AUTHENTICATION_INTEGRITY} for
247
* authentication with integrity protection.
250
* The quality of protection.
252
public void setQuality(String qop) {
257
* Sets the optional response digest for mutual authentication. Note that
258
* when used with HTTP connectors, this property maps to the
259
* "response-digest" value in the "response-auth" directive of the
260
* "Authentication-Info" header.
262
* @param responseDigest
263
* The response digest.
265
public void setResponseDigest(String responseDigest) {
266
this.responseDigest = responseDigest;