ihuzenko commented on a change in pull request #2022: DRILL-7637: Add an option to retrieve MapR SSL truststore/keystore cr… URL: https://github.com/apache/drill/pull/2022#discussion_r392141040
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/ssl/SSLCredentialsProvider.java ########## @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.ssl; + +import java.util.Optional; +import java.util.function.BiFunction; + +/** + * Provides an implementation of credentials provider depending on "useMapRSSLConfig" option value + * and whether Drill was built with mapr profile or not. + */ +abstract class SSLCredentialsProvider { + + private static final String MAPR_CREDENTIALS_PROVIDER_CLIENT = "org.apache.drill.exec.ssl.SSLCredentialsProviderMaprClient"; + private static final String MAPR_CREDENTIALS_PROVIDER_SERVER = "org.apache.drill.exec.ssl.SSLCredentialsProviderMaprServer"; + + /** + * Provides a concrete implementation of {@link SSLCredentialsProvider}. + * + * @param getPropertyMethod a reference to a method to retrieve credentials from config: + * <ul> + * <li>String parameter1 - property name</li> + * <li>String parameter2 - default value</li> + * <li>returns the property value or default value</li> + * </ul> + * @param mode CLIENT or SERVER + * @param useMapRSSLConfig use a MapR credential provider + * @return concrete implementation of SSLCredentialsProvider + */ + static SSLCredentialsProvider getSSLCredentialsProvider(BiFunction<String, String, String> getPropertyMethod, SSLConfig.Mode mode, boolean useMapRSSLConfig) { + return useMapRSSLConfig ? + Optional.ofNullable(getMaprCredentialsProvider(mode)) + .orElse(new SSLCredentialsProviderImpl(getPropertyMethod)) : + new SSLCredentialsProviderImpl(getPropertyMethod); + } + + private static SSLCredentialsProvider getMaprCredentialsProvider(SSLConfig.Mode mode) { + try { + return (SSLCredentialsProvider) Class.forName(getMaprCredentialsProviderClassName(mode)).newInstance(); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + // This is expected if built without MapR profile + return null; + } + } + + private static String getMaprCredentialsProviderClassName(SSLConfig.Mode mode) { Review comment: there is no need to have a separate method for this, the switch-case can be placed directly into ```getMaprCredentialsProvider(SSLConfig.Mode mode)```. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
