/** * List of all the entries in the secure store belonging to the specified namespace. No filtering or authentication * is done here. * @return A list of {@link SecureStoreMetadata} objects representing the data stored in the store. * @param namespace The namespace this key belongs to. * @throws NamespaceNotFoundException If the specified namespace does not exist. * @throws IOException If there was a problem reading from the keystore. */ @Override public List<SecureStoreMetadata> list(String namespace) throws Exception { checkNamespaceExists(namespace); readLock.lock(); try { Enumeration<String> aliases = keyStore.aliases(); List<SecureStoreMetadata> metadataList = new ArrayList<>(); String prefix = namespace + NAME_SEPARATOR; while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); // Filter out elements not in this namespace. if (alias.startsWith(prefix)) { metadataList.add(getSecureStoreMetadata(alias)); } } return metadataList; } catch (KeyStoreException e) { throw new IOException("Failed to get the list of elements from the secure store.", e); } finally { readLock.unlock(); } }
public void put(String namespace, String name, String data, @Nullable String description, Map<String, String> properties) throws Exception { checkNamespaceExists(namespace); String keyName = getKeyName(namespace, name); SecureStoreMetadata meta = new SecureStoreMetadata(name, description, System.currentTimeMillis(), properties);
/** * Returns the data stored in the secure store. * @param namespace The namespace this key belongs to. * @param name Name of the data element. * @return An object representing the securely stored data associated with the name. * @throws NamespaceNotFoundException If the specified namespace does not exist. * @throws NotFoundException If the key is not found in the store. * @throws IOException If there was a problem reading from the store. */ @Override public SecureStoreData get(String namespace, String name) throws Exception { checkNamespaceExists(namespace); String keyName = getKeyName(namespace, name); readLock.lock(); try { if (!keyStore.containsAlias(keyName)) { throw new NotFoundException(name + " not found in the secure store."); } Key key = keyStore.getKey(keyName, password); return deserialize(key.getEncoded()); } catch (NoSuchAlgorithmException | UnrecoverableKeyException | KeyStoreException e) { throw new IOException("Unable to retrieve the key " + name, e); } finally { readLock.unlock(); } }
checkNamespaceExists(namespace); String keyName = getKeyName(namespace, name); Key key = null;