@Test public void testUpdateSystemvmPassword() { final String realusername = System.getProperty("user.name"); System.setProperty("user.name", "cloud"); Mockito.when(_configDao.getValue("system.vm.random.password")).thenReturn(String.valueOf(true)); TransactionLegacy.open("cloud"); Mockito.when(_mgrService.generateRandomPassword()).thenReturn("randomPassword"); configurationServer.updateSystemvmPassword(); Mockito.verify(_mgrService, Mockito.times(1)).generateRandomPassword(); System.setProperty("user.name", realusername); }
@DB protected void updateSystemvmPassword() { final String userid = System.getProperty("user.name"); if (!userid.startsWith("cloud")) { return; } if (!Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { return; } final String already = _configDao.getValue("system.vm.password"); if (already == null) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); try { final String rpassword = _mgrService.generateRandomPassword(); final String wSql = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', ?,'randmon password generated each management server starts for system vm')"; final PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql); stmt.setString(1, DBEncryptionUtil.encrypt(rpassword)); stmt.executeUpdate(); s_logger.info("Updated systemvm password in database"); } catch (final SQLException e) { s_logger.error("Cannot retrieve systemvm password", e); } } }
ConfigurationServerImpl extends ManagerBase implements ConfigurationServer { @DB protected void updateSystemvmPassword() { final String userid = System.getProperty("user.name"); if (!userid.startsWith("cloud")) { return; } if (!Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { return; } final String already = _configDao.getValue("system.vm.password"); if (already == null) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); try { final String rpassword = _mgrService.generateRandomPassword(); final String wSql = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', ?,'randmon password generated each management server starts for system vm')"; final PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql); stmt.setString(1, DBEncryptionUtil.encrypt(rpassword)); stmt.executeUpdate(); s_logger.info("Updated systemvm password in database"); } catch (final SQLException e) { s_logger.error("Cannot retrieve systemvm password", e); } } } }
ConfigurationServerImpl extends ManagerBase implements ConfigurationServer { @DB protected void updateSystemvmPassword() { final String userid = System.getProperty("user.name"); if (!userid.startsWith("cloud")) { return; } if (!Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { return; } final String already = _configDao.getValue("system.vm.password"); if (already == null) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); try { final String rpassword = _mgrService.generateRandomPassword(); final String wSql = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', ?,'randmon password generated each management server starts for system vm')"; final PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql); stmt.setString(1, DBEncryptionUtil.encrypt(rpassword)); stmt.executeUpdate(); s_logger.info("Updated systemvm password in database"); } catch (final SQLException e) { s_logger.error("Cannot retrieve systemvm password", e); } } } ConfigurationServerImpl(); }
ConfigurationServerImpl extends ManagerBase implements ConfigurationServer { @DB protected void updateSystemvmPassword() { final String userid = System.getProperty("user.name"); if (!userid.startsWith("cloud")) { return; } if (!Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { return; } final String already = _configDao.getValue("system.vm.password"); if (already == null) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); try { final String rpassword = _mgrService.generateRandomPassword(); final String wSql = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', ?,'randmon password generated each management server starts for system vm')"; final PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql); stmt.setString(1, DBEncryptionUtil.encrypt(rpassword)); stmt.executeUpdate(); s_logger.info("Updated systemvm password in database"); } catch (final SQLException e) { s_logger.error("Cannot retrieve systemvm password", e); } } } ConfigurationServerImpl(); @Override boolean configure(final String name, final Map<String, Object> params); @Override void persistDefaultValues(); @DB void saveUser(); @DB void updateResourceCount(); Map<String, String> getServicesAndProvidersForNetwork(final long networkOfferingId); @Override @DB void updateKeyPairs(); @Override List<ConfigurationVO> getConfigListByScope(final String scope, final Long resourceId); }
ConfigurationServerImpl extends ManagerBase implements ConfigurationServer { @DB protected void updateSystemvmPassword() { final String userid = System.getProperty("user.name"); if (!userid.startsWith("cloud")) { return; } if (!Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { return; } final String already = _configDao.getValue("system.vm.password"); if (already == null) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); try { final String rpassword = _mgrService.generateRandomPassword(); final String wSql = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', ?,'randmon password generated each management server starts for system vm')"; final PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql); stmt.setString(1, DBEncryptionUtil.encrypt(rpassword)); stmt.executeUpdate(); s_logger.info("Updated systemvm password in database"); } catch (final SQLException e) { s_logger.error("Cannot retrieve systemvm password", e); } } } ConfigurationServerImpl(); @Override boolean configure(final String name, final Map<String, Object> params); @Override void persistDefaultValues(); @DB void saveUser(); @DB void updateResourceCount(); Map<String, String> getServicesAndProvidersForNetwork(final long networkOfferingId); @Override @DB void updateKeyPairs(); @Override List<ConfigurationVO> getConfigListByScope(final String scope, final Long resourceId); static final Logger s_logger; }