1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.http.auth;
28
29 import java.util.Queue;
30
31 import org.apache.http.util.Args;
32
33
34
35
36
37
38 public class AuthState {
39
40
41 private AuthProtocolState state;
42
43
44 private AuthScheme authScheme;
45
46
47 private AuthScope authScope;
48
49
50 private Credentials credentials;
51
52
53 private Queue<AuthOption> authOptions;
54
55 public AuthState() {
56 super();
57 this.state = AuthProtocolState.UNCHALLENGED;
58 }
59
60
61
62
63
64
65 public void reset() {
66 this.state = AuthProtocolState.UNCHALLENGED;
67 this.authOptions = null;
68 this.authScheme = null;
69 this.authScope = null;
70 this.credentials = null;
71 }
72
73
74
75
76 public AuthProtocolState getState() {
77 return this.state;
78 }
79
80
81
82
83 public void setState(final AuthProtocolState state) {
84 this.state = state != null ? state : AuthProtocolState.UNCHALLENGED;
85 }
86
87
88
89
90 public AuthScheme getAuthScheme() {
91 return this.authScheme;
92 }
93
94
95
96
97 public Credentials getCredentials() {
98 return this.credentials;
99 }
100
101
102
103
104
105
106
107
108
109 public void update(final AuthScheme authScheme, final Credentials credentials) {
110 Args.notNull(authScheme, "Auth scheme");
111 Args.notNull(credentials, "Credentials");
112 this.authScheme = authScheme;
113 this.credentials = credentials;
114 this.authOptions = null;
115 }
116
117
118
119
120
121
122 public Queue<AuthOption> getAuthOptions() {
123 return this.authOptions;
124 }
125
126
127
128
129
130
131
132 public boolean hasAuthOptions() {
133 return this.authOptions != null && !this.authOptions.isEmpty();
134 }
135
136
137
138
139
140
141 public boolean isConnectionBased() {
142 return this.authScheme != null && this.authScheme.isConnectionBased();
143 }
144
145
146
147
148
149
150
151
152 public void update(final Queue<AuthOption> authOptions) {
153 Args.notEmpty(authOptions, "Queue of auth options");
154 this.authOptions = authOptions;
155 this.authScheme = null;
156 this.credentials = null;
157 }
158
159
160
161
162
163
164 @Deprecated
165 public void invalidate() {
166 reset();
167 }
168
169
170
171
172 @Deprecated
173 public boolean isValid() {
174 return this.authScheme != null;
175 }
176
177
178
179
180
181
182
183
184 @Deprecated
185 public void setAuthScheme(final AuthScheme authScheme) {
186 if (authScheme == null) {
187 reset();
188 return;
189 }
190 this.authScheme = authScheme;
191 }
192
193
194
195
196
197
198
199
200 @Deprecated
201 public void setCredentials(final Credentials credentials) {
202 this.credentials = credentials;
203 }
204
205
206
207
208
209
210
211
212 @Deprecated
213 public AuthScope getAuthScope() {
214 return this.authScope;
215 }
216
217
218
219
220
221
222
223
224 @Deprecated
225 public void setAuthScope(final AuthScope authScope) {
226 this.authScope = authScope;
227 }
228
229 @Override
230 public String toString() {
231 final StringBuilder buffer = new StringBuilder();
232 buffer.append("state:").append(this.state).append(";");
233 if (this.authScheme != null) {
234 buffer.append("auth scheme:").append(this.authScheme.getSchemeName()).append(";");
235 }
236 if (this.credentials != null) {
237 buffer.append("credentials present");
238 }
239 return buffer.toString();
240 }
241
242 }