@Override public Vault load(final Path directory, final String masterkey, final byte[] pepper) throws VaultUnlockCancelException { synchronized(registry) { if(registry.contains(directory)) { return registry.find(session, directory); } final Vault vault = VaultFactory.get(directory, masterkey, pepper); if(log.isInfoEnabled()) { log.info(String.format("Loading vault %s for session %s", vault, session)); } try { registry.add(vault.load(session, prompt, keychain)); } catch(BackgroundException e) { log.warn(String.format("Failure loading vault %s. %s", vault, e.getDetail())); throw new VaultUnlockCancelException(vault, e); } return vault; } } }
@Override public void shutdown() { try { if(log.isInfoEnabled()) { log.info(String.format("Close connection pool %s", this)); } this.evict(); pool.close(); } catch(Exception e) { log.warn(String.format("Failure closing connection pool %s", e.getMessage())); } finally { registry.clear(); } }
/** * Wrap proxy with cryptographic feature * * @param type Feature type * @param feature Proxy implementation to wrap with vault features * @return Feature implementation or null when not supported */ @SuppressWarnings("unchecked") public <T> T getFeature(final Class<T> type, final T feature) { return registry.getFeature(this, type, feature); }
@Override public void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) throws BackgroundException { for(Map.Entry<TransferItem, TransferStatus> file : files.entrySet()) { registry.find(session, file.getKey().remote).getFeature(session, Bulk.class, proxy).post(type, Collections.singletonMap(file.getKey(), file.getValue()), callback); } }
@Override public R pre(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) throws BackgroundException { for(Map.Entry<TransferItem, TransferStatus> file : files.entrySet()) { registry.find(session, file.getKey().remote).getFeature(session, Bulk.class, proxy).pre(type, Collections.singletonMap(file.getKey(), file.getValue()), callback); } return proxy.pre(type, files, callback); }
@Override public void delete(final List<Path> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { final Map<Vault, List<Path>> vaults = new HashMap<>(); for(Path file : files) { final Vault vault = registry.find(session, file); final List<Path> sorted; if(vaults.containsKey(vault)) { sorted = vaults.get(vault); } else { sorted = new ArrayList<>(); } sorted.add(file); vaults.put(vault, sorted); } for(Map.Entry<Vault, List<Path>> entry : vaults.entrySet()) { final Vault vault = entry.getKey(); final Delete feature = vault.getFeature(session, Delete.class, proxy); feature.delete(entry.getValue(), prompt, callback); } }
@Override public void shutdown() { lock.lock(); try { try { session.close(); } catch(BackgroundException e) { log.warn(String.format("Failure closing session. %s", e.getMessage())); } finally { registry.clear(); } } finally { lock.unlock(); } }
@Override @SuppressWarnings("unchecked") public T lock(final Path file) throws BackgroundException { return (T) registry.find(session, file).getFeature(session, Lock.class, proxy).lock(file); }
@Override public void evict() { lock.lock(); try { try { session.close(); } catch(BackgroundException e) { log.warn(String.format("Ignore failure closing connection. %s", e.getMessage())); } finally { session.removeListener(transcript); registry.clear(); } } finally { lock.unlock(); } }
@Override @SuppressWarnings("unchecked") public Output upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { return (Output) registry.find(session, file).getFeature(session, Upload.class, proxy).upload(file, local, throttle, listener, status, callback); }
@Override public boolean isRevertable(final Path file) { try { return registry.find(session, file).getFeature(session, Versioning.class, proxy).isRevertable(file); } catch(VaultUnlockCancelException e) { return false; } }
@Override @SuppressWarnings("unchecked") public void unlock(final Path file, final T token) throws BackgroundException { registry.find(session, file).getFeature(session, Lock.class, proxy).unlock(file, token); }
@Override public LifecycleConfiguration getConfiguration(final Path container) throws BackgroundException { return registry.find(session, container).getFeature(session, Lifecycle.class, proxy).getConfiguration(container); }
@Override public void setEncryption(final Path file, final Algorithm algorithm) throws BackgroundException { registry.find(session, file).getFeature(session, Encryption.class, proxy).setEncryption(file, algorithm); }
@Override public Algorithm getDefault(final Path file) throws BackgroundException { return registry.find(session, file).getFeature(session, Encryption.class, proxy).getDefault(file); }
@Override public void setPermission(final Path file, final Acl acl) throws BackgroundException { registry.find(session, file).getFeature(session, AclPermission.class, proxy).setPermission(file, acl); }
@Override public LoggingConfiguration getConfiguration(final Path container) throws BackgroundException { return registry.find(session, container).getFeature(session, Logging.class, proxy).getConfiguration(container); }
@Override public void setUnixOwner(final Path file, final String owner) throws BackgroundException { registry.find(session, file).getFeature(session, UnixPermission.class, proxy).setUnixOwner(file, owner); }
@Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { registry.find(session, file).getFeature(session, UnixPermission.class, proxy).setUnixPermission(file, permission); }
@Override public VersioningConfiguration getConfiguration(final Path container) throws BackgroundException { return registry.find(session, container).getFeature(session, Versioning.class, proxy).getConfiguration(container); }