KeyManagerFactorySpiWrapper.java

  1. /*
  2.  * Copyright 2019-2021 the original author or authors.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *      https://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */

  16. package nl.altindag.ssl.keymanager;

  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;

  19. import javax.net.ssl.KeyManager;
  20. import javax.net.ssl.KeyManagerFactorySpi;
  21. import javax.net.ssl.ManagerFactoryParameters;
  22. import java.security.KeyStore;
  23. import java.util.Objects;

  24. class KeyManagerFactorySpiWrapper extends KeyManagerFactorySpi {

  25.     private static final Logger LOGGER = LoggerFactory.getLogger(KeyManagerFactorySpiWrapper.class);

  26.     private final KeyManager[] keyManagers;

  27.     KeyManagerFactorySpiWrapper(KeyManager keyManager) {
  28.         Objects.requireNonNull(keyManager);
  29.         this.keyManagers = new KeyManager[]{keyManager};
  30.     }

  31.     @Override
  32.     protected void engineInit(KeyStore keyStore, char[] keyStorePassword) {
  33.         LOGGER.info("Ignoring provided KeyStore");
  34.     }

  35.     @Override
  36.     protected void engineInit(ManagerFactoryParameters managerFactoryParameters) {
  37.         LOGGER.info("Ignoring provided ManagerFactoryParameters");
  38.     }

  39.     @Override
  40.     protected KeyManager[] engineGetKeyManagers() {
  41.         return keyManagers;
  42.     }

  43. }