|
18 | 18 |
|
19 | 19 | package org.apache.hadoop.hbase.rest;
|
20 | 20 |
|
| 21 | +import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; |
21 | 22 | import java.lang.management.ManagementFactory;
|
22 | 23 | import java.util.ArrayList;
|
| 24 | +import java.util.EnumSet; |
23 | 25 | import java.util.List;
|
24 | 26 | import java.util.Map;
|
25 |
| -import java.util.EnumSet; |
26 | 27 | import java.util.concurrent.ArrayBlockingQueue;
|
27 |
| - |
28 |
| -import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; |
| 28 | +import javax.servlet.DispatcherType; |
29 | 29 | import org.apache.commons.lang3.ArrayUtils;
|
30 |
| -import org.apache.yetus.audience.InterfaceAudience; |
31 | 30 | import org.apache.hadoop.conf.Configuration;
|
32 | 31 | import org.apache.hadoop.hbase.HBaseConfiguration;
|
33 | 32 | import org.apache.hadoop.hbase.HBaseInterfaceAudience;
|
| 33 | +import org.apache.hadoop.hbase.http.ClickjackingPreventionFilter; |
| 34 | +import org.apache.hadoop.hbase.http.HttpServerUtil; |
34 | 35 | import org.apache.hadoop.hbase.http.InfoServer;
|
| 36 | +import org.apache.hadoop.hbase.http.SecurityHeadersFilter; |
35 | 37 | import org.apache.hadoop.hbase.log.HBaseMarkers;
|
36 | 38 | import org.apache.hadoop.hbase.rest.filter.AuthFilter;
|
37 | 39 | import org.apache.hadoop.hbase.rest.filter.GzipFilter;
|
38 | 40 | import org.apache.hadoop.hbase.rest.filter.RestCsrfPreventionFilter;
|
39 | 41 | import org.apache.hadoop.hbase.security.UserProvider;
|
40 | 42 | import org.apache.hadoop.hbase.util.DNS;
|
41 |
| -import org.apache.hadoop.hbase.http.HttpServerUtil; |
42 | 43 | import org.apache.hadoop.hbase.util.Pair;
|
43 | 44 | import org.apache.hadoop.hbase.util.ReflectionUtils;
|
44 | 45 | import org.apache.hadoop.hbase.util.Strings;
|
45 | 46 | import org.apache.hadoop.hbase.util.VersionInfo;
|
46 |
| - |
47 |
| -import org.apache.hbase.thirdparty.com.google.common.base.Preconditions; |
48 |
| -import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine; |
49 |
| -import org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter; |
50 |
| -import org.apache.hbase.thirdparty.org.apache.commons.cli.Options; |
51 |
| -import org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException; |
52 |
| -import org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser; |
53 |
| - |
| 47 | +import org.apache.yetus.audience.InterfaceAudience; |
54 | 48 | import org.eclipse.jetty.http.HttpVersion;
|
55 |
| -import org.eclipse.jetty.server.Server; |
56 |
| -import org.eclipse.jetty.server.HttpConnectionFactory; |
57 |
| -import org.eclipse.jetty.server.SslConnectionFactory; |
| 49 | +import org.eclipse.jetty.jmx.MBeanContainer; |
58 | 50 | import org.eclipse.jetty.server.HttpConfiguration;
|
59 |
| -import org.eclipse.jetty.server.ServerConnector; |
| 51 | +import org.eclipse.jetty.server.HttpConnectionFactory; |
60 | 52 | import org.eclipse.jetty.server.SecureRequestCustomizer;
|
61 |
| -import org.eclipse.jetty.util.ssl.SslContextFactory; |
| 53 | +import org.eclipse.jetty.server.Server; |
| 54 | +import org.eclipse.jetty.server.ServerConnector; |
| 55 | +import org.eclipse.jetty.server.SslConnectionFactory; |
| 56 | +import org.eclipse.jetty.servlet.FilterHolder; |
62 | 57 | import org.eclipse.jetty.servlet.ServletContextHandler;
|
63 | 58 | import org.eclipse.jetty.servlet.ServletHolder;
|
| 59 | +import org.eclipse.jetty.util.ssl.SslContextFactory; |
64 | 60 | import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
65 |
| -import org.eclipse.jetty.jmx.MBeanContainer; |
66 |
| -import org.eclipse.jetty.servlet.FilterHolder; |
67 |
| - |
68 | 61 | import org.glassfish.jersey.server.ResourceConfig;
|
69 | 62 | import org.glassfish.jersey.servlet.ServletContainer;
|
70 | 63 | import org.slf4j.Logger;
|
71 | 64 | import org.slf4j.LoggerFactory;
|
72 |
| - |
73 |
| -import javax.servlet.DispatcherType; |
| 65 | +import org.apache.hbase.thirdparty.com.google.common.base.Preconditions; |
| 66 | +import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine; |
| 67 | +import org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter; |
| 68 | +import org.apache.hbase.thirdparty.org.apache.commons.cli.Options; |
| 69 | +import org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException; |
| 70 | +import org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser; |
74 | 71 |
|
75 | 72 | /**
|
76 | 73 | * Main class for launching REST gateway as a servlet hosted by Jetty.
|
@@ -137,6 +134,23 @@ void addCSRFFilter(ServletContextHandler ctxHandler, Configuration conf) {
|
137 | 134 | }
|
138 | 135 | }
|
139 | 136 |
|
| 137 | + private void addClickjackingPreventionFilter(ServletContextHandler ctxHandler, |
| 138 | + Configuration conf) { |
| 139 | + FilterHolder holder = new FilterHolder(); |
| 140 | + holder.setName("clickjackingprevention"); |
| 141 | + holder.setClassName(ClickjackingPreventionFilter.class.getName()); |
| 142 | + holder.setInitParameters(ClickjackingPreventionFilter.getDefaultParameters(conf)); |
| 143 | + ctxHandler.addFilter(holder, PATH_SPEC_ANY, EnumSet.allOf(DispatcherType.class)); |
| 144 | + } |
| 145 | + |
| 146 | + private void addSecurityHeadersFilter(ServletContextHandler ctxHandler, Configuration conf) { |
| 147 | + FilterHolder holder = new FilterHolder(); |
| 148 | + holder.setName("securityheaders"); |
| 149 | + holder.setClassName(SecurityHeadersFilter.class.getName()); |
| 150 | + holder.setInitParameters(SecurityHeadersFilter.getDefaultParameters(conf)); |
| 151 | + ctxHandler.addFilter(holder, PATH_SPEC_ANY, EnumSet.allOf(DispatcherType.class)); |
| 152 | + } |
| 153 | + |
140 | 154 | // login the server principal (if using secure Hadoop)
|
141 | 155 | private static Pair<FilterHolder, Class<? extends ServletContainer>> loginServerPrincipal(
|
142 | 156 | UserProvider userProvider, Configuration conf) throws Exception {
|
@@ -349,6 +363,8 @@ public synchronized void run() throws Exception {
|
349 | 363 | ctxHandler.addFilter(filter, PATH_SPEC_ANY, EnumSet.of(DispatcherType.REQUEST));
|
350 | 364 | }
|
351 | 365 | addCSRFFilter(ctxHandler, conf);
|
| 366 | + addClickjackingPreventionFilter(ctxHandler, conf); |
| 367 | + addSecurityHeadersFilter(ctxHandler, conf); |
352 | 368 | HttpServerUtil.constrainHttpMethods(ctxHandler, servlet.getConfiguration()
|
353 | 369 | .getBoolean(REST_HTTP_ALLOW_OPTIONS_METHOD, REST_HTTP_ALLOW_OPTIONS_METHOD_DEFAULT));
|
354 | 370 |
|
|
0 commit comments