@Test public void testListCredentials() throws Exception { PrincipalKeyCredential credential1 = new PrincipalKeyCredential("username1", "password1"); PrincipalKeyCredential credential2 = new PrincipalKeyCredential("username2", "password2"); PrincipalKeyCredential credential3 = new PrincipalKeyCredential("username3", "password3"); PrincipalKeyCredential credential4 = new PrincipalKeyCredential("username4", "password4"); credentialStoreService.setCredential(CLUSTER_NAME, "test1", credential1, CredentialStoreType.PERSISTED); credentialStoreService.setCredential(CLUSTER_NAME, "test2", credential2, CredentialStoreType.PERSISTED); credentialStoreService.setCredential(CLUSTER_NAME, "test3", credential3, CredentialStoreType.TEMPORARY); credentialStoreService.setCredential(CLUSTER_NAME, "test4", credential4, CredentialStoreType.TEMPORARY); Map<String, CredentialStoreType> credentials = credentialStoreService.listCredentials(CLUSTER_NAME); Assert.assertNotNull(credentials); Assert.assertEquals(4, credentials.size()); Assert.assertEquals(CredentialStoreType.PERSISTED, credentials.get("test1")); Assert.assertEquals(CredentialStoreType.PERSISTED, credentials.get("test2")); Assert.assertEquals(CredentialStoreType.TEMPORARY, credentials.get("test3")); Assert.assertEquals(CredentialStoreType.TEMPORARY, credentials.get("test4")); }
@Override public Map<String, CredentialStoreType> listCredentials(String clusterName) throws AmbariException { if (!isInitialized()) { throw new AmbariException("This CredentialStoreService has not yet been initialized"); } Collection<String> persistedAliases = isInitialized(CredentialStoreType.PERSISTED) ? persistedCredentialStore.listCredentials() : null; Collection<String> temporaryAliases = isInitialized(CredentialStoreType.TEMPORARY) ? temporaryCredentialStore.listCredentials() : null; Map<String, CredentialStoreType> map = new HashMap<String, CredentialStoreType>(); if (persistedAliases != null) { for (String alias : persistedAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.PERSISTED); } } } if (temporaryAliases != null) { for (String alias : temporaryAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.TEMPORARY); } } } return map; }
CredentialStoreServiceImpl implements CredentialStoreService { @Override public Map<String, CredentialStoreType> listCredentials(String clusterName) throws AmbariException { if (!isInitialized()) { throw new AmbariException("This CredentialStoreService has not yet been initialized"); } Collection<String> persistedAliases = isInitialized(CredentialStoreType.PERSISTED) ? persistedCredentialStore.listCredentials() : null; Collection<String> temporaryAliases = isInitialized(CredentialStoreType.TEMPORARY) ? temporaryCredentialStore.listCredentials() : null; Map<String, CredentialStoreType> map = new HashMap<String, CredentialStoreType>(); if (persistedAliases != null) { for (String alias : persistedAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.PERSISTED); } } } if (temporaryAliases != null) { for (String alias : temporaryAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.TEMPORARY); } } } return map; } }
CredentialStoreServiceImpl implements CredentialStoreService { @Override public Map<String, CredentialStoreType> listCredentials(String clusterName) throws AmbariException { if (!isInitialized()) { throw new AmbariException("This CredentialStoreService has not yet been initialized"); } Collection<String> persistedAliases = isInitialized(CredentialStoreType.PERSISTED) ? persistedCredentialStore.listCredentials() : null; Collection<String> temporaryAliases = isInitialized(CredentialStoreType.TEMPORARY) ? temporaryCredentialStore.listCredentials() : null; Map<String, CredentialStoreType> map = new HashMap<String, CredentialStoreType>(); if (persistedAliases != null) { for (String alias : persistedAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.PERSISTED); } } } if (temporaryAliases != null) { for (String alias : temporaryAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.TEMPORARY); } } } return map; } @Inject  CredentialStoreServiceImpl(Configuration configuration, SecurePasswordHelper securePasswordHelper); }
CredentialStoreServiceImpl implements CredentialStoreService { @Override public Map<String, CredentialStoreType> listCredentials(String clusterName) throws AmbariException { if (!isInitialized()) { throw new AmbariException("This CredentialStoreService has not yet been initialized"); } Collection<String> persistedAliases = isInitialized(CredentialStoreType.PERSISTED) ? persistedCredentialStore.listCredentials() : null; Collection<String> temporaryAliases = isInitialized(CredentialStoreType.TEMPORARY) ? temporaryCredentialStore.listCredentials() : null; Map<String, CredentialStoreType> map = new HashMap<String, CredentialStoreType>(); if (persistedAliases != null) { for (String alias : persistedAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.PERSISTED); } } } if (temporaryAliases != null) { for (String alias : temporaryAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.TEMPORARY); } } } return map; } @Inject  CredentialStoreServiceImpl(Configuration configuration, SecurePasswordHelper securePasswordHelper); synchronized void initializeTemporaryCredentialStore(long retentionDuration, TimeUnit units, boolean activelyPurge); synchronized void initializePersistedCredentialStore(File credentialStoreLocation, MasterKeyService masterKeyService); @Override void setCredential(String clusterName, String alias, Credential credential, CredentialStoreType credentialStoreType); @Override Credential getCredential(String clusterName, String alias); @Override Credential getCredential(String clusterName, String alias, CredentialStoreType credentialStoreType); @Override void removeCredential(String clusterName, String alias); @Override void removeCredential(String clusterName, String alias, CredentialStoreType credentialStoreType); @Override boolean containsCredential(String clusterName, String alias); @Override boolean containsCredential(String clusterName, String alias, CredentialStoreType credentialStoreType); @Override CredentialStoreType getCredentialStoreType(String clusterName, String alias); @Override Map<String, CredentialStoreType> listCredentials(String clusterName); @Override synchronized boolean isInitialized(); @Override synchronized boolean isInitialized(CredentialStoreType credentialStoreType); static String canonicalizeAlias(String clusterName, String alias); static String decanonicalizeAlias(String clusterName, String canonicaizedAlias); }
CredentialStoreServiceImpl implements CredentialStoreService { @Override public Map<String, CredentialStoreType> listCredentials(String clusterName) throws AmbariException { if (!isInitialized()) { throw new AmbariException("This CredentialStoreService has not yet been initialized"); } Collection<String> persistedAliases = isInitialized(CredentialStoreType.PERSISTED) ? persistedCredentialStore.listCredentials() : null; Collection<String> temporaryAliases = isInitialized(CredentialStoreType.TEMPORARY) ? temporaryCredentialStore.listCredentials() : null; Map<String, CredentialStoreType> map = new HashMap<String, CredentialStoreType>(); if (persistedAliases != null) { for (String alias : persistedAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.PERSISTED); } } } if (temporaryAliases != null) { for (String alias : temporaryAliases) { if (isAliasRequested(clusterName, alias)) { map.put(decanonicalizeAlias(clusterName, alias), CredentialStoreType.TEMPORARY); } } } return map; } @Inject  CredentialStoreServiceImpl(Configuration configuration, SecurePasswordHelper securePasswordHelper); synchronized void initializeTemporaryCredentialStore(long retentionDuration, TimeUnit units, boolean activelyPurge); synchronized void initializePersistedCredentialStore(File credentialStoreLocation, MasterKeyService masterKeyService); @Override void setCredential(String clusterName, String alias, Credential credential, CredentialStoreType credentialStoreType); @Override Credential getCredential(String clusterName, String alias); @Override Credential getCredential(String clusterName, String alias, CredentialStoreType credentialStoreType); @Override void removeCredential(String clusterName, String alias); @Override void removeCredential(String clusterName, String alias, CredentialStoreType credentialStoreType); @Override boolean containsCredential(String clusterName, String alias); @Override boolean containsCredential(String clusterName, String alias, CredentialStoreType credentialStoreType); @Override CredentialStoreType getCredentialStoreType(String clusterName, String alias); @Override Map<String, CredentialStoreType> listCredentials(String clusterName); @Override synchronized boolean isInitialized(); @Override synchronized boolean isInitialized(CredentialStoreType credentialStoreType); static String canonicalizeAlias(String clusterName, String alias); static String decanonicalizeAlias(String clusterName, String canonicaizedAlias);  }