~ubuntu-branches/ubuntu/saucy/restlet/saucy

« back to all changes in this revision

Viewing changes to org.restlet/src/org/restlet/data/AuthenticationInfo.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 16:25:45 UTC
  • Revision ID: package-import@ubuntu.com-20120611162545-5w2o0resi5y3pybc
Tags: upstream-2.0.14
ImportĀ upstreamĀ versionĀ 2.0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2005-2012 Restlet S.A.S.
 
3
 * 
 
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.
 
8
 * 
 
9
 * You can obtain a copy of the Apache 2.0 license at
 
10
 * http://www.opensource.org/licenses/apache-2.0
 
11
 * 
 
12
 * You can obtain a copy of the LGPL 3.0 license at
 
13
 * http://www.opensource.org/licenses/lgpl-3.0
 
14
 * 
 
15
 * You can obtain a copy of the LGPL 2.1 license at
 
16
 * http://www.opensource.org/licenses/lgpl-2.1
 
17
 * 
 
18
 * You can obtain a copy of the CDDL 1.0 license at
 
19
 * http://www.opensource.org/licenses/cddl1
 
20
 * 
 
21
 * You can obtain a copy of the EPL 1.0 license at
 
22
 * http://www.opensource.org/licenses/eclipse-1.0
 
23
 * 
 
24
 * See the Licenses for the specific language governing permissions and
 
25
 * limitations under the Licenses.
 
26
 * 
 
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
 
30
 * 
 
31
 * Restlet is a registered trademark of Restlet S.A.S.
 
32
 */
 
33
 
 
34
package org.restlet.data;
 
35
 
 
36
import org.restlet.engine.util.SystemUtils;
 
37
 
 
38
/**
 
39
 * Preemptive authentication information. Sent by an origin server to a client
 
40
 * after a successful digest authentication attempt.<br>
 
41
 * <br>
 
42
 * Note that when used with HTTP connectors, this class maps to the
 
43
 * "Authentication-Info" header.
 
44
 * 
 
45
 * @see <a href="http://tools.ietf.org/html/rfc2617#section-3.2.3">HTTP
 
46
 *      Authentication - The Authentication-Info Header</a>
 
47
 * 
 
48
 * @author Kelly McLaughlin
 
49
 * @author Jerome Louvel
 
50
 */
 
51
public class AuthenticationInfo {
 
52
 
 
53
    /** The next nonce value. */
 
54
    private volatile String nextServerNonce;
 
55
 
 
56
    /** The nonce-count value. */
 
57
    private volatile int nonceCount;
 
58
 
 
59
    /** The client nonce. */
 
60
    private volatile String clientNonce;
 
61
 
 
62
    /** The quality of protection. */
 
63
    private volatile String quality;
 
64
 
 
65
    /** The optional response digest for mutual authentication. */
 
66
    private volatile String responseDigest;
 
67
 
 
68
    /**
 
69
     * Default constructor.
 
70
     * 
 
71
     * @param nextNonce
 
72
     *            The next nonce value.
 
73
     */
 
74
    // public AuthenticationInfo(String nextNonce) {
 
75
    // this(nextNonce, 0, );
 
76
    // }
 
77
 
 
78
    /**
 
79
     * Constructor.
 
80
     * 
 
81
     * @param nextNonce
 
82
     *            The next nonce value.
 
83
     * @param nonceCount
 
84
     *            The nonce-count value.
 
85
     * @param cnonce
 
86
     *            The cnonce value.
 
87
     * @param quality
 
88
     *            The quality of protection.
 
89
     * @param responseDigest
 
90
     *            The optional response digest for mutual authentication.
 
91
     */
 
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;
 
99
    }
 
100
 
 
101
    /** {@inheritDoc} */
 
102
    @Override
 
