KeyManagerConfigurer extends SecurityConfigurerAdapter<Void, ServiceProviderBuilder> { @Override public void configure(ServiceProviderBuilder builder) throws Exception { if (keyManagerBean == null) { if (keyManager == null) { privateKeyDERLocation = Optional.ofNullable(privateKeyDERLocation).orElseGet(config::getPrivateKeyDerLocation); publicKeyPEMLocation = Optional.ofNullable(publicKeyPEMLocation).orElseGet(config::getPublicKeyPemLocation); defaultKey = Optional.ofNullable(defaultKey).orElseGet(config::getDefaultKey); keyPasswords = Optional.ofNullable(keyPasswords).orElseGet(config::getKeyPasswords); storePass = Optional.ofNullable(storePass).orElseGet(config::getStorePass); storeLocation = Optional.ofNullable(storeLocation).orElseGet(config::getStoreLocation); if (keyStore == null) { if (storeLocation == null) { if (privateKeyDERLocation == null || publicKeyPEMLocation == null) { keyManager = new EmptyKeyManager(); } else { validateDefaultKeyAndPasswords(); keyStore = keystoreFactory.loadKeystore(publicKeyPEMLocation, privateKeyDERLocation, defaultKey, ""); keyManager = new JKSKeyManager(keyStore, keyPasswords, defaultKey); } } else { validateDefaultKeyAndPasswords(); keyManager = new JKSKeyManager(resourceLoader.getResource(storeLocation), storePass, keyPasswords, defaultKey); } } else { keyManager = new JKSKeyManager(keyStore, keyPasswords, defaultKey); } } builder.setSharedObject(KeyManager.class, keyManager); } } KeyManagerConfigurer(KeyManager keyManager);  KeyManagerConfigurer(); @Override void init(ServiceProviderBuilder builder); @Override void configure(ServiceProviderBuilder builder); KeyManagerConfigurer keyStore(KeyStore keyStore); KeyManagerConfigurer publicKeyPEMLocation(String publicKeyPEMLocation); KeyManagerConfigurer privateKeyDERLocation(String privateKeyDERLocation); KeyManagerConfigurer storeLocation(String storeLocation); KeyManagerConfigurer storePass(String storePass); KeyManagerConfigurer keyPasswords(Map<String, String> keyPasswords); KeyManagerConfigurer keyPassword(String key, String password); KeyManagerConfigurer defaultKey(String defaultKey);  }
@Test public void configure() throws Exception { KeyManagerConfigurer configurer = new KeyManagerConfigurer(); configurer.init(builder); configurer.configure(builder); verify(builder).setSharedObject(eq(KeyManager.class), any(KeyManager.class)); }