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
28
29
30 package org.apache.commons.httpclient.auth;
31
32 /***
33 * This class provides detailed information about the state of the
34 * authentication process.
35 *
36 * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
37 * @since 3.0
38 */
39 public class AuthState {
40
41 /*** Actual authentication scheme */
42 private AuthScheme authScheme = null;
43
44 /*** Whether preemtive authentication is attempted */
45 private boolean preemptive = false;
46
47 /***
48 * Default constructor.
49 *
50 */
51 public AuthState() {
52 super();
53 }
54
55 /***
56 * Preemptively assigns Basic authentication scheme.
57 */
58 public void setPreemptive() {
59 if (this.authScheme != null) {
60 throw new IllegalStateException("Authentication state already initialized");
61 }
62 this.authScheme = AuthPolicy.getAuthScheme("basic");
63 this.preemptive = true;
64 }
65
66 /***
67 * Invalidates the authentication state by resetting its parameters.
68 */
69 public void invalidate() {
70 this.authScheme = null;
71 this.preemptive = false;
72 }
73
74 /***
75 * Tests if preemptive authentication is used.
76 *
77 * @return <tt>true</tt> if using the default Basic {@link AuthScheme
78 * authentication scheme}, <tt>false</tt> otherwise.
79 */
80 public boolean isPreemptive() {
81 return this.preemptive;
82 }
83
84 /***
85 * Assigns the given {@link AuthScheme authentication scheme}.
86 *
87 * @param authScheme the {@link AuthScheme authentication scheme}
88 */
89 public void setAuthScheme(final AuthScheme authScheme) {
90 this.authScheme = authScheme;
91 this.preemptive = false;
92 }
93
94 /***
95 * Returns the {@link AuthScheme authentication scheme}.
96 *
97 * @return {@link AuthScheme authentication scheme}
98 */
99 public AuthScheme getAuthScheme() {
100 return authScheme;
101 }
102
103 /***
104 * Returns the authentication realm.
105 *
106 * @return the name of the authentication realm
107 */
108 public String getRealm() {
109 if (this.authScheme != null) {
110 return this.authScheme.getRealm();
111 } else {
112 return null;
113 }
114 }
115 }