You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2017/08/22 14:54:04 UTC

[1/4] karaf git commit: Fix warnings

Repository: karaf
Updated Branches:
  refs/heads/master 09c445c38 -> 3db554d45


Fix warnings

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/ab04a21b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/ab04a21b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/ab04a21b

Branch: refs/heads/master
Commit: ab04a21b151d17b73f4f834ff2547abde28049f8
Parents: 09c445c
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Tue Aug 22 10:32:46 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Tue Aug 22 10:32:46 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/karaf/profile/command/ProfileDisplay.java  | 1 -
 .../java/org/apache/karaf/profile/command/ProfileEdit.java     | 6 +++---
 2 files changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/ab04a21b/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java
----------------------------------------------------------------------
diff --git a/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java b/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java
index 9e54cef..e6d4619 100644
--- a/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java
+++ b/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java
@@ -91,7 +91,6 @@ public class ProfileDisplay implements Action {
         List<String> agentProperties = new ArrayList<>();
         List<String> systemProperties = new ArrayList<>();
         List<String> configProperties = new ArrayList<>();
-        List<String> otherResources = new ArrayList<>();
         for (Map.Entry<String, Object> entry : agentConfiguration.entrySet()) {
             String key = entry.getKey();
             Object value = entry.getValue();

http://git-wip-us.apache.org/repos/asf/karaf/blob/ab04a21b/profile/src/main/java/org/apache/karaf/profile/command/ProfileEdit.java
----------------------------------------------------------------------
diff --git a/profile/src/main/java/org/apache/karaf/profile/command/ProfileEdit.java b/profile/src/main/java/org/apache/karaf/profile/command/ProfileEdit.java
index 1b986ee..596731a 100644
--- a/profile/src/main/java/org/apache/karaf/profile/command/ProfileEdit.java
+++ b/profile/src/main/java/org/apache/karaf/profile/command/ProfileEdit.java
@@ -407,10 +407,10 @@ public class ProfileEdit implements Action {
     }
 
     private void openInEditor(Profile profile, String resource) throws Exception {
+        /* TODO:JLINE
         String id = profile.getId();
         String location = id + " " + resource;
         //Call the editor
-        /* TODO:JLINE
         ConsoleEditor editor = editorFactory.create("simple", getTerminal());
         editor.setTitle("Profile");
         editor.setOpenEnabled(false);
@@ -462,8 +462,8 @@ public class ProfileEdit implements Action {
         try {
             Configuration[] configuration = configurationAdmin.listConfigurations("(service.pid=" + pid + ")");
             if (configuration != null && configuration.length > 0) {
-                Dictionary dictionary = configuration[0].getProperties();
-                Enumeration keyEnumeration = dictionary.keys();
+                Dictionary<String, Object> dictionary = configuration[0].getProperties();
+                Enumeration<String> keyEnumeration = dictionary.keys();
                 while (keyEnumeration.hasMoreElements()) {
                     String key = String.valueOf(keyEnumeration.nextElement());
                     //file.install.filename needs to be skipped as it specific to the current container.


[2/4] karaf git commit: Refactor EncryptionSupport to use tracker

Posted by cs...@apache.org.
Refactor EncryptionSupport to use tracker


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/e380f888
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/e380f888
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/e380f888

Branch: refs/heads/master
Commit: e380f888a6c2d7f08513129e8c74a37c5d2afd4a
Parents: ab04a21
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Tue Aug 22 13:58:52 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Tue Aug 22 13:58:52 2017 +0200

----------------------------------------------------------------------
 .../modules/encryption/EncryptionSupport.java   | 162 ++++++++++---------
 1 file changed, 82 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/e380f888/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java
index ff2f12a..036fc9b 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java
@@ -17,115 +17,117 @@ package org.apache.karaf.jaas.modules.encryption;
 import org.apache.karaf.jaas.modules.Encryption;
 import org.apache.karaf.jaas.modules.EncryptionService;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.SortedMap;
 
 public class EncryptionSupport {
-
     private final Logger logger = LoggerFactory.getLogger(EncryptionSupport.class);
 
     private BundleContext bundleContext;
-
     private Encryption encryption;
     private String encryptionPrefix;
     private String encryptionSuffix;
-    protected Map<String, ?> options;
+    private boolean debug;
+    private boolean enabled;
+    private String name;
 
-    protected boolean debug;
+    private Map<String, String> encOpts;
 
 
     public EncryptionSupport(Map<String, ?> options) {
-        this.options = options;
         this.debug = Boolean.parseBoolean((String) options.get("debug"));
         // the bundle context is set in the Config JaasRealm by default
         this.bundleContext = (BundleContext) options.get(BundleContext.class.getName());
+        encOpts = new HashMap<>();
+        for (String key : options.keySet()) {
+            if (key.startsWith("encryption.")) {
+                encOpts.put(key.substring("encryption.".length()), options.get(key).toString());
+            }
+        }
+        encryptionPrefix = encOpts.remove("prefix");
+        encryptionSuffix = encOpts.remove("suffix");
+        enabled = Boolean.parseBoolean(encOpts.remove("enabled"));
+        if (!enabled) {
+            if (debug) {
+                logger.debug("Encryption is disabled.");
+            }
+        }
+        name = encOpts.remove("name");
+        if (debug) {
+            if (name != null && name.length() > 0) {
+                logger.debug("Encryption is enabled. Using service " + name + " with options " + encOpts);
+            } else {
+                logger.debug("Encryption is enabled. Using options " + encOpts);
+            }
+        }
     }
 
     public Encryption getEncryption() {
-        if (encryption == null) {
-            Map<String, String> encOpts = new HashMap<>();
-            for (String key : options.keySet()) {
-                if (key.startsWith("encryption.")) {
-                    encOpts.put(key.substring("encryption.".length()), options.get(key).toString());
-                }
-            }
-            encryptionPrefix = encOpts.remove("prefix");
-            encryptionSuffix = encOpts.remove("suffix");
-            boolean enabled = Boolean.parseBoolean(encOpts.remove("enabled"));
+        if (encryption != null) {
+            return encryption;
+        }
+        if (!enabled) {
+            return null;
+        }
 
-            if (!enabled) {
-                if (debug) {
-                    logger.debug("Encryption is disabled.");
-                }
-            } else {
-                String name = encOpts.remove("name");
-                if (debug) {
-                    if (name != null && name.length() > 0) {
-                        logger.debug("Encryption is enabled. Using service " + name + " with options " + encOpts);
-                    } else {
-                        logger.debug("Encryption is enabled. Using options " + encOpts);
-                    }
-                }
-                // lookup the encryption service reference
-                ServiceReference[] encryptionServiceReferences;
-                try {
-                    encryptionServiceReferences = bundleContext.getServiceReferences(
-                            EncryptionService.class.getName(),
-                            name != null && name.length() > 0 ? "(name=" + name + ")" : null);
-                    int timeout = 0;
-                    while (encryptionServiceReferences == null || encryptionServiceReferences.length == 0) {
-                        try {
-                            Thread.sleep(500);
-                        } catch (InterruptedException  ie) {
-                            // nothing to do
-                        }
-                        encryptionServiceReferences = bundleContext.getServiceReferences(
-                                EncryptionService.class.getName(),
-                                name != null && name.length() > 0 ? "(name=" + name + ")" : null);
-                        timeout++;
-                        if (timeout == 40)
-                            break;
-                    }
-                } catch (InvalidSyntaxException e) {
-                    throw new IllegalStateException("The encryption service filter is not well formed.", e);
-                }
-                if (encryptionServiceReferences == null || encryptionServiceReferences.length == 0) {
-                    if (name != null && name.length() > 0) {
-                        throw new IllegalStateException("Encryption service " + name + " not found. Please check that the encryption service is correctly set up.");
-                    } else {
-                        throw new IllegalStateException("No encryption service found. Please install the Karaf encryption feature and check that the encryption algorithm is supported.");
-                    }
-                }
-                Arrays.sort(encryptionServiceReferences);
-                for (ServiceReference ref : encryptionServiceReferences) {
-                    try {
-                        EncryptionService encryptionService = (EncryptionService) bundleContext.getService(ref);
-                        if (encryptionService != null) {
-                            try {
-                                encryption = encryptionService.createEncryption(encOpts);
-                                if (encryption != null) {
-                                    break;
-                                }
-                            } finally {
-                                bundleContext.ungetService(ref);
-                            }
-                        }
-                    } catch (IllegalStateException e) {
-                        // continue
-                    }
-                }
-                if (encryption == null) {
-                    throw new IllegalStateException("No EncryptionService supporting the required options could be found.");
+        ServiceTracker<EncryptionService, EncryptionService> tracker = new ServiceTracker<>(bundleContext, getFilter(), null);
+        tracker.open();
+        try {
+            return getEncryptionInternal(tracker);
+        } finally {
+            tracker.close();
+        }
+    }
+
+    private Encryption getEncryptionInternal(ServiceTracker<EncryptionService, EncryptionService> tracker) {
+        try {
+            tracker.waitForService(20000);
+        } catch (InterruptedException e1) {
+            return null;
+        }
+        SortedMap<ServiceReference<EncryptionService>, EncryptionService> tracked = tracker.getTracked();
+        if (tracked.isEmpty()) {
+            throw new IllegalStateException(noEncryptionServiceMsg());
+        }
+        for (EncryptionService encryptionService : tracked.values()) {
+            try {
+                Encryption encr = encryptionService.createEncryption(encOpts);
+                if (encr != null) {
+                    this.encryption = encr;
+                    return encryption;
                 }
+            } catch (IllegalStateException e) {
+                // continue
             }
         }
-        return encryption;
+        throw new IllegalStateException("No EncryptionService supporting the required options could be found.");
+    }
+
+    private String noEncryptionServiceMsg() {
+        if (name != null && name.length() > 0) {
+            return "Encryption service " + name + " not found. Please check that the encryption service is correctly set up.";
+        } else {
+            return "No encryption service found. Please install the Karaf encryption feature and check that the encryption algorithm is supported.";
+        }
+    }
+
+    private org.osgi.framework.Filter getFilter() {
+        String nameFilter = name != null && name.length() > 0 ? "(name=" + name + ")" : null;
+        String objFilter = "(objectClass=" + EncryptionService.class.getName() + ")";
+        String filter = nameFilter == null ? objFilter : "&(" + nameFilter + objFilter + ")"; 
+        try {
+            return FrameworkUtil.createFilter(filter);
+        } catch (InvalidSyntaxException e) {
+            throw new IllegalStateException(e);
+        }
     }
 
     public String getEncryptionSuffix() {


[3/4] karaf git commit: [KARAF-5316] Make EncryptionSupport easier to use

Posted by cs...@apache.org.
[KARAF-5316] Make EncryptionSupport easier to use


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/d6edb10e
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/d6edb10e
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/d6edb10e

Branch: refs/heads/master
Commit: d6edb10e0cf65f1d9eafb98154add8f007f70653
Parents: e380f88
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Tue Aug 22 16:29:42 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Tue Aug 22 16:29:42 2017 +0200

----------------------------------------------------------------------
 .../jaas/modules/AbstractKarafLoginModule.java  | 47 +------------
 .../modules/encryption/EncryptionSupport.java   | 71 +++++++++++++++-----
 .../jaas/modules/jdbc/JDBCBackingEngine.java    | 14 +---
 .../properties/AutoEncryptionSupport.java       | 28 +-------
 .../properties/PropertiesBackingEngine.java     | 19 ++----
 5 files changed, 66 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/d6edb10e/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/AbstractKarafLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/AbstractKarafLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/AbstractKarafLoginModule.java
index 7f7807b..a6601d0 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/AbstractKarafLoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/AbstractKarafLoginModule.java
@@ -68,7 +68,7 @@ public abstract class AbstractKarafLoginModule implements LoginModule {
         user = null;
     }
 
-    public void initialize(Subject sub, CallbackHandler handler, Map options) {
+    public void initialize(Subject sub, CallbackHandler handler, Map<String, ?> options) {
         this.subject = sub;
         this.callbackHandler = handler;
         this.options = options;
@@ -81,50 +81,9 @@ public abstract class AbstractKarafLoginModule implements LoginModule {
         encryptionSupport = new EncryptionSupport(options);
     }
 
-
-    public String getEncryptedPassword(String password) {
-        Encryption encryption = encryptionSupport.getEncryption();
-        String encryptionPrefix = encryptionSupport.getEncryptionPrefix();
-        String encryptionSuffix = encryptionSupport.getEncryptionSuffix();
-
-        if (encryption == null) {
-            return password;
-        } else {
-            boolean prefix = encryptionPrefix == null || password.startsWith(encryptionPrefix);
-            boolean suffix = encryptionSuffix == null || password.endsWith(encryptionSuffix);
-            if (prefix && suffix) {
-                return password;
-            } else {
-                String p = encryption.encryptPassword(password);
-                if (encryptionPrefix != null) {
-                    p = encryptionPrefix + p;
-                }
-                if (encryptionSuffix != null) {
-                    p = p + encryptionSuffix;
-                }
-                return p;
-            }
-        }
-    }
-
     public boolean checkPassword(String plain, String encrypted) {
-        Encryption encryption = encryptionSupport.getEncryption();
-        String encryptionPrefix = encryptionSupport.getEncryptionPrefix();
-        String encryptionSuffix = encryptionSupport.getEncryptionSuffix();
-
-        if (encryption == null) {
-            return plain.equals(encrypted);
-        } else {
-            boolean prefix = encryptionPrefix == null || encrypted.startsWith(encryptionPrefix);
-            boolean suffix = encryptionSuffix == null || encrypted.endsWith(encryptionSuffix);
-            if (prefix && suffix) {
-                encrypted = encrypted.substring(encryptionPrefix != null ? encryptionPrefix.length() : 0,
-                        encrypted.length() - (encryptionSuffix != null ? encryptionSuffix.length() : 0));
-                return encryption.checkPassword(plain, encrypted);
-            } else {
-                return plain.equals(encrypted);
-            }
-        }
+        String newEncrypted = encryptionSupport.encrypt(plain);
+        return encrypted.equals(newEncrypted);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/d6edb10e/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java
index 036fc9b..61e28f0 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java
@@ -40,7 +40,12 @@ public class EncryptionSupport {
     private String name;
 
     private Map<String, String> encOpts;
-
+    
+    public static EncryptionSupport noEncryptionSupport() {
+        Map<String, Object> options = new HashMap<>();
+        options.put("enabled", "false");
+        return new EncryptionSupport(options);
+    }
 
     public EncryptionSupport(Map<String, ?> options) {
         this.debug = Boolean.parseBoolean((String) options.get("debug"));
@@ -52,31 +57,54 @@ public class EncryptionSupport {
                 encOpts.put(key.substring("encryption.".length()), options.get(key).toString());
             }
         }
-        encryptionPrefix = encOpts.remove("prefix");
-        encryptionSuffix = encOpts.remove("suffix");
+        encryptionPrefix = defaulIfNull(encOpts.remove("prefix"), "");
+        encryptionSuffix = defaulIfNull(encOpts.remove("suffix"), "");
         enabled = Boolean.parseBoolean(encOpts.remove("enabled"));
-        if (!enabled) {
-            if (debug) {
-                logger.debug("Encryption is disabled.");
-            }
+        if (!enabled && debug) {
+            logger.debug("Encryption is disabled.");
         }
         name = encOpts.remove("name");
         if (debug) {
-            if (name != null && name.length() > 0) {
-                logger.debug("Encryption is enabled. Using service " + name + " with options " + encOpts);
-            } else {
-                logger.debug("Encryption is enabled. Using options " + encOpts);
-            }
+            logOptions();
+        }
+    }
+    
+    public String encrypt(String plain) {
+        getEncryption();
+        if (encryption == null || isEncrypted(plain)) {
+            return plain;
+        } else {
+            return encryptionPrefix + encryption.encryptPassword(plain) + encryptionSuffix;
+        }
+    }
+    
+    private void logOptions() {
+        if (name != null && name.length() > 0) {
+            logger.debug("Encryption is enabled. Using service " + name + " with options " + encOpts);
+        } else {
+            logger.debug("Encryption is enabled. Using options " + encOpts);
         }
     }
+    
+    private String defaulIfNull(String value, String defaultValue) {
+        return value == null ? defaultValue : value;
+    }
+    
+    private boolean isEncrypted(String password) {
+        boolean prefixPresent = "".equals(encryptionPrefix) || password.startsWith(encryptionPrefix);
+        boolean suffixPresent = "".equals(encryptionSuffix) || password.endsWith(encryptionSuffix);
+        return prefixPresent && suffixPresent;
+    }
 
+    /**
+     * @deprecated Use encrypt instead. This method will be made private
+     * @return chosen encryption
+     */
+    @Deprecated
     public Encryption getEncryption() {
-        if (encryption != null) {
+        if (encryption != null || !enabled) {
             return encryption;
         }
-        if (!enabled) {
-            return null;
-        }
 
         ServiceTracker<EncryptionService, EncryptionService> tracker = new ServiceTracker<>(bundleContext, getFilter(), null);
         tracker.open();
@@ -130,20 +158,31 @@ public class EncryptionSupport {
         }
     }
 
+    @Deprecated
     public String getEncryptionSuffix() {
         return encryptionSuffix;
     }
 
+    @Deprecated
     public void setEncryptionSuffix(String encryptionSuffix) {
         this.encryptionSuffix = encryptionSuffix;
     }
 
+    @Deprecated
     public String getEncryptionPrefix() {
         return encryptionPrefix;
     }
 
+    @Deprecated
     public void setEncryptionPrefix(String encryptionPrefix) {
         this.encryptionPrefix = encryptionPrefix;
     }
+    
+    /**
+     * For tests
+     */
+    void setEncryption(Encryption encryption) {
+        this.encryption = encryption;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/d6edb10e/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/jdbc/JDBCBackingEngine.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/jdbc/JDBCBackingEngine.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/jdbc/JDBCBackingEngine.java
index 11a52cc..420d549 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/jdbc/JDBCBackingEngine.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/jdbc/JDBCBackingEngine.java
@@ -50,6 +50,7 @@ public class JDBCBackingEngine implements BackingEngine {
 
     public JDBCBackingEngine(DataSource dataSource) {
         this.dataSource = dataSource;
+        this.encryptionSupport = EncryptionSupport.noEncryptionSupport();
     }
 
     public JDBCBackingEngine(DataSource dataSource, EncryptionSupport encryptionSupport) {
@@ -67,19 +68,10 @@ public class JDBCBackingEngine implements BackingEngine {
         if (username.startsWith(GROUP_PREFIX)) {
             throw new IllegalArgumentException("Prefix not permitted: " + GROUP_PREFIX);
         }
-        //If encryption support is enabled, encrypt password
-        if (encryptionSupport != null && encryptionSupport.getEncryption() != null) {
-            password = encryptionSupport.getEncryption().encryptPassword(password);
-            if (encryptionSupport.getEncryptionPrefix() != null) {
-                password = encryptionSupport.getEncryptionPrefix() + password;
-            }
-            if (encryptionSupport.getEncryptionSuffix() != null) {
-                password = password + encryptionSupport.getEncryptionSuffix();
-            }
-        }
+        String encPassword = encryptionSupport.encrypt(password);
         try {
             try (Connection connection = dataSource.getConnection()) {
-                rawUpdate(connection, addUserStatement, username, password);
+                rawUpdate(connection, addUserStatement, username, encPassword);
             }
         } catch (SQLException e) {
             throw new RuntimeException("Error adding user", e);

http://git-wip-us.apache.org/repos/asf/karaf/blob/d6edb10e/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java
index 975497e..662fc31 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java
@@ -32,7 +32,6 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.felix.utils.properties.Properties;
-import org.apache.karaf.jaas.modules.Encryption;
 import org.apache.karaf.jaas.modules.encryption.EncryptionSupport;
 import org.apache.karaf.util.StreamUtils;
 import org.slf4j.Logger;
@@ -119,7 +118,7 @@ public class AutoEncryptionSupport implements Runnable, Closeable {
             String storedPassword = infos[0];
 
             // check if the stored password is flagged as encrypted
-            String encryptedPassword = getEncryptedPassword(storedPassword);
+            String encryptedPassword = encryptionSupport.encrypt(storedPassword);
             if (!storedPassword.equals(encryptedPassword)) {
                 LOGGER.debug("The password isn't flagged as encrypted, encrypt it.");
                 userInfos = encryptedPassword + ",";
@@ -143,29 +142,4 @@ public class AutoEncryptionSupport implements Runnable, Closeable {
         }
     }
 
-    String getEncryptedPassword(String password) {
-        Encryption encryption = encryptionSupport.getEncryption();
-        String encryptionPrefix = encryptionSupport.getEncryptionPrefix();
-        String encryptionSuffix = encryptionSupport.getEncryptionSuffix();
-
-        if (encryption == null) {
-            return password;
-        } else {
-            boolean prefix = encryptionPrefix == null || password.startsWith(encryptionPrefix);
-            boolean suffix = encryptionSuffix == null || password.endsWith(encryptionSuffix);
-            if (prefix && suffix) {
-                return password;
-            } else {
-                String p = encryption.encryptPassword(password);
-                if (encryptionPrefix != null) {
-                    p = encryptionPrefix + p;
-                }
-                if (encryptionSuffix != null) {
-                    p = p + encryptionSuffix;
-                }
-                return p;
-            }
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/d6edb10e/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesBackingEngine.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesBackingEngine.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesBackingEngine.java
index 1c3a85b..9435f0c 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesBackingEngine.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesBackingEngine.java
@@ -39,6 +39,7 @@ public class PropertiesBackingEngine implements BackingEngine {
 
     public PropertiesBackingEngine(Properties users) {
         this.users = users;
+        this.encryptionSupport = EncryptionSupport.noEncryptionSupport();
     }
 
     public PropertiesBackingEngine(Properties users, EncryptionSupport encryptionSupport) {
@@ -58,25 +59,13 @@ public class PropertiesBackingEngine implements BackingEngine {
         String[] infos = null;
         StringBuffer userInfoBuffer = new StringBuffer();
 
-        String newPassword = password;
-
-        //If encryption support is enabled, encrypt password
-        if (encryptionSupport != null && encryptionSupport.getEncryption() != null) {
-            newPassword = encryptionSupport.getEncryption().encryptPassword(password);
-            if (encryptionSupport.getEncryptionPrefix() != null) {
-                newPassword = encryptionSupport.getEncryptionPrefix() + newPassword;
-            }
-            if (encryptionSupport.getEncryptionSuffix() != null) {
-                newPassword = newPassword + encryptionSupport.getEncryptionSuffix();
-            }
-        }
-
+        String encPassword = encryptionSupport.encrypt(password);
         String userInfos = users.get(username);
 
         //If user already exists, update password
         if (userInfos != null && userInfos.length() > 0) {
             infos = userInfos.split(",");
-            userInfoBuffer.append(newPassword);
+            userInfoBuffer.append(encPassword);
 
             for (int i = 1; i < infos.length; i++) {
                 userInfoBuffer.append(",");
@@ -85,7 +74,7 @@ public class PropertiesBackingEngine implements BackingEngine {
             String newUserInfo = userInfoBuffer.toString();
             users.put(username, newUserInfo);
         } else {
-            users.put(username, newPassword);
+            users.put(username, encPassword);
         }
 
         try {

[4/4] karaf git commit: Fix warnings

Posted by cs...@apache.org.
Fix warnings


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/3db554d4
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/3db554d4
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/3db554d4

Branch: refs/heads/master
Commit: 3db554d453e3f80dc5ffb71d2cbcb655b2ddc277
Parents: d6edb10
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Tue Aug 22 16:34:21 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Tue Aug 22 16:34:21 2017 +0200

----------------------------------------------------------------------
 .../karaf/jaas/modules/audit/AbstractAuditLoginModule.java    | 2 +-
 .../karaf/jaas/modules/audit/EventAdminAuditLoginModule.java  | 2 +-
 .../apache/karaf/jaas/modules/audit/FileAuditLoginModule.java | 2 +-
 .../apache/karaf/jaas/modules/audit/LogAuditLoginModule.java  | 2 +-
 .../java/org/apache/karaf/jaas/modules/impl/KarafRealm.java   | 2 --
 .../org/apache/karaf/jaas/modules/krb5/Krb5LoginModule.java   | 1 +
 .../apache/karaf/jaas/modules/osgi/OsgiConfigLoginModule.java | 2 +-
 .../jaas/modules/properties/DigestPasswordLoginModule.java    | 4 ++--
 .../karaf/jaas/modules/properties/PropertiesLoginModule.java  | 2 +-
 .../jaas/modules/publickey/PublickeyBackingEngineFactory.java | 7 +++----
 10 files changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/AbstractAuditLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/AbstractAuditLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/AbstractAuditLoginModule.java
index 5349246..140ba40 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/AbstractAuditLoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/AbstractAuditLoginModule.java
@@ -38,7 +38,7 @@ public abstract class AbstractAuditLoginModule implements LoginModule {
     private boolean enabled;
 
     public void initialize(Subject subject, CallbackHandler callbackHandler,
-                           Map sharedState, Map options) {
+                           Map<String, ?> sharedState, Map<String, ?> options) {
         this.subject = subject;
         enabled = Boolean.parseBoolean((String) options.get("enabled"));
         handler = callbackHandler;

http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/EventAdminAuditLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/EventAdminAuditLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/EventAdminAuditLoginModule.java
index 8375013..54ce6aa 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/EventAdminAuditLoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/EventAdminAuditLoginModule.java
@@ -38,7 +38,7 @@ public class EventAdminAuditLoginModule extends AbstractAuditLoginModule {
     private String topic;
 
     public void initialize(Subject subject, CallbackHandler callbackHandler,
-                           Map sharedState, Map options) {
+                           Map<String, ?> sharedState, Map<String, ?> options) {
         super.initialize(subject, callbackHandler, sharedState, options);
         bundleContext = (BundleContext) options.get(BundleContext.class.getName());
         topic = (String) options.get("topic");

http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/FileAuditLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/FileAuditLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/FileAuditLoginModule.java
index eda7c71..6134964 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/FileAuditLoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/FileAuditLoginModule.java
@@ -36,7 +36,7 @@ public class FileAuditLoginModule extends AbstractAuditLoginModule {
     private String logFile;
 
     public void initialize(Subject subject, CallbackHandler callbackHandler,
-                           Map sharedState, Map options) {
+                           Map<String, ?> sharedState, Map<String, ?> options) {
         super.initialize(subject, callbackHandler, sharedState, options);
         logFile = (String) options.get(LOG_FILE_OPTION);
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/LogAuditLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/LogAuditLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/LogAuditLoginModule.java
index f9e6915..41db1ba 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/LogAuditLoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/LogAuditLoginModule.java
@@ -30,7 +30,7 @@ public class LogAuditLoginModule extends AbstractAuditLoginModule {
     private Logger logger;
 
     public void initialize(Subject subject, CallbackHandler callbackHandler,
-                           Map sharedState, Map options) {
+                           Map<String, ?> sharedState, Map<String, ?> options) {
         super.initialize(subject, callbackHandler, sharedState, options);
         level = (String) options.get(LOG_LEVEL_OPTION);
         logger = LoggerFactory.getLogger((String) options.get(LOG_LOGGER_OPTION));

http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
index eaabbac..6fe764c 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
@@ -34,8 +34,6 @@ public class KarafRealm implements JaasRealm {
     private static final String LOG_AUDIT_MODULE = "org.apache.karaf.jaas.modules.audit.LogAuditLoginModule";
     private static final String EVENTADMIN_AUDIT_MODULE = "org.apache.karaf.jaas.modules.audit.EventAdminAuditLoginModule";
 
-    private static final String MODULE = "org.apache.karaf.jaas.module";
-
     private final BundleContext bundleContext;
     private volatile Map<String, Object> properties;
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/krb5/Krb5LoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/krb5/Krb5LoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/krb5/Krb5LoginModule.java
index 28a6e11..3d7ad47 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/krb5/Krb5LoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/krb5/Krb5LoginModule.java
@@ -28,6 +28,7 @@ import java.util.regex.Pattern;
 /**
  * Karaf Kerberos login module.
  */
+@SuppressWarnings("restriction")
 public class Krb5LoginModule implements LoginModule {
 
     private com.sun.security.auth.module.Krb5LoginModule loginModule = new com.sun.security.auth.module.Krb5LoginModule();

http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/osgi/OsgiConfigLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/osgi/OsgiConfigLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/osgi/OsgiConfigLoginModule.java
index 8ce320e..dd4aa4d 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/osgi/OsgiConfigLoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/osgi/OsgiConfigLoginModule.java
@@ -49,7 +49,7 @@ public class OsgiConfigLoginModule extends AbstractKarafLoginModule {
         try {
             String pid = (String) options.get(PID);
             Configuration config = ConfigAdminHolder.getService().getConfiguration(pid, null);
-            Dictionary properties = config.getProperties();
+            Dictionary<String, Object> properties = config.getProperties();
 
             Callback[] callbacks = new Callback[2];
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/DigestPasswordLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/DigestPasswordLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/DigestPasswordLoginModule.java
index 4ae2afa..1e01761 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/DigestPasswordLoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/DigestPasswordLoginModule.java
@@ -54,7 +54,7 @@ public class  DigestPasswordLoginModule extends AbstractKarafLoginModule {
     private String usersFile;
     
 
-    public void initialize(Subject sub, CallbackHandler handler, Map sharedState, Map options) {
+    public void initialize(Subject sub, CallbackHandler handler, Map<String, ?> sharedState, Map<String, ?> options) {
         super.initialize(sub,handler,options);
         usersFile = (String) options.get(USER_FILE);
         if (debug) {
@@ -89,7 +89,7 @@ public class  DigestPasswordLoginModule extends AbstractKarafLoginModule {
             System.arraycopy(b3, 0, b4, offset, b3.length);
             
             byte[] digestBytes = generateDigest(b4);
-            passwdDigest = new String(new Base64().encodeBase64(digestBytes));
+            passwdDigest = new String(Base64.encodeBase64(digestBytes));
         } catch (Exception e) {
             LOGGER.debug(e.getMessage(), e);
         }

http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java
index 9fe11ed..fd3f5b6 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java
@@ -49,7 +49,7 @@ public class PropertiesLoginModule extends AbstractKarafLoginModule {
     private String usersFile;
     
 
-    public void initialize(Subject sub, CallbackHandler handler, Map sharedState, Map options) {
+    public void initialize(Subject sub, CallbackHandler handler, Map<String, ?> sharedState, Map<String, ?> options) {
         super.initialize(sub,handler,options);
         usersFile = (String) options.get(USER_FILE);
         if (debug) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/3db554d4/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/publickey/PublickeyBackingEngineFactory.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/publickey/PublickeyBackingEngineFactory.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/publickey/PublickeyBackingEngineFactory.java
index 990965a..70f11db 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/publickey/PublickeyBackingEngineFactory.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/publickey/PublickeyBackingEngineFactory.java
@@ -31,7 +31,7 @@ public class PublickeyBackingEngineFactory implements BackingEngineFactory {
 
     private static final String USER_FILE = "users";
 
-    public BackingEngine build(Map options) {
+    public BackingEngine build(Map<String, ?> options) {
         PublickeyBackingEngine engine = null;
         String usersFile = (String) options.get(USER_FILE);
 
@@ -39,12 +39,11 @@ public class PublickeyBackingEngineFactory implements BackingEngineFactory {
         Properties users;
         try {
             users = new Properties(f);
-            engine = new PublickeyBackingEngine(users);
+            return new PublickeyBackingEngine(users);
         } catch (IOException ioe) {
             logger.warn("Cannot open keys file:" + usersFile);
-        } finally {
-            return engine;
         }
+        return engine;
     }
 
     public String getModuleClass() {