public PrivateKey get ( KeyStoreChooser keyStoreChooser , PrivateKeyChooserByAlias privateKeyChooserByAlias ) { CacheKey cacheKey = new CacheKey ( keyStoreChooser . getKeyStoreName ( ) , privateKeyChooserByAlias . getAlias ( ) ) ; PrivateKey retrievedPrivateKey = cache . get ( cacheKey ) ; if ( retrievedPrivateKey != null ) { return retrievedPrivateKey ; } KeyStore keyStore = keyStoreRegistry . get ( keyStoreChooser ) ; if ( keyStore != null ) { PrivateKeyFactoryBean factory = new PrivateKeyFactoryBean ( ) ; factory . setKeystore ( keyStore ) ; factory . setAlias ( privateKeyChooserByAlias . getAlias ( ) ) ; factory . setPassword ( privateKeyChooserByAlias . getPassword ( ) ) ; try { factory . afterPropertiesSet ( ) ; PrivateKey privateKey = ( PrivateKey ) factory . getObject ( ) ; if ( privateKey != null ) { cache . put ( cacheKey , privateKey ) ; } return privateKey ; } catch ( Exception e ) { throw new PrivateKeyException ( "error initializing private key factory bean" , e ) ; } } return null ; }
Returns the selected private key or null if not found .