Skip to content

Commit d040907

Browse files
committed
HIVE-29112: refactored ServletServerBuilder#createConnector();
- removed useless method ServletServerBuilder#createSslContextFactory(); - removed useless method ServletSecurity#createSslContextFactory();
1 parent d6e4f45 commit d040907

2 files changed

Lines changed: 14 additions & 43 deletions

File tree

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ServletSecurity.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,7 @@ static void loginServerPrincipal(Configuration conf) throws IOException {
320320
* @throws IOException if getting password fails
321321
*/
322322
static SslContextFactory createSslContextFactory(Configuration conf) throws IOException {
323-
return createSslContextFactoryIf(conf, MetastoreConf.ConfVars.USE_SSL);
324-
}
325-
326-
/**
327-
* Creates an SSL context factory if a configuration variable states so.
328-
* @param conf the configuration
329-
* @param condition the condition variable to check for SSL
330-
* @return null if no ssl in config, an instance otherwise
331-
* @throws IOException if getting password fails
332-
*/
333-
static SslContextFactory createSslContextFactoryIf(Configuration conf, MetastoreConf.ConfVars condition)
334-
throws IOException {
335-
final boolean useSsl = MetastoreConf.getBoolVar(conf, condition);
323+
final boolean useSsl = MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.USE_SSL);
336324
if (!useSsl) {
337325
return null;
338326
}

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ServletServerBuilder.java

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,6 @@ private Server createServer() {
164164
return server;
165165
}
166166

167-
/**
168-
* Create an SSL context factory using the configuration.
169-
*
170-
* @param conf The configuration to use
171-
* @return The created SslContextFactory or null if creation failed
172-
*/
173-
private static SslContextFactory createSslContextFactory(Configuration conf) throws IOException {
174-
return ServletSecurity.createSslContextFactoryIf(conf, MetastoreConf.ConfVars.USE_SSL);
175-
}
176-
177167
/**
178168
* Create an HTTP or HTTPS connector.
179169
*
@@ -185,26 +175,19 @@ private static SslContextFactory createSslContextFactory(Configuration conf) thr
185175
*/
186176
private ServerConnector createConnector(Server server, SslContextFactory sslContextFactory, int port) {
187177
final ServerConnector connector;
188-
if (sslContextFactory == null) {
189-
connector = new ServerConnector(server);
190-
connector.setName(HTTP);
191-
HttpConnectionFactory httpFactory = connector.getConnectionFactory(HttpConnectionFactory.class);
192-
// do not leak information
193-
if (httpFactory != null) {
194-
HttpConfiguration httpConf = httpFactory.getHttpConfiguration();
195-
httpConf.setSendServerVersion(false);
196-
httpConf.setSendXPoweredBy(false);
197-
}
198-
} else {
199-
HttpConfiguration httpsConf = new HttpConfiguration();
200-
httpsConf.setSecureScheme(HTTPS);
201-
httpsConf.setSecurePort(port);
202-
// do not leak information
203-
httpsConf.setSendServerVersion(false);
204-
httpsConf.setSendXPoweredBy(false);
205-
httpsConf.addCustomizer(new SecureRequestCustomizer());
206-
connector = new ServerConnector(server, sslContextFactory, new HttpConnectionFactory(httpsConf));
178+
HttpConfiguration httpConf = new HttpConfiguration();
179+
// Do not leak information
180+
httpConf.setSendServerVersion(false);
181+
httpConf.setSendXPoweredBy(false);
182+
if (sslContextFactory != null) {
183+
httpConf.setSecureScheme(HTTPS);
184+
httpConf.setSecurePort(port);
185+
httpConf.addCustomizer(new SecureRequestCustomizer());
186+
connector = new ServerConnector(server, sslContextFactory, new HttpConnectionFactory(httpConf));
207187
connector.setName(HTTPS);
188+
} else {
189+
connector = new ServerConnector(server, new HttpConnectionFactory(httpConf));
190+
connector.setName(HTTP);
208191
}
209192
connector.setPort(port);
210193
connector.setReuseAddress(true);
@@ -253,7 +236,7 @@ public Server startServer() throws Exception {
253236
}
254237
final Server server = createServer();
255238
// create the connectors
256-
final SslContextFactory sslContextFactory = createSslContextFactory(configuration);
239+
final SslContextFactory sslContextFactory = ServletSecurity.createSslContextFactory(configuration);
257240
final ServerConnector[] connectors = new ServerConnector[size];
258241
final ServletContextHandler[] handlers = new ServletContextHandler[size];
259242
Iterator<Map.Entry<Integer, ServletContextHandler>> it = handlersMap.entrySet().iterator();

0 commit comments

Comments
 (0)