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
142
143 public void update(final Queue<AuthOption> authOptions) {
144 Args.notEmpty(authOptions, "Queue of auth options");
145 this.authOptions = authOptions;
146 this.authScheme = null;
147 this.credentials = null;
148 }
149
150
151
152
153
154
155 @Deprecated
156 public void invalidate() {
157 reset();
158 }
159
160
161
162
163 @Deprecated
164 public boolean isValid() {
165 return this.authScheme != null;
166 }
167
168
169
170
171
172
173
174
175 @Deprecated
176 public void setAuthScheme(final AuthScheme authScheme) {
177 if (authScheme == null) {
178 reset();
179 return;
180 }
181 this.authScheme = authScheme;
182 }
183
184
185
186
187
188
189
190
191 @Deprecated
192 public void setCredentials(final Credentials credentials) {
193 this.credentials = credentials;
194 }
195
196
197
198
199
200
201
202
203 @Deprecated
204 public AuthScope getAuthScope() {
205 return this.authScope;
206 }
207
208
209
210
211
212
213
214
215 @Deprecated
216 public void setAuthScope(final AuthScope authScope) {
217 this.authScope = authScope;
218 }
219
220 @Override
221 public String toString() {
222 final StringBuilder buffer = new StringBuilder();
223 buffer.append("state:").append(this.state).append(";");
224 if (this.authScheme != null) {
225 buffer.append("auth scheme:").append(this.authScheme.getSchemeName()).append(";");
226 }
227 if (this.credentials != null) {
228 buffer.append("credentials present");
229 }
230 return buffer.toString();
231 }
232
233 }