java 从Elytron凭证存储获取密码

pn9klfpd  于 2023-05-27  发布在  Java
关注(0)|答案(1)|浏览(106)

我使用的通用代码已经粘贴在这里几次,以获得一个别名内的credstore在elytron这里的密码:
(Do忽略所有这些系统变量,我不能正常调试,所以我必须使用记录器)

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

      System.out.println("prueba1");
      
      
      System.out.println("prueba2");
      CredentialStore credentialStore = null;
      System.out.println("prueba3");
        try {
            credentialStore = CredentialStore.getInstance("KeyStoreCredentialStore", CREDENTIAL_STORE_PROVIDER);
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("prueba4");
        HashMap<String, String> configuration = new HashMap<String,String>();
        configuration.put("location", "mycredstore.cs");
        configuration.put("create", "true");

        try {
            credentialStore.initialize(configuration, protectionParameter);
        } catch (CredentialStoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(credentialStore.isInitialized());  
        Password password = null;
        try {
            password = credentialStore.retrieve("dbPassword", PasswordCredential.class).getPassword();
        } catch (UnsupportedCredentialTypeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (CredentialStoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("prueba5");
        clearTextPswd = password.toString();
        System.out.println(clearTextPswd);
        return clearTextPswd;
  }

代码本身应该没问题,但问题是:我无法启动应用程序后添加该代码。自从我将最后一个Wildfly-elytron版本添加到依赖项中以来,我从org.wildfly.commons.assert得到了一个NoClassDefFoundError,它不允许我使用它或调试它。这些是我的依赖项,会有什么问题吗?你以前遇到过这个问题吗?
它在调用方法时不触发,而只是在启动后调用类时触发。

<groupId>org.pushingpixels</groupId>
            <artifactId>trident</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.wildfly.security/wildfly-elytron -->
        <dependency>
            <groupId>org.wildfly.security</groupId>
            <artifactId>wildfly-elytron</artifactId>
            <version>2.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.picketbox</groupId>
            <artifactId>picketbox</artifactId>
            <version>5.1.0.Final</version>
        </dependency>````
ee7vknir

ee7vknir1#

事实上,问题是我没有添加wildfly-commons的更新版本。在那之后,虽然它仍然不能工作(看看你,下一篇文章),但至少在构建时不会崩溃,现在我可以正确地调试它。

相关问题