0

After my disastrous attempt at (not) installing dependencies, I'm back with a slight problem. I have a credstore created (mycredstore) that has an alias inside with a password I need to retrieve, but whenever Java goes in, it just says that the alias won't exist at all. How can I check that I do indeed have aliases to get to, or at least what's the name of the credential-store that I'm accessing?

I've tried accessing the keystore too, but that's no good since there's nothing there to retrieve. This is on Wildfly 26.0.0 Final, and Wildfly-elytron 2.1.0 Final. I've also tried to do it via CLIs, but I've had no luck whatsoever. This code is partially from https://github.com/wildfly-security-incubator/elytron-examples/blob/main/credential-store/src/main/java/org/wildfly/security/examples/CredentialStoreExample.java

      String clearTextPswd = null;
      Provider CREDENTIAL_STORE_PROVIDER = new WildFlyElytronCredentialStoreProvider();
      Provider PASSWORD_PROVIDER = new WildFlyElytronPasswordProvider();
      Security.addProvider(PASSWORD_PROVIDER);
      Password password = null;
      final String ALIAS = "dbPassword";
      
      Password storePassword = ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, "StorePassword".toCharArray());
      ProtectionParameter protectionParameter = new CredentialSourceProtectionParameter(IdentityCredentials.NONE.withCredential(new PasswordCredential(storePassword)));


        try {
            CredentialStore credentialStore = CredentialStore.getInstance("KeyStoreCredentialStore", CREDENTIAL_STORE_PROVIDER);
            HashMap<String, String> configuration = new HashMap<>();
            configuration.put("externalPath", "Wildfly\\standalone\\configuration\\credStore.cs");
            String aliasPwd = "";
            credentialStore.initialize(configuration, protectionParameter);
            System.out.println(credentialStore.isInitialized());

            
            System.out.println("************************************");
            System.out.println("Current Aliases: -");
            for (String aliasExist : credentialStore.getAliases()) {
                System.out.print(" - ");
                System.out.println(aliasExist);
                if (aliasExist.equals(ALIAS)) {
                    aliasPwd=aliasExist;
                }
            }
            System.out.println("************************************");
            
              
            
            if (aliasPwd.equals(ALIAS)) {
                password = credentialStore.retrieve(ALIAS, PasswordCredential.class).getPassword();
            } 
Cpt-Proxy
  • 39
  • 7

0 Answers0