CredentialStoreServiceImpl implements CredentialStoreService { @Override public boolean containsCredential(String clusterName, String alias) throws AmbariException { return containsCredential(clusterName, alias, CredentialStoreType.TEMPORARY) || containsCredential(clusterName, alias, CredentialStoreType.PERSISTED); } @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);  }
@Test public void testContainsCredential() 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); Assert.assertTrue(credentialStoreService.containsCredential(CLUSTER_NAME, "test1", CredentialStoreType.PERSISTED)); Assert.assertFalse(credentialStoreService.containsCredential(CLUSTER_NAME, "test1", CredentialStoreType.TEMPORARY)); Assert.assertFalse(credentialStoreService.containsCredential(CLUSTER_NAME, "test3", CredentialStoreType.PERSISTED)); Assert.assertFalse(credentialStoreService.containsCredential(CLUSTER_NAME, "test1", CredentialStoreType.TEMPORARY)); Assert.assertFalse(credentialStoreService.containsCredential(CLUSTER_NAME, "test3", CredentialStoreType.PERSISTED)); Assert.assertTrue(credentialStoreService.containsCredential(CLUSTER_NAME, "test3", CredentialStoreType.TEMPORARY)); Assert.assertTrue(credentialStoreService.containsCredential(CLUSTER_NAME, "test1")); Assert.assertTrue(credentialStoreService.containsCredential(CLUSTER_NAME, "test3")); }