View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
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   *  Immutable class encapsulating Kerberos configuration options.
35   *
36   *  @since 4.6
37   *
38   * @deprecated Do not use. The GGS based experimental authentication schemes are no longer
39   * supported. Consider using Basic or Bearer authentication with TLS instead.
40   *
41   */
42  @Deprecated
43  @Contract(threading = ThreadingBehavior.IMMUTABLE)
44  public class KerberosConfig implements Cloneable {
45  
46      public enum Option {
47  
48          DEFAULT,
49          ENABLE,
50          DISABLE
51  
52      }
53  
54      public static final KerberosConfig DEFAULT = new Builder().build();
55  
56      private final Option stripPort;
57      private final Option useCanonicalHostname;
58      private final Option requestDelegCreds;
59  
60      /**
61       * Intended for CDI compatibility
62      */
63      protected KerberosConfig() {
64          this(Option.DEFAULT, Option.DEFAULT, Option.DEFAULT);
65      }
66  
67      KerberosConfig(
68              final Option stripPort,
69              final Option useCanonicalHostname,
70              final Option requestDelegCreds) {
71          super();
72          this.stripPort = stripPort;
73          this.useCanonicalHostname = useCanonicalHostname;
74          this.requestDelegCreds = requestDelegCreds;
75      }
76  
77      public Option getStripPort() {
78          return stripPort;
79      }
80  
81      public Option getUseCanonicalHostname() {
82          return useCanonicalHostname;
83      }
84  
85      public Option getRequestDelegCreds() {
86          return requestDelegCreds;
87      }
88  
89      @Override
90      protected KerberosConfig clone() throws CloneNotSupportedException {
91          return (KerberosConfig) super.clone();
92      }
93  
94      @Override
95      public String toString() {
96          final StringBuilder builder = new StringBuilder();
97          builder.append("[");
98          builder.append("stripPort=").append(stripPort);
99          builder.append(", useCanonicalHostname=").append(useCanonicalHostname);
100         builder.append(", requestDelegCreds=").append(requestDelegCreds);
101         builder.append("]");
102         return builder.toString();
103     }
104 
105     public static KerberosConfig.Builder custom() {
106         return new Builder();
107     }
108 
109     public static KerberosConfig.Builder copy(final KerberosConfig config) {
110         return new Builder()
111                 .setStripPort(config.getStripPort())
112                 .setUseCanonicalHostname(config.getUseCanonicalHostname())
113                 .setRequestDelegCreds(config.getRequestDelegCreds());
114     }
115 
116     public static class Builder {
117 
118         private Option stripPort;
119         private Option useCanonicalHostname;
120         private Option requestDelegCreds;
121 
122         Builder() {
123             super();
124             this.stripPort = Option.DEFAULT;
125             this.useCanonicalHostname = Option.DEFAULT;
126             this.requestDelegCreds = Option.DEFAULT;
127         }
128 
129         public Builder setStripPort(final Option stripPort) {
130             this.stripPort = stripPort;
131             return this;
132         }
133 
134         public Builder setStripPort(final boolean stripPort) {
135             this.stripPort = stripPort ? Option.ENABLE : Option.DISABLE;
136             return this;
137         }
138 
139         public Builder setUseCanonicalHostname(final Option useCanonicalHostname) {
140             this.useCanonicalHostname = useCanonicalHostname;
141             return this;
142         }
143 
144         public Builder setUseCanonicalHostname(final boolean useCanonicalHostname) {
145             this.useCanonicalHostname = useCanonicalHostname ? Option.ENABLE : Option.DISABLE;
146             return this;
147         }
148 
149         public Builder setRequestDelegCreds(final Option requestDelegCreds) {
150             this.requestDelegCreds = requestDelegCreds;
151             return this;
152         }
153 
154         public KerberosConfig build() {
155             return new KerberosConfig(
156                     stripPort,
157                     useCanonicalHostname,
158                     requestDelegCreds);
159         }
160 
161     }
162 
163 }