@Test public void testLoadPassword() throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException, InvalidKeyException, InvalidKeySpecException { final SecretKey storedSecretKey = storeKeyIntoKeyStoreFile(KEY_PHRASE); // Set properties to simulate the server final URL serverKeyStoreURL = getClass().getResource(KEYSTORE_JCEKS_RESOURCE_NAME); System.setProperty(KeyStoreConstants.PROP_PWD_KS_URL, serverKeyStoreURL.toExternalForm()); System.setProperty(KeyStoreConstants.PROP_PWD_KS_PWD, KEYSTORE_SERVER_PASSWORD); try { final KeyStoreHelper serverHelper = new KeyStoreHelper(); final String passwordKey = serverHelper.getPasswordKey(KEY_ALIAS, KEY_PASSWORD.toCharArray()); assertEquals(new String(storedSecretKey.getEncoded()), passwordKey); } catch (final RuntimeException re) { re.printStackTrace(); fail(re.getMessage()); } }
@Test public void testLoadPasswordNoKeystore() { final KeyStoreHelper serverHelper = new KeyStoreHelper(); try { serverHelper.getPasswordKey(null, null); fail(); } catch (final RuntimeException re) { assertTrue(true); } }
public static String loadControllerPassword(final String defaultPassword) { KeyStoreHelper keyStoreHelper = new KeyStoreHelper(); try { String pwdKeyAlias = System.getProperty(PROP_PWD_CTRL_ALIAS, ""); char[] pwdKeyPassword = System.getProperty(PROP_PWD_CTRL_PWD, "").toCharArray(); return keyStoreHelper.getPasswordKey(pwdKeyAlias, pwdKeyPassword); } catch (RuntimeException re) { logger.warn("Unable to load key store. Using password from configuration"); return defaultPassword; } } }
public static String loadControllerPassword(final String defaultPassword) { KeyStoreHelper keyStoreHelper = new KeyStoreHelper(); try { String pwdKeyAlias = System.getProperty(PROP_PWD_CTRL_ALIAS, ""); char[] pwdKeyPassword = System.getProperty(PROP_PWD_CTRL_PWD, "").toCharArray(); return keyStoreHelper.getPasswordKey(pwdKeyAlias, pwdKeyPassword); } catch (RuntimeException re) { logger.warn("Unable to load key store. Using password from configuration"); return defaultPassword; } } }
public static String loadServerPassword() { String passwordKey; KeyStoreHelper keyStoreHelper = new KeyStoreHelper(); try { String pwdKeyAlias = System.getProperty(PROP_PWD_SERVER_ALIAS, ""); char[] pwdKeyPassword = System.getProperty(PROP_PWD_SERVER_PWD, "").toCharArray(); passwordKey = keyStoreHelper.getPasswordKey(pwdKeyAlias, pwdKeyPassword); } catch (RuntimeException re) { logger.warn("Unable to load key store. Using password from configuration"); passwordKey = System.getProperty(KieServerConstants.CFG_KIE_PASSWORD, "kieserver1!"); } return passwordKey; }
public static String loadServerPassword() { String passwordKey; KeyStoreHelper keyStoreHelper = new KeyStoreHelper(); try { String pwdKeyAlias = System.getProperty(PROP_PWD_SERVER_ALIAS, ""); char[] pwdKeyPassword = System.getProperty(PROP_PWD_SERVER_PWD, "").toCharArray(); passwordKey = keyStoreHelper.getPasswordKey(pwdKeyAlias, pwdKeyPassword); } catch (RuntimeException re) { logger.warn("Unable to load key store. Using password from configuration"); passwordKey = System.getProperty(KieServerConstants.CFG_KIE_PASSWORD, "kieserver1!"); } return passwordKey; }