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.hc.client5.http.auth;
28
29 import java.util.Queue;
30
31 import org.apache.hc.core5.util.Args;
32
33
34
35
36
37
38
39 public class AuthExchange {
40
41 public enum State {
42
43 UNCHALLENGED, CHALLENGED, HANDSHAKE, FAILURE, SUCCESS
44
45 }
46
47 private State state;
48 private AuthScheme authScheme;
49 private Queue<AuthScheme> authOptions;
50 private String pathPrefix;
51
52 public AuthExchange() {
53 super();
54 this.state = State.UNCHALLENGED;
55 }
56
57 public void reset() {
58 this.state = State.UNCHALLENGED;
59 this.authOptions = null;
60 this.authScheme = null;
61 this.pathPrefix = null;
62 }
63
64 public State getState() {
65 return this.state;
66 }
67
68 public void setState(final State state) {
69 this.state = state != null ? state : State.UNCHALLENGED;
70 }
71
72
73
74
75 public AuthScheme getAuthScheme() {
76 return this.authScheme;
77 }
78
79
80
81
82 public boolean isConnectionBased() {
83 return this.authScheme != null && this.authScheme.isConnectionBased();
84 }
85
86
87
88
89 public String getPathPrefix() {
90 return pathPrefix;
91 }
92
93
94
95
96 public void setPathPrefix(final String pathPrefix) {
97 this.pathPrefix = pathPrefix;
98 }
99
100
101
102
103
104
105 public void select(final AuthScheme authScheme) {
106 Args.notNull(authScheme, "Auth scheme");
107 this.authScheme = authScheme;
108 this.authOptions = null;
109 }
110
111
112
113
114 public Queue<AuthScheme> getAuthOptions() {
115 return this.authOptions;
116 }
117
118
119
120
121
122
123 public void setOptions(final Queue<AuthScheme> authOptions) {
124 Args.notEmpty(authOptions, "Queue of auth options");
125 this.authOptions = authOptions;
126 }
127
128 @Override
129 public String toString() {
130 final StringBuilder buffer = new StringBuilder();
131 buffer.append("[").append(this.state);
132 if (this.authScheme != null) {
133 buffer.append(" ").append(this.authScheme);
134 }
135 buffer.append("]");
136 return buffer.toString();
137 }
138
139 }