HADOOP-14352. Make some HttpServer2 SSL properties optional (jzhuge via rkanter)

This commit is contained in:
Robert Kanter 2017-05-02 17:51:28 -07:00
parent cedaf4cab9
commit 8b82317fab

View File

@ -348,18 +348,17 @@ public Builder setXFrameOption(String option) {
/** /**
* A wrapper of {@link Configuration#getPassword(String)}. It returns * A wrapper of {@link Configuration#getPassword(String)}. It returns
* <code>String</code> instead of <code>char[]</code> and throws * <code>String</code> instead of <code>char[]</code>.
* {@link IOException} when the password not found.
* *
* @param conf the configuration * @param conf the configuration
* @param name the property name * @param name the property name
* @return the password string * @return the password string or null
*/ */
private static String getPassword(Configuration conf, String name) private static String getPasswordString(Configuration conf, String name)
throws IOException { throws IOException {
char[] passchars = conf.getPassword(name); char[] passchars = conf.getPassword(name);
if (passchars == null) { if (passchars == null) {
throw new IOException("Password " + name + " not found"); return null;
} }
return new String(passchars); return new String(passchars);
} }
@ -371,20 +370,30 @@ private void loadSSLConfiguration() throws IOException {
if (sslConf == null) { if (sslConf == null) {
return; return;
} }
needsClientAuth(sslConf.getBoolean( needsClientAuth = sslConf.getBoolean(
SSLFactory.SSL_SERVER_NEED_CLIENT_AUTH, SSLFactory.SSL_SERVER_NEED_CLIENT_AUTH,
SSLFactory.SSL_SERVER_NEED_CLIENT_AUTH_DEFAULT)); SSLFactory.SSL_SERVER_NEED_CLIENT_AUTH_DEFAULT);
keyStore(sslConf.get(SSLFactory.SSL_SERVER_KEYSTORE_LOCATION), keyStore = sslConf.getTrimmed(SSLFactory.SSL_SERVER_KEYSTORE_LOCATION);
getPassword(sslConf, SSLFactory.SSL_SERVER_KEYSTORE_PASSWORD), if (keyStore == null || keyStore.isEmpty()) {
sslConf.get(SSLFactory.SSL_SERVER_KEYSTORE_TYPE, throw new IOException(String.format("Property %s not specified",
SSLFactory.SSL_SERVER_KEYSTORE_TYPE_DEFAULT)); SSLFactory.SSL_SERVER_KEYSTORE_LOCATION));
keyPassword(getPassword(sslConf, }
SSLFactory.SSL_SERVER_KEYSTORE_KEYPASSWORD)); keyStorePassword = getPasswordString(sslConf,
trustStore(sslConf.get(SSLFactory.SSL_SERVER_TRUSTSTORE_LOCATION), SSLFactory.SSL_SERVER_KEYSTORE_PASSWORD);
getPassword(sslConf, SSLFactory.SSL_SERVER_TRUSTSTORE_PASSWORD), if (keyStorePassword == null) {
sslConf.get(SSLFactory.SSL_SERVER_TRUSTSTORE_TYPE, throw new IOException(String.format("Property %s not specified",
SSLFactory.SSL_SERVER_TRUSTSTORE_TYPE_DEFAULT)); SSLFactory.SSL_SERVER_KEYSTORE_PASSWORD));
excludeCiphers(sslConf.get(SSLFactory.SSL_SERVER_EXCLUDE_CIPHER_LIST)); }
keyStoreType = sslConf.get(SSLFactory.SSL_SERVER_KEYSTORE_TYPE,
SSLFactory.SSL_SERVER_KEYSTORE_TYPE_DEFAULT);
keyPassword = getPasswordString(sslConf,
SSLFactory.SSL_SERVER_KEYSTORE_KEYPASSWORD);
trustStore = sslConf.get(SSLFactory.SSL_SERVER_TRUSTSTORE_LOCATION);
trustStorePassword = getPasswordString(sslConf,
SSLFactory.SSL_SERVER_TRUSTSTORE_PASSWORD);
trustStoreType = sslConf.get(SSLFactory.SSL_SERVER_TRUSTSTORE_TYPE,
SSLFactory.SSL_SERVER_TRUSTSTORE_TYPE_DEFAULT);
excludeCiphers = sslConf.get(SSLFactory.SSL_SERVER_EXCLUDE_CIPHER_LIST);
} }
public HttpServer2 build() throws IOException { public HttpServer2 build() throws IOException {