@Test public void testSave() throws Exception { doAnswer(invoc -> { OrientKeyStoreData entity = (OrientKeyStoreData) invoc.getArguments()[0]; entity.setEntityMetadata(newEntityMetadata("1")); return null; }).when(storageManager).save(anyObject()); KeyStore keyStore = newKeyStoreWithData(); storage.save(keyStore, STORE_PASSWORD); assertThat(storage.modified(), is(false)); ArgumentCaptor<OrientKeyStoreData> entityCaptor = ArgumentCaptor.forClass(OrientKeyStoreData.class); verify(storageManager).save(entityCaptor.capture()); OrientKeyStoreData entity = entityCaptor.getValue(); assertThat(entity.getName(), is(KEY_STORE_NAME)); assertThat(entity.getBytes(), is(notNullValue())); keyStore = newKeyStore(); keyStore.load(new ByteArrayInputStream(entity.getBytes()), STORE_PASSWORD); assertThat(keyStore.containsAlias(CERT_ALIAS), is(true)); }
@Override public void save(final KeyStore keyStore, final char[] password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(16 * 1024); keyStore.store(baos, password); OrientKeyStoreData entity = new OrientKeyStoreData(); entity.setName(keyStoreName); entity.setBytes(baos.toByteArray()); storageManager.save(entity); loadedVersion = entity.getEntityMetadata().getVersion(); log.debug("Saved version {} of key store {}", loadedVersion, keyStoreName); }
OrientKeyStoreStorage extends ComponentSupport implements KeyStoreStorage { @Override public void save(final KeyStore keyStore, final char[] password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(16 * 1024); keyStore.store(baos, password); OrientKeyStoreData entity = new OrientKeyStoreData(); entity.setName(keyStoreName); entity.setBytes(baos.toByteArray()); storageManager.save(entity); loadedVersion = entity.getEntityMetadata().getVersion(); log.debug("Saved version {} of key store {}", loadedVersion, keyStoreName); } }
OrientKeyStoreStorage extends ComponentSupport implements KeyStoreStorage { @Override public void save(final KeyStore keyStore, final char[] password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(16 * 1024); keyStore.store(baos, password); OrientKeyStoreData entity = new OrientKeyStoreData(); entity.setName(keyStoreName); entity.setBytes(baos.toByteArray()); storageManager.save(entity); loadedVersion = entity.getEntityMetadata().getVersion(); log.debug("Saved version {} of key store {}", loadedVersion, keyStoreName); } OrientKeyStoreStorage(final OrientKeyStoreStorageManager storageManager, final String keyStoreName); }
OrientKeyStoreStorage extends ComponentSupport implements KeyStoreStorage { @Override public void save(final KeyStore keyStore, final char[] password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(16 * 1024); keyStore.store(baos, password); OrientKeyStoreData entity = new OrientKeyStoreData(); entity.setName(keyStoreName); entity.setBytes(baos.toByteArray()); storageManager.save(entity); loadedVersion = entity.getEntityMetadata().getVersion(); log.debug("Saved version {} of key store {}", loadedVersion, keyStoreName); } OrientKeyStoreStorage(final OrientKeyStoreStorageManager storageManager, final String keyStoreName); @VisibleForTesting String getKeyStoreName(); @Override boolean exists(); @Override boolean modified(); @Subscribe void onKeyStoreDataUpdated(final KeyStoreDataEvent event); @Override void load(final KeyStore keyStore, final char[] password); @Override void save(final KeyStore keyStore, final char[] password); @Override String toString(); }
OrientKeyStoreStorage extends ComponentSupport implements KeyStoreStorage { @Override public void save(final KeyStore keyStore, final char[] password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(16 * 1024); keyStore.store(baos, password); OrientKeyStoreData entity = new OrientKeyStoreData(); entity.setName(keyStoreName); entity.setBytes(baos.toByteArray()); storageManager.save(entity); loadedVersion = entity.getEntityMetadata().getVersion(); log.debug("Saved version {} of key store {}", loadedVersion, keyStoreName); } OrientKeyStoreStorage(final OrientKeyStoreStorageManager storageManager, final String keyStoreName); @VisibleForTesting String getKeyStoreName(); @Override boolean exists(); @Override boolean modified(); @Subscribe void onKeyStoreDataUpdated(final KeyStoreDataEvent event); @Override void load(final KeyStore keyStore, final char[] password); @Override void save(final KeyStore keyStore, final char[] password); @Override String toString();  }