@Test public void testPassword() throws Exception { String password = CredentialReader.getDecryptedString(keystoreFile, "TestCredential2"); assertEquals("PassworD123", password); String[] argsdeleteCommand = new String[] {"delete", "TestCredential2", "-provider", "jceks: buildks buildksOBJ = new buildks(); buildksOBJ.deleteCredential(argsdeleteCommand, true); }
public static String getDecryptedString(String CrendentialProviderPath,String alias) { String credential=null; try{ if(CrendentialProviderPath==null || alias==null){ return null; } char[] pass = null; Configuration conf = new Configuration(); String crendentialProviderPrefixJceks=JavaKeyStoreProvider.SCHEME_NAME + ": String crendentialProviderPrefixLocalJceks="localjceks: crendentialProviderPrefixJceks=crendentialProviderPrefixJceks.toLowerCase(); CrendentialProviderPath=CrendentialProviderPath.trim(); alias=alias.trim(); if(CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixJceks) || CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixLocalJceks)){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, CrendentialProviderPath); }else{ if(CrendentialProviderPath.startsWith("/")){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": }else{ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": } } List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); List<String> aliasesList=new ArrayList<String>(); CredentialProvider.CredentialEntry credEntry=null; for(CredentialProvider provider: providers) { aliasesList=provider.getAliases(); if(aliasesList!=null && aliasesList.contains(alias.toLowerCase())){ credEntry=null; credEntry= provider.getCredentialEntry(alias); pass = credEntry.getCredential(); if(pass!=null && pass.length>0){ credential=String.valueOf(pass); break; } } } }catch(Exception ex){ ex.printStackTrace(); credential=null; } return credential; }
CredentialReader { public static String getDecryptedString(String CrendentialProviderPath,String alias) { String credential=null; try{ if(CrendentialProviderPath==null || alias==null){ return null; } char[] pass = null; Configuration conf = new Configuration(); String crendentialProviderPrefixJceks=JavaKeyStoreProvider.SCHEME_NAME + ": String crendentialProviderPrefixLocalJceks="localjceks: crendentialProviderPrefixJceks=crendentialProviderPrefixJceks.toLowerCase(); CrendentialProviderPath=CrendentialProviderPath.trim(); alias=alias.trim(); if(CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixJceks) || CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixLocalJceks)){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, CrendentialProviderPath); }else{ if(CrendentialProviderPath.startsWith("/")){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": }else{ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": } } List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); List<String> aliasesList=new ArrayList<String>(); CredentialProvider.CredentialEntry credEntry=null; for(CredentialProvider provider: providers) { aliasesList=provider.getAliases(); if(aliasesList!=null && aliasesList.contains(alias.toLowerCase())){ credEntry=null; credEntry= provider.getCredentialEntry(alias); pass = credEntry.getCredential(); if(pass!=null && pass.length>0){ credential=String.valueOf(pass); break; } } } }catch(Exception ex){ ex.printStackTrace(); credential=null; } return credential; } }
CredentialReader { public static String getDecryptedString(String CrendentialProviderPath,String alias) { String credential=null; try{ if(CrendentialProviderPath==null || alias==null){ return null; } char[] pass = null; Configuration conf = new Configuration(); String crendentialProviderPrefixJceks=JavaKeyStoreProvider.SCHEME_NAME + ": String crendentialProviderPrefixLocalJceks="localjceks: crendentialProviderPrefixJceks=crendentialProviderPrefixJceks.toLowerCase(); CrendentialProviderPath=CrendentialProviderPath.trim(); alias=alias.trim(); if(CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixJceks) || CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixLocalJceks)){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, CrendentialProviderPath); }else{ if(CrendentialProviderPath.startsWith("/")){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": }else{ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": } } List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); List<String> aliasesList=new ArrayList<String>(); CredentialProvider.CredentialEntry credEntry=null; for(CredentialProvider provider: providers) { aliasesList=provider.getAliases(); if(aliasesList!=null && aliasesList.contains(alias.toLowerCase())){ credEntry=null; credEntry= provider.getCredentialEntry(alias); pass = credEntry.getCredential(); if(pass!=null && pass.length>0){ credential=String.valueOf(pass); break; } } } }catch(Exception ex){ ex.printStackTrace(); credential=null; } return credential; }  }
CredentialReader { public static String getDecryptedString(String CrendentialProviderPath,String alias) { String credential=null; try{ if(CrendentialProviderPath==null || alias==null){ return null; } char[] pass = null; Configuration conf = new Configuration(); String crendentialProviderPrefixJceks=JavaKeyStoreProvider.SCHEME_NAME + ": String crendentialProviderPrefixLocalJceks="localjceks: crendentialProviderPrefixJceks=crendentialProviderPrefixJceks.toLowerCase(); CrendentialProviderPath=CrendentialProviderPath.trim(); alias=alias.trim(); if(CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixJceks) || CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixLocalJceks)){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, CrendentialProviderPath); }else{ if(CrendentialProviderPath.startsWith("/")){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": }else{ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": } } List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); List<String> aliasesList=new ArrayList<String>(); CredentialProvider.CredentialEntry credEntry=null; for(CredentialProvider provider: providers) { aliasesList=provider.getAliases(); if(aliasesList!=null && aliasesList.contains(alias.toLowerCase())){ credEntry=null; credEntry= provider.getCredentialEntry(alias); pass = credEntry.getCredential(); if(pass!=null && pass.length>0){ credential=String.valueOf(pass); break; } } } }catch(Exception ex){ ex.printStackTrace(); credential=null; } return credential; }  static String getDecryptedString(String CrendentialProviderPath,String alias); }
CredentialReader { public static String getDecryptedString(String CrendentialProviderPath,String alias) { String credential=null; try{ if(CrendentialProviderPath==null || alias==null){ return null; } char[] pass = null; Configuration conf = new Configuration(); String crendentialProviderPrefixJceks=JavaKeyStoreProvider.SCHEME_NAME + ": String crendentialProviderPrefixLocalJceks="localjceks: crendentialProviderPrefixJceks=crendentialProviderPrefixJceks.toLowerCase(); CrendentialProviderPath=CrendentialProviderPath.trim(); alias=alias.trim(); if(CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixJceks) || CrendentialProviderPath.toLowerCase().startsWith(crendentialProviderPrefixLocalJceks)){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, CrendentialProviderPath); }else{ if(CrendentialProviderPath.startsWith("/")){ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": }else{ conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, JavaKeyStoreProvider.SCHEME_NAME + ": } } List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf); List<String> aliasesList=new ArrayList<String>(); CredentialProvider.CredentialEntry credEntry=null; for(CredentialProvider provider: providers) { aliasesList=provider.getAliases(); if(aliasesList!=null && aliasesList.contains(alias.toLowerCase())){ credEntry=null; credEntry= provider.getCredentialEntry(alias); pass = credEntry.getCredential(); if(pass!=null && pass.length>0){ credential=String.valueOf(pass); break; } } } }catch(Exception ex){ ex.printStackTrace(); credential=null; } return credential; }  static String getDecryptedString(String CrendentialProviderPath,String alias);  }