Ravi Nori has uploaded a new change for review.

Change subject: tools : engine-config confirm new passwd when changing passwd
......................................................................

tools : engine-config confirm new passwd when changing passwd

When changing internal users password engine-config does
not ask the user to confirm the new password.

This patch asks for the password a second time and validates
it againts the previously entered password.

Change-Id: I800d1857676ad12ed084b276b3c473237280cc77
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=904762
Signed-off-by: Ravi Nori <[email protected]>
---
M 
backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
M 
backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
M 
backend/manager/tools/engine-tools-common/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java
3 files changed, 18 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/17/11817/1

diff --git 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
index b7fcff0..92eb842 100644
--- 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
+++ 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
@@ -193,15 +193,19 @@
      * @return The user's password
      */
     public static String startPasswordDialog(String user) throws IOException {
+        return startPasswordDialog(user, "Please enter a password");
+    }
+
+    public static String startPasswordDialog(String user, String msg) throws 
IOException {
         log.debug("starting password dialog.");
         if (user == null) {
-            System.out.printf("Please enter a password");
+            System.out.printf(msg);
         } else {
-            System.out.printf("Please enter a password for %s: ", user);
+            System.out.printf("%s for %s: ",msg , user);
         }
         return new String(System.console().readPassword());
     }
-
+    
     /**
      * Prints the values of the given key from the DB.
      *
diff --git 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
index 3ce97ff..eadf7c9 100644
--- 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
+++ 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/entity/helper/PasswordValueHelper.java
@@ -22,6 +22,7 @@
     private static final Logger log = 
Logger.getLogger(PasswordValueHelper.class);
     public static final String INTERACTIVE_MODE = "Interactive";
     private EngineConfigCLIParser parser;
+    private String key;
 
     static {
         try {
@@ -104,6 +105,13 @@
         String password = null;
         if (StringUtils.isNotBlank(value) && 
value.equalsIgnoreCase(INTERACTIVE_MODE)) {
             password = EngineConfigLogic.startPasswordDialog(null);
+            if ("AdminPassword".equals(key)) {
+                String passwordConfirm = 
EngineConfigLogic.startPasswordDialog(null, "Please reenter password");
+                if (!password.equals(passwordConfirm)) {
+                    log.error("Passwords don't match");
+                    return extractPasswordValue(value);
+                }
+            }
         } else {
                 password =
                     
EngineConfigLogic.getPassFromFile((StringUtils.isNotBlank(value)) ? value
@@ -114,6 +122,7 @@
 
     @Override
     public ValidationResult validate(ConfigKey key, String value) {
+        this.key = key.getKey();
         // check if value is file path
         if (StringUtils.isNotBlank(value) && new File(value).exists()) {
             return new ValidationResult(true);
diff --git 
a/backend/manager/tools/engine-tools-common/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java
 
b/backend/manager/tools/engine-tools-common/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java
index 5a0bf9e..2a01792 100644
--- 
a/backend/manager/tools/engine-tools-common/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java
+++ 
b/backend/manager/tools/engine-tools-common/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java
@@ -85,11 +85,13 @@
             throw new SQLException("Can't find database password parameter \"" 
+ ENGINE_DB_PASSWORD + "\" in file \"" + configFile.getAbsolutePath() + "\".");
         }
 
+        if (password.length() > 0) {
         // The password is encrypted inside the file, so we need to decrypt it 
here:
         password = EncryptionUtils.decode(password, "", "");
         if (password == null) {
             throw new SQLException("Failed to decrypt password from parameter 
\"" + ENGINE_DB_PASSWORD + "\" in file \"" + configFile.getAbsolutePath() + 
"\".");
         }
+        }
 
         // Load the driver:
         try {


--
To view, visit http://gerrit.ovirt.org/11817
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I800d1857676ad12ed084b276b3c473237280cc77
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ravi Nori <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to