103
    public final boolean equals(final Object obj) {
 
104
        boolean result = (obj == this);
 
105
 
 
106
        // if obj == this no need to go further
 
107
        if (!result) {
 
108
            // if obj isn't a challenge request or is null don't evaluate
 
109
            // further
 
110
            if (obj instanceof AuthenticationInfo) {
 
111
                final AuthenticationInfo that = (AuthenticationInfo) obj;
 
112
                if (getNextServerNonce() != null) {
 
113
                    result = getNextServerNonce().equals(
 
114
                            that.getNextServerNonce());
 
115
                } else {
 
116
                    result = (that.getNextServerNonce() == null);
 
117
                }
 
118
 
 
119
                if (result) {
 
120
                    result = (getNonceCount() == that.getNonceCount());
 
121
                }
 
122
 
 
123
                if (result) {
 
124
                    if (getClientNonce() != null) {
 
125
                        result = getClientNonce().equals(that.getClientNonce());
 
126
                    } else {
 
127
                        result = (that.getClientNonce() == null);
 
128
                    }
 
129
                }
 
130
 
 
131
                if (result) {
 
132
                    if (getQuality() != null) {
 
133
                        result = getQuality().equals(that.getQuality());
 
134
                    } else {
 
135
                        result = (that.getQuality() == null);
 
136
                    }
 
137
                }
 
138
 
 
139
                if (result) {
 
140
                    if (getResponseDigest() != null) {
 
141
                        result = getResponseDigest().equals(
 
142
                                that.getResponseDigest());
 
143
                    } else {
 
144
                        result = (that.getResponseDigest() == null);
 
145
                    }
 
146
                }
 
147
            }
 
148
        }
 
149
 
 
150
        return result;
 
151
    }
 
152
 
 
153
    /**
 
154
     * Returns the client nonce.
 
155
     * 
 
156
     * @return The client nonce.
 
157
     */
 
158
    public String getClientNonce() {
 
159
        return this.clientNonce;
 
160
    }
 
161
 
 
162
    /**
 
163
     * Returns the next server nonce. This is the nonce the server wishes the
 
164
     * client to use for a future authentication response
 
165
     * 
 
166
     * @return The next nonce value.
 
167
     */
 
168
    public String getNextServerNonce() {
 
169
        return this.nextServerNonce;
 
170
    }
 
171
 
 
172
    /**
 
173
     * Returns the nonce-count value.
 
174
     * 
 
175
     * @return The nonce-count value.
 
176
     */
 
177
    public int getNonceCount() {
 
178
        return this.nonceCount;
 
179
    }
 
180
 
 
181
    /**
 
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.
 
186
     * 
 
187
     * @return The quality of protection.
 
188
     */
 
189
    public String getQuality() {
 
190
        return this.quality;
 
191
    }
 
192
 
 
193
    /**
 
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.
 
198
     * 
 
199
     * @return The optional response digest for mutual authentication.
 
200
     */
 
201
    public String getResponseDigest() {
 
202
        return this.responseDigest;
 
203
    }
 
204
 
 
205
    /** {@inheritDoc} */
 
206
    @Override
 
207
    public int hashCode() {
 
208
        return SystemUtils.hashCode(getNextServerNonce(), getNonceCount(),
 
209
                getClientNonce(), getQuality(), getResponseDigest());
 
210
    }
 
211
 
 
212
    /**
 
213
     * Sets the client nonce.
 
214
     * 
 
215
     * @param clientNonce
 
216
     *            The client nonce.
 
217
     */
 
218
    public void setClientNonce(String clientNonce) {
 
219
        this.clientNonce = clientNonce;
 
220
    }
 
221
 
 
222
    /**
 
223
     * Sets the next server nonce. This is the nonce the server wishes the
 
224
     * client to use for a future authentication response
 
225
     * 
 
226
     * @param nextNonce
 
227
     *            The next nonce.
 
228
     */
 
229
    public void setNextServerNonce(String nextNonce) {
 
230
        this.nextServerNonce = nextNonce;
 
231
    }
 
232
 
 
233
    /**
 
234
     * Sets the nonce-count value.
 
235
     * 
 
236
     * @param nonceCount
 
237
     *            The nonceCount value.
 
238
     */
 
239
    public void setNonceCount(int nonceCount) {
 
240
        this.nonceCount = nonceCount;
 
241
    }
 
242
 
 
243
    /**
 
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.
 
248
     * 
 
249
     * @param qop
 
250
     *            The quality of protection.
 
251
     */
 
252
    public void setQuality(String qop) {
 
253
        this.quality = qop;
 
254
    }
 
255
 
 
256
    /**
 
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.
 
261
     * 
 
262
     * @param responseDigest
 
263
     *            The response digest.
 
264
     */
 
265
    public void setResponseDigest(String responseDigest) {
 
266
        this.responseDigest = responseDigest;
 
267
    }
 
268
}