1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.http;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.classification.InterfaceStability;
22 import org.apache.hadoop.conf.Configuration;
23
24
25
26
27 @InterfaceAudience.Private
28 @InterfaceStability.Unstable
29 public class HttpConfig {
30 private Policy policy;
31 public enum Policy {
32 HTTP_ONLY,
33 HTTPS_ONLY,
34 HTTP_AND_HTTPS;
35
36 public Policy fromString(String value) {
37 if (HTTPS_ONLY.name().equalsIgnoreCase(value)) {
38 return HTTPS_ONLY;
39 } else if (HTTP_AND_HTTPS.name().equalsIgnoreCase(value)) {
40 return HTTP_AND_HTTPS;
41 }
42 return HTTP_ONLY;
43 }
44
45 public boolean isHttpEnabled() {
46 return this == HTTP_ONLY || this == HTTP_AND_HTTPS;
47 }
48
49 public boolean isHttpsEnabled() {
50 return this == HTTPS_ONLY || this == HTTP_AND_HTTPS;
51 }
52 }
53
54 public HttpConfig(final Configuration conf) {
55 boolean sslEnabled = conf.getBoolean(
56 ServerConfigurationKeys.HBASE_SSL_ENABLED_KEY,
57 ServerConfigurationKeys.HBASE_SSL_ENABLED_DEFAULT);
58 policy = sslEnabled ? Policy.HTTPS_ONLY : Policy.HTTP_ONLY;
59 if (sslEnabled) {
60 conf.addResource("ssl-server.xml");
61 conf.addResource("ssl-client.xml");
62 }
63 }
64
65 public void setPolicy(Policy policy) {
66 this.policy = policy;
67 }
68
69 public boolean isSecure() {
70 return policy == Policy.HTTPS_ONLY;
71 }
72
73 public String getSchemePrefix() {
74 return (isSecure()) ? "https://" : "http://";
75 }
76
77 public String getScheme(Policy policy) {
78 return policy == Policy.HTTPS_ONLY ? "https://" : "http://";
79 }
80 }