karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5411) Client doesn't prompt for user if no user.properties file
Date Mon, 23 Oct 2017 05:55:00 GMT

    [ https://issues.apache.org/jira/browse/KARAF-5411?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16214680#comment-16214680
] 

ASF GitHub Bot commented on KARAF-5411:
---------------------------------------

jbonofre closed pull request #382: [KARAF-5411] Allow for users.properties file not existing,
or empty
URL: https://github.com/apache/karaf/pull/382
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/client/src/main/java/org/apache/karaf/client/ClientConfig.java b/client/src/main/java/org/apache/karaf/client/ClientConfig.java
index 20e48a1b20..ab2b402e80 100644
--- a/client/src/main/java/org/apache/karaf/client/ClientConfig.java
+++ b/client/src/main/java/org/apache/karaf/client/ClientConfig.java
@@ -172,29 +172,31 @@ public ClientConfig(String[] args) throws Exception {
         }
         command = commandBuilder.toString();
 
-        Map<String, String> usersCfg = PropertiesLoader.loadPropertiesFile(new File(karafEtc,"users.properties").toURI().toURL(),
false);
-        if (!usersCfg.isEmpty()) {
-            Set<String> users = new LinkedHashSet<>();
-            for (String user : usersCfg.keySet()) {
-                if (!user.startsWith(GROUP_PREFIX)) {
-                    users.add(user);
-                }
-            }
-            if (user == null) {
-                if (users.iterator().hasNext()) {
-                    user = users.iterator().next();
-                }
-            }
-            if (interactiveMode && !inputPassword) {
-                password = null;
-            } else if (!inputPassword) {
-                password = usersCfg.get(user);
-                if (password != null && password.contains(ROLE_DELIMITER)) {
-                    password = password.substring(0, password.indexOf(ROLE_DELIMITER));
-                }
-            }
+        File userPropertiesFile = new File(karafEtc,"users.properties");
+        if (userPropertiesFile.exists()) {
+	        Map<String, String> usersCfg = PropertiesLoader.loadPropertiesFile(userPropertiesFile.toURI().toURL(),
false);
+	        if (!usersCfg.isEmpty()) {
+	            Set<String> users = new LinkedHashSet<>();
+	            for (String user : usersCfg.keySet()) {
+	                if (!user.startsWith(GROUP_PREFIX)) {
+	                    users.add(user);
+	                }
+	            }
+	            if (user == null) {
+	                if (users.iterator().hasNext()) {
+	                    user = users.iterator().next();
+	                }
+	            }
+	            if (interactiveMode && !inputPassword) {
+	                password = null;
+	            } else if (!inputPassword) {
+	                password = usersCfg.get(user);
+	                if (password != null && password.contains(ROLE_DELIMITER)) {
+	                    password = password.substring(0, password.indexOf(ROLE_DELIMITER));
+	                }
+	            }
+	        }
         }
-
     }
     
     private static void showHelp() {
@@ -272,6 +274,10 @@ public int getPort() {
     public String getUser() {
         return user;
     }
+    
+    public void setUser(String user) {
+    	this.user = user;
+    }
 
     public String getPassword() {
         return password;
diff --git a/client/src/main/java/org/apache/karaf/client/Main.java b/client/src/main/java/org/apache/karaf/client/Main.java
index 2bdb5710b1..1d53042404 100644
--- a/client/src/main/java/org/apache/karaf/client/Main.java
+++ b/client/src/main/java/org/apache/karaf/client/Main.java
@@ -142,14 +142,28 @@ public String getUpdatedPassword(ClientSession session, String prompt,
String la
                     }
                 });
             }
+            
+            if (config.getUser()==null || config.getUser().isEmpty()) {
+            	while (true) {
+            		String user = console.readLine("Enter user : ");
+            		if (user==null || user.isEmpty()) {
+            			System.err.println("User must not be empty!");
+            		}
+            		else {
+                    	config.setUser(user);
+                    	break;
+            		}
+            	}
+            }
+            else if (console != null) {
+                console.printf("Logging in as %s\n", config.getUser());
+            }
+            
             setupAgent(config.getUser(), config.getKeyFile(), client, passwordProvider);
             client.getProperties().put(FactoryManager.IDLE_TIMEOUT, String.valueOf(config.getIdleTimeout()));
             // TODO: remove the line below when SSHD-732 is fixed
             client.setKeyPairProvider(new FileKeyPairProvider());
             client.start();
-            if (console != null) {
-                console.printf("Logging in as %s\n", config.getUser());
-            }
             ClientSession session = connectWithRetries(client, config);
             if (config.getPassword() != null) {
                 session.addPasswordIdentity(config.getPassword());


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Client doesn't prompt for user if no user.properties file
> ---------------------------------------------------------
>
>                 Key: KARAF-5411
>                 URL: https://issues.apache.org/jira/browse/KARAF-5411
>             Project: Karaf
>          Issue Type: Bug
>         Environment: 4.1.2, 4.2
>            Reporter: Tom Quarendon
>            Assignee: Jean-Baptiste Onofré
>             Fix For: 4.2.0, 4.1.3
>
>
> If you have no etc/users.properties file, or have a users.properties file that is empty,
the client (bin/client) won't run, as it has no user.
> It would seem obvious to prompt for the username in these circumstances.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message