karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [6/7] git commit: [KARAF-2760]monitor etc/user.properties change with felix FileInstaller (cherry picked from commit 2cf592365f7a6a100107fda7bf40b6e8f15e95d2)
Date Fri, 21 Feb 2014 18:22:55 GMT
[KARAF-2760]monitor etc/user.properties change with felix FileInstaller
(cherry picked from commit 2cf592365f7a6a100107fda7bf40b6e8f15e95d2)

Conflicts:
	jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java
(cherry picked from commit a60cec5bdc0c7b2e8777a03937d3409f90db8ca9)


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

Branch: refs/heads/karaf-3.0.x
Commit: 4d7f393d6421110d69500d287c30bb73a3dce471
Parents: c3e198a
Author: Freeman Fang <freeman.fang@gmail.com>
Authored: Tue Feb 18 14:03:11 2014 +0800
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Fri Feb 21 19:17:34 2014 +0100

----------------------------------------------------------------------
 jaas/modules/pom.xml                            |  5 ++
 .../modules/properties/PropertiesInstaller.java | 54 ++++++++++++++++++++
 .../properties/PropertiesLoginModule.java       | 14 +++--
 3 files changed, 70 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/4d7f393d/jaas/modules/pom.xml
----------------------------------------------------------------------
diff --git a/jaas/modules/pom.xml b/jaas/modules/pom.xml
index e45cddf..2e3df63 100644
--- a/jaas/modules/pom.xml
+++ b/jaas/modules/pom.xml
@@ -55,6 +55,11 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.fileinstall</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <scope>provided</scope>

http://git-wip-us.apache.org/repos/asf/karaf/blob/4d7f393d/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesInstaller.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesInstaller.java
b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesInstaller.java
new file mode 100644
index 0000000..730e97e
--- /dev/null
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesInstaller.java
@@ -0,0 +1,54 @@
+package org.apache.karaf.jaas.modules.properties;
+
+import java.io.File;
+
+import org.apache.felix.fileinstall.ArtifactInstaller;
+import org.apache.felix.utils.properties.Properties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PropertiesInstaller implements ArtifactInstaller {
+    
+    private final Logger LOGGER = LoggerFactory.getLogger(PropertiesInstaller.class);
+    
+    private String usersFileName;
+    
+    private File usersFile;
+    
+        
+    PropertiesLoginModule propertiesLoginModule;
+
+    
+    public PropertiesInstaller(PropertiesLoginModule propertiesLoginModule, String usersFile)
{
+        this.propertiesLoginModule = propertiesLoginModule;
+        this.usersFileName = usersFile;
+    }
+
+    public boolean canHandle(File artifact) {
+        if (usersFile == null) {
+            usersFile = new File(usersFileName);
+        }
+        return artifact.getName().endsWith(usersFile.getName());
+    }
+
+    public void install(File artifact) throws Exception {
+        if (usersFile == null) {
+            usersFile = new File(usersFileName);
+        }
+        Properties userProperties = new Properties(usersFile);
+        this.propertiesLoginModule.encryptedPassword(userProperties);
+    }
+
+    public void update(File artifact) throws Exception {
+        if (usersFile == null) {
+            usersFile = new File(usersFileName);
+        }
+        Properties userProperties = new Properties(usersFile);
+        this.propertiesLoginModule.encryptedPassword(userProperties);
+    }
+
+    public void uninstall(File artifact) throws Exception {
+        LOGGER.warn("the users.properties was removed");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/4d7f393d/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 e618f93..b7d375d 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
@@ -48,13 +48,20 @@ public class PropertiesLoginModule extends AbstractKarafLoginModule {
     static final String USER_FILE = "users";
 
     private String usersFile;
-
+    
+    private PropertiesInstaller propertiesInstaller;
+    
+    
     public void initialize(Subject sub, CallbackHandler handler, Map sharedState, Map options)
{
         super.initialize(sub,handler,options);
         usersFile = (String) options.get(USER_FILE);
         if (debug) {
             LOGGER.debug("Initialized debug={} usersFile={}", debug, usersFile);
         }
+        propertiesInstaller = new PropertiesInstaller(this, usersFile);
+        if (this.bundleContext != null) {
+            this.bundleContext.registerService("org.apache.felix.fileinstall.ArtifactInstaller",
propertiesInstaller, null);
+        }       
     }
 
     public boolean login() throws LoginException {
@@ -74,7 +81,7 @@ public class PropertiesLoginModule extends AbstractKarafLoginModule {
         }
 
         //encrypt all password if necessary
-        EncryptedPassword(users);
+        encryptedPassword(users);
 
         Callback[] callbacks = new Callback[2];
 
@@ -176,7 +183,8 @@ public class PropertiesLoginModule extends AbstractKarafLoginModule {
         return true;
     }
 
-    private void EncryptedPassword(Properties users) {
+    
+    void encryptedPassword(Properties users) {
         for (Object userName : users.keySet()) {
             String user = (String)userName;
             String userInfos = null;


Mime
View raw message