You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2013/04/09 14:33:47 UTC

svn commit: r1465994 - in /ace/trunk: org.apache.ace.configurator.serveruseradmin/ org.apache.ace.configurator.useradmin.task/ org.apache.ace.configurator/ org.apache.ace.configurator/src/org/apache/ace/configurator/serveruseradmin/ org.apache.ace.conf...

Author: marrs
Date: Tue Apr  9 12:33:46 2013
New Revision: 1465994

URL: http://svn.apache.org/r1465994
Log:
ACE-333 Merged the configurator projects.

Added:
    ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/serveruseradmin/
    ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/serveruseradmin/Activator.java
    ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/
    ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/
    ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/Activator.java
    ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/UpdateUserAdminTask.java
Removed:
    ace/trunk/org.apache.ace.configurator.serveruseradmin/
    ace/trunk/org.apache.ace.configurator.useradmin.task/
Modified:
    ace/trunk/org.apache.ace.configurator/bnd.bnd
    ace/trunk/org.apache.ace.useradmin.ui.itest/bnd.bnd
    ace/trunk/run-client/client.bndrun
    ace/trunk/run-obr/obr.bndrun
    ace/trunk/run-server-allinone/server-allinone.bndrun
    ace/trunk/run-server/server.bndrun

Modified: ace/trunk/org.apache.ace.configurator/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.configurator/bnd.bnd?rev=1465994&r1=1465993&r2=1465994&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.configurator/bnd.bnd (original)
+++ ace/trunk/org.apache.ace.configurator/bnd.bnd Tue Apr  9 12:33:46 2013
@@ -1,8 +1,12 @@
--buildpath: osgi.core,\
+-buildpath: \
+	osgi.core,\
 	osgi.cmpn,\
 	org.apache.felix.dependencymanager,\
+	org.apache.ace.range.api;version=latest,\
+	org.apache.ace.repository.api;version=latest,\
+	org.apache.ace.repository.ext;version=latest,\
+	org.apache.ace.resourceprocessor.useradmin;version=latest,\
 	org.apache.ace.test;version=latest,\
 	commons-io;version=2.0.1
-Bundle-Activator: org.apache.ace.configurator.Activator
-Private-Package: org.apache.ace.configurator
-Bundle-Version: 1.0.0
\ No newline at end of file
+
+-sub: *.bnd
\ No newline at end of file

Added: ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/serveruseradmin/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/serveruseradmin/Activator.java?rev=1465994&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/serveruseradmin/Activator.java (added)
+++ ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/serveruseradmin/Activator.java Tue Apr  9 12:33:46 2013
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ace.configurator.serveruseradmin;
+
+import java.util.Dictionary;
+
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.osgi.service.useradmin.UserAdmin;
+
+/**
+ * This bundle configures a single server user, which is to be used until we
+ * have a full-fledged user administration system.
+ */
+public class Activator extends DependencyActivatorBase {
+
+    private final static String TEST_USER = "serverUser";
+    private final static String TEST_PASSWORD = "serverPassword";
+
+    private volatile UserAdmin m_userAdmin; /* Injected by dependency manager */
+    private volatile LogService m_log;      /* Injected by dependency manager */
+
+    @Override
+    public void init(BundleContext context, DependencyManager manager) throws Exception {
+        manager.add(createComponent()
+            .setImplementation(this)
+            .add(createServiceDependency().setService(UserAdmin.class).setRequired(true))
+            .add(createServiceDependency().setService(LogService.class).setRequired(false)));
+    }
+
+    @Override
+    public void destroy(BundleContext context, DependencyManager manager) throws Exception {
+        // do nothing
+    }
+
+    public synchronized void start() {
+        // create users
+        createUser(TEST_USER, TEST_PASSWORD);
+    }
+
+    @SuppressWarnings("unchecked")
+    private User createUser(String username, String password) {
+        User user = (User) m_userAdmin.createRole(username, Role.USER);
+        if (user != null) {
+            Dictionary properties = user.getProperties();
+            if (properties != null) {
+                properties.put("username", username);
+            }
+            else {
+                m_log.log(LogService.LOG_ERROR, "Could not get properties for " + username);
+            }
+
+            Dictionary credentials = user.getCredentials();
+            if (credentials != null) {
+                credentials.put("password", password);
+            }
+            else {
+                m_log.log(LogService.LOG_ERROR, "Could not get credentials for " + username);
+            }
+        }
+        else {
+            try {
+                user = (User) m_userAdmin.getRole(username);
+                m_log.log(LogService.LOG_WARNING, "User " + username + " already existed.");
+            }
+            catch (ClassCastException e) {
+                m_log.log(LogService.LOG_WARNING, "Role " + username + " already existed (it's no user).");
+            }
+        }
+        return user;
+    }
+}
\ No newline at end of file

Added: ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/Activator.java?rev=1465994&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/Activator.java (added)
+++ ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/Activator.java Tue Apr  9 12:33:46 2013
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ace.configurator.useradmin.task;
+
+import java.util.Properties;
+
+import org.apache.ace.resourceprocessor.useradmin.UserAdminConfigurator;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * Activator for the UserAdmin updater task.
+ */
+public class Activator extends DependencyActivatorBase {
+
+    @Override
+    public void init(BundleContext context, DependencyManager manager) throws Exception {
+        Properties props = new Properties();
+        props.put("taskName", UpdateUserAdminTask.PID);
+        props.put("description", "Synchronizes the UserAdmin with the server.");
+        manager.add(createComponent()
+            .setInterface(Runnable.class.getName(), props)
+            .setImplementation(UpdateUserAdminTask.class)
+            .add(createServiceDependency().setService(UserAdminConfigurator.class).setRequired(true))
+            .add(createServiceDependency().setService(LogService.class).setRequired(false))
+            .add(createConfigurationDependency().setPid(UpdateUserAdminTask.PID))
+            );
+    }
+
+    @Override
+    public void destroy(BundleContext context, DependencyManager manager) throws Exception {
+        // Nothing to do, the runnable will be pulled automatically.
+    }
+
+}
\ No newline at end of file

Added: ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/UpdateUserAdminTask.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/UpdateUserAdminTask.java?rev=1465994&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/UpdateUserAdminTask.java (added)
+++ ace/trunk/org.apache.ace.configurator/src/org/apache/ace/configurator/useradmin/task/UpdateUserAdminTask.java Tue Apr  9 12:33:46 2013
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ace.configurator.useradmin.task;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.ace.repository.Repository;
+import org.apache.ace.repository.ext.BackupRepository;
+import org.apache.ace.repository.ext.CachedRepository;
+import org.apache.ace.repository.ext.impl.CachedRepositoryImpl;
+import org.apache.ace.repository.ext.impl.FilebasedBackupRepository;
+import org.apache.ace.resourceprocessor.useradmin.UserAdminConfigurator;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.log.LogService;
+
+/**
+ * UpdateUserAdminTask processes the contents of a repository containing
+ * an XML description of the users that should be present in this system's
+ * user admin.<br>
+ * <br>
+ * From the first run on, this task will keep a local copy of the user repository,
+ * so login can happen when the server is offline.
+ */
+public class UpdateUserAdminTask implements Runnable, ManagedService {
+    /**
+     * The UpdateUserAdminTask is also used as its taskName for the scheduler.
+     */
+    public static final String PID = UpdateUserAdminTask.class.getName();
+
+    public static final String KEY_REPOSITORY_LOCATION = "repositoryLocation";
+    public static final String KEY_REPOSITORY_CUSTOMER = "repositoryCustomer";
+    public static final String KEY_REPOSITORY_NAME = "repositoryName";
+
+    private static final String FILE_ROOT = "userrepositories";
+    private static final String VERSION = "version";
+
+    // Will by injected by Dependency Manager...
+    private volatile UserAdminConfigurator m_configurator;
+    private volatile LogService m_log;
+    private volatile BundleContext m_context;
+
+    private CachedRepository m_repo;
+    private BackupRepository m_backup;
+    private String m_repoFilter;
+    private File m_properties;
+    
+    /**
+     * Called by Dependency Manager upon initialization of this component.
+     * <p>
+     * Due to the dependency on the configuration; the {@link #updated(Dictionary)} method is already called!
+     * </p>
+     * 
+     * @param comp this component, cannot be <code>null</code>.
+     */
+    public void init(Component comp) {
+        final DependencyManager dm = comp.getDependencyManager();
+        // Add the required dependency to the remote repository...
+        comp.add(dm.createServiceDependency()
+            .setService(Repository.class, m_repoFilter)
+            .setCallbacks("addRepo", "removeRepo")
+            .setInstanceBound(true)
+            .setRequired(true)
+            );
+    }
+
+    /**
+     * Checks whether there are updates to the remote repository, and if so, updates the users' backend with its contents.
+     * 
+     * @see java.lang.Runnable#run()
+     */
+    public void run() {
+        try {
+            if (!m_repo.isCurrent()) {
+                m_configurator.setUsers(m_repo.checkout(true));
+                m_log.log(LogService.LOG_DEBUG, "UpdateUserAdminTask updates to a new version: " + m_repo.getMostRecentVersion());
+                saveVersion(m_properties, m_repo.getMostRecentVersion());
+            }
+        }
+        catch (IOException e) {
+            // If anything went wrong, this means the remote repository is not available;
+            // this also means the UserAdmin is left undisturbed.
+        	m_log.log(LogService.LOG_WARNING, "Error running update UserAdmin task.", e);
+        }
+    }
+
+    /**
+     * Called by Dependency Manager upon starting of this component.
+     * 
+     * @param comp this component, cannot be <code>null</code>.
+     */
+    public void start(Component comp) {
+        try {
+            // Try to read the server data
+            m_configurator.setUsers(m_repo.checkout(true));
+        }
+        catch (IOException e) {
+            try {
+                m_log.log(LogService.LOG_DEBUG, "UpdateUserAdminTask failed to load remote data; falling back to local data.");
+                // If reading remote fails, try to set whatever we have locally
+                m_configurator.setUsers(m_repo.getLocal(true));
+            }
+            catch (IOException e2) {
+                // No problem, now we just have an empty user admin...
+                m_log.log(LogService.LOG_DEBUG, "UpdateUserAdminTask failed to load local data.");
+            }
+        }
+    }
+
+    public void updated(Dictionary dict) throws ConfigurationException {
+        if (dict != null) {
+            String customer = (String) dict.get(KEY_REPOSITORY_CUSTOMER);
+            if (customer == null) {
+                throw new ConfigurationException(KEY_REPOSITORY_CUSTOMER, "Property missing.");
+            }
+            String name = (String) dict.get(KEY_REPOSITORY_NAME);
+            if (name == null) {
+                throw new ConfigurationException(KEY_REPOSITORY_NAME, "Property missing.");
+            }
+
+            String fileRoot = FILE_ROOT + File.separator + customer + File.separator + name + File.separator;
+
+            File local = getFile(fileRoot + "local");
+            File backup = getFile(fileRoot + "backup");
+            m_backup = new FilebasedBackupRepository(local, backup);
+            
+            m_properties = getFile(fileRoot + "properties");
+            
+            m_repoFilter = "(&(customer=" + customer + ")(name=" + name + "))";
+        }
+    }
+
+    /**
+     * Creates the cached repository when given a remote repository.
+     * 
+     * @param remoteRepo the remote repository to add, cannot be <code>null</code>.
+     */
+    final void addRepo(Repository remoteRepo) {
+        m_repo = new CachedRepositoryImpl(remoteRepo, m_backup, loadVersion(m_properties));
+    }
+
+    /**
+     * Removes the cached repository when given a remote repository.
+     * 
+     * @param remoteRepo the remote repository to remove, cannot be <code>null</code>.
+     */
+    final void removeRepo(Repository remoteRepo) {
+        m_repo = null;
+    }
+
+    private File getFile(String name) {
+        File result = m_context.getDataFile(name);
+        if (!result.exists()) {
+            result.getParentFile().mkdirs();
+            try {
+                if (!result.createNewFile()) {
+                    m_log.log(LogService.LOG_ERROR, "Error creating new file " + name);
+                }
+            }
+            catch (IOException e) {
+                m_log.log(LogService.LOG_ERROR, "Error creating new file " + name, e);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Loads the most recent version from the given properties file.
+     */
+    private long loadVersion(File propertiesfile) {
+        long result = CachedRepositoryImpl.UNCOMMITTED_VERSION;
+        try {
+            Properties props = new Properties();
+            props.loadFromXML(new FileInputStream(propertiesfile));
+            result = Long.parseLong((String) props.get(VERSION));
+        }
+        catch (IOException ioe) {
+            // We have no data; no problem.
+        }
+        return result;
+    }
+
+    /**
+     * Saves the most recent version to the given properties file.
+     */
+    private void saveVersion(File properties, Long version) {
+        Properties props = new Properties();
+        props.put(VERSION, version.toString());
+        try {
+            FileOutputStream fileOutputStream = new FileOutputStream(properties);
+            props.storeToXML(fileOutputStream, null);
+        }
+        catch (IOException e) {
+            m_log.log(LogService.LOG_ERROR, "UpdateUserAdminTask failed to save local version number.");
+        }
+    }
+}
\ No newline at end of file

Modified: ace/trunk/org.apache.ace.useradmin.ui.itest/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.useradmin.ui.itest/bnd.bnd?rev=1465994&r1=1465993&r2=1465994&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.useradmin.ui.itest/bnd.bnd (original)
+++ ace/trunk/org.apache.ace.useradmin.ui.itest/bnd.bnd Tue Apr  9 12:33:46 2013
@@ -29,7 +29,7 @@ Private-Package: org.apache.ace.useradmi
 	org.apache.ace.client.rest;version=latest,\
 	org.apache.ace.configurator.serveruseradmin;version=latest,\
 	org.apache.ace.configurator.useradmin.task;version=latest,\
-	org.apache.ace.configurator;version=latest,\
+	org.apache.ace.configurator.impl;version=latest,\
 	org.apache.ace.connectionfactory;version=latest,\
 	org.apache.ace.consolelogger;version=latest,\
 	org.apache.ace.deployment.provider.api;version=latest,\

Modified: ace/trunk/run-client/client.bndrun
URL: http://svn.apache.org/viewvc/ace/trunk/run-client/client.bndrun?rev=1465994&r1=1465993&r2=1465994&view=diff
==============================================================================
--- ace/trunk/run-client/client.bndrun (original)
+++ ace/trunk/run-client/client.bndrun Tue Apr  9 12:33:46 2013
@@ -26,7 +26,7 @@
 	org.apache.ace.client.rest;version=latest,\
 	org.apache.ace.configurator.serveruseradmin;version=latest,\
 	org.apache.ace.configurator.useradmin.task;version=latest,\
-	org.apache.ace.configurator;version=latest,\
+	org.apache.ace.configurator.impl;version=latest,\
 	org.apache.ace.connectionfactory;version=latest,\
 	org.apache.ace.consolelogger;version=latest,\
 	org.apache.ace.verifier.ui;version=latest,\

Modified: ace/trunk/run-obr/obr.bndrun
URL: http://svn.apache.org/viewvc/ace/trunk/run-obr/obr.bndrun?rev=1465994&r1=1465993&r2=1465994&view=diff
==============================================================================
--- ace/trunk/run-obr/obr.bndrun (original)
+++ ace/trunk/run-obr/obr.bndrun Tue Apr  9 12:33:46 2013
@@ -12,7 +12,7 @@
 	org.apache.felix.useradmin,\
 	org.apache.felix.useradmin.filestore,\
 	org.apache.ace.httplistener;version=latest,\
-	org.apache.ace.configurator;version=latest,\
+	org.apache.ace.configurator.impl;version=latest,\
 	org.apache.ace.obr.metadata;version=latest,\
 	org.apache.ace.obr.storage;version=latest,\
 	org.apache.ace.authentication.api;version=latest,\

Modified: ace/trunk/run-server-allinone/server-allinone.bndrun
URL: http://svn.apache.org/viewvc/ace/trunk/run-server-allinone/server-allinone.bndrun?rev=1465994&r1=1465993&r2=1465994&view=diff
==============================================================================
--- ace/trunk/run-server-allinone/server-allinone.bndrun (original)
+++ ace/trunk/run-server-allinone/server-allinone.bndrun Tue Apr  9 12:33:46 2013
@@ -26,7 +26,7 @@
 	org.apache.ace.client.rest;version=latest,\
 	org.apache.ace.configurator.serveruseradmin;version=latest,\
 	org.apache.ace.configurator.useradmin.task;version=latest,\
-	org.apache.ace.configurator;version=latest,\
+	org.apache.ace.configurator.impl;version=latest,\
 	org.apache.ace.connectionfactory;version=latest,\
 	org.apache.ace.consolelogger;version=latest,\
 	org.apache.ace.deployment.provider.api;version=latest,\

Modified: ace/trunk/run-server/server.bndrun
URL: http://svn.apache.org/viewvc/ace/trunk/run-server/server.bndrun?rev=1465994&r1=1465993&r2=1465994&view=diff
==============================================================================
--- ace/trunk/run-server/server.bndrun (original)
+++ ace/trunk/run-server/server.bndrun Tue Apr  9 12:33:46 2013
@@ -19,7 +19,7 @@
 	org.apache.ace.authentication.processor.password;version=latest,\
 	org.apache.ace.configurator.serveruseradmin;version=latest,\
 	org.apache.ace.configurator.useradmin.task;version=latest,\
-	org.apache.ace.configurator;version=latest,\
+	org.apache.ace.configurator.impl;version=latest,\
 	org.apache.ace.connectionfactory;version=latest,\
 	org.apache.ace.deployment.provider.api;version=latest,\
 	org.apache.ace.deployment.provider.repositorybased;version=latest,\