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 package org.apache.hc.client5.http.auth;
29
30 import org.apache.hc.core5.annotation.Contract;
31 import org.apache.hc.core5.annotation.ThreadingBehavior;
32
33
34
35
36
37
38 @Contract(threading = ThreadingBehavior.IMMUTABLE)
39 public class KerberosConfig implements Cloneable {
40
41 public enum Option {
42
43 DEFAULT,
44 ENABLE,
45 DISABLE
46
47 }
48
49 public static final KerberosConfig DEFAULT = new Builder().build();
50
51 private final Option stripPort;
52 private final Option useCanonicalHostname;
53 private final Option requestDelegCreds;
54
55
56
57
58 protected KerberosConfig() {
59 this(Option.DEFAULT, Option.DEFAULT, Option.DEFAULT);
60 }
61
62 KerberosConfig(
63 final Option stripPort,
64 final Option useCanonicalHostname,
65 final Option requestDelegCreds) {
66 super();
67 this.stripPort = stripPort;
68 this.useCanonicalHostname = useCanonicalHostname;
69 this.requestDelegCreds = requestDelegCreds;
70 }
71
72 public Option getStripPort() {
73 return stripPort;
74 }
75
76 public Option getUseCanonicalHostname() {
77 return useCanonicalHostname;
78 }
79
80 public Option getRequestDelegCreds() {
81 return requestDelegCreds;
82 }
83
84 @Override
85 protected KerberosConfig clone() throws CloneNotSupportedException {
86 return (KerberosConfig) super.clone();
87 }
88
89 @Override
90 public String toString() {
91 final StringBuilder builder = new StringBuilder();
92 builder.append("[");
93 builder.append("stripPort=").append(stripPort);
94 builder.append(", useCanonicalHostname=").append(useCanonicalHostname);
95 builder.append(", requestDelegCreds=").append(requestDelegCreds);
96 builder.append("]");
97 return builder.toString();
98 }
99
100 public static KerberosConfig.Builder custom() {
101 return new Builder();
102 }
103
104 public static KerberosConfig.Builder copy(final KerberosConfig config) {
105 return new Builder()
106 .setStripPort(config.getStripPort())
107 .setUseCanonicalHostname(config.getUseCanonicalHostname())
108 .setRequestDelegCreds(config.getRequestDelegCreds());
109 }
110
111 public static class Builder {
112
113 private Option stripPort;
114 private Option useCanonicalHostname;
115 private Option requestDelegCreds;
116
117 Builder() {
118 super();
119 this.stripPort = Option.DEFAULT;
120 this.useCanonicalHostname = Option.DEFAULT;
121 this.requestDelegCreds = Option.DEFAULT;
122 }
123
124 public Builder setStripPort(final Option stripPort) {
125 this.stripPort = stripPort;
126 return this;
127 }
128
129 public Builder setStripPort(final boolean stripPort) {
130 this.stripPort = stripPort ? Option.ENABLE : Option.DISABLE;
131 return this;
132 }
133
134 public Builder setUseCanonicalHostname(final Option useCanonicalHostname) {
135 this.useCanonicalHostname = useCanonicalHostname;
136 return this;
137 }
138
139 public Builder setUseCanonicalHostname(final boolean useCanonicalHostname) {
140 this.useCanonicalHostname = useCanonicalHostname ? Option.ENABLE : Option.DISABLE;
141 return this;
142 }
143
144 public Builder setRequestDelegCreds(final Option requestDelegCreds) {
145 this.requestDelegCreds = requestDelegCreds;
146 return this;
147 }
148
149 public KerberosConfig build() {
150 return new KerberosConfig(
151 stripPort,
152 useCanonicalHostname,
153 requestDelegCreds);
154 }
155
156 }
157
158 }