james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r415619 - in /james/server/trunk/src: conf/ java/org/apache/james/management/ java/org/apache/james/remotemanager/ test/org/apache/james/management/ test/org/apache/james/test/mock/james/
Date Tue, 20 Jun 2006 12:00:57 GMT
Author: berndf
Date: Tue Jun 20 05:00:57 2006
New Revision: 415619

URL: http://svn.apache.org/viewvc?rev=415619&view=rev
Log:
- added additional parameter to many operations to select the user repository
- added operation getUserRepositoryNames()

Modified:
    james/server/trunk/src/conf/james-assembly.xml
    james/server/trunk/src/java/org/apache/james/management/UserManagement.java
    james/server/trunk/src/java/org/apache/james/management/UserManagement.xinfo
    james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java
    james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java
    james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java
    james/server/trunk/src/test/org/apache/james/management/UserManagementTest.java
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockUsersStore.java

Modified: james/server/trunk/src/conf/james-assembly.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-assembly.xml?rev=415619&r1=415618&r2=415619&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-assembly.xml (original)
+++ james/server/trunk/src/conf/james-assembly.xml Tue Jun 20 05:00:57 2006
@@ -70,6 +70,7 @@
     <!-- The User Management block  -->
   <block name="usermanagement" class="org.apache.james.management.UserManagement" >
     <provide name="localusersrepository" role="org.apache.james.services.UsersRepository"/>
+    <provide name="users-store" role="org.apache.james.services.UsersStore"/>
   </block>
 
   <!-- POP3 Server -->

Modified: james/server/trunk/src/java/org/apache/james/management/UserManagement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/UserManagement.java?rev=415619&r1=415618&r2=415619&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/UserManagement.java (original)
+++ james/server/trunk/src/java/org/apache/james/management/UserManagement.java Tue Jun 20
05:00:57 2006
@@ -24,6 +24,7 @@
 import org.apache.james.services.UsersRepository;
 import org.apache.james.services.User;
 import org.apache.james.services.JamesUser;
+import org.apache.james.services.UsersStore;
 import org.apache.mailet.MailAddress;
 
 import javax.mail.internet.ParseException;
@@ -33,89 +34,112 @@
 
 public class UserManagement implements UserManagementMBean, Serviceable {
 
+    String ROLE = "org.apache.james.management.UserManagement";
+    
     /**
      * The administered UsersRepository
      */
-    private UsersRepository users;
+    private UsersRepository localUsers;
+    private UsersStore usersStore;
 
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */
     public void service( final ServiceManager componentManager )
         throws ServiceException {
-        users = (UsersRepository) componentManager.lookup(UsersRepository.ROLE);
-        if (users == null) {
-            throw new ServiceException("","The user repository could not be found.");
+        localUsers = (UsersRepository) componentManager.lookup(UsersRepository.ROLE);
+        if (localUsers == null) {
+            throw new ServiceException("","The local user repository could not be found.");
+        }
+        usersStore = (UsersStore)componentManager.lookup( UsersStore.ROLE );
+        if (usersStore == null) {
+            throw new ServiceException("","The user store containing the user repositories
could not be found.");
         }
     }
 
-    private JamesUser getJamesUser(String userName) throws UserManagementException {
-        User baseuser = users.getUserByName(userName);
+    private JamesUser getJamesUser(String userName, String repositoryName) throws UserManagementException
{
+        User baseuser = getUserRepository(repositoryName).getUserByName(userName);
         if (baseuser == null) throw new UserManagementException("user not found: " + userName);
         if (! (baseuser instanceof JamesUser ) ) throw new UserManagementException("user
is not of type JamesUser: " + userName);
 
         return (JamesUser) baseuser;
     }
 
-    public boolean addUser(String userName, String password) {
-        return users.addUser(userName, password);
+    private UsersRepository getUserRepository(String repositoryName) throws UserManagementException
{
+        if (repositoryName == null) return localUsers; // return default
+
+        if (usersStore == null) throw new UserManagementException("cannot access user repository
named " + repositoryName);
+
+        UsersRepository repository = usersStore.getRepository(repositoryName);
+        if (repository == null) throw new UserManagementException("user repository does not
exist: " + repositoryName);
+        
+        return repository;
     }
 
-    public boolean deleteUser(String userName) {
+    public boolean addUser(String userName, String password, String repositoryName) throws
UserManagementException {
+        return getUserRepository(repositoryName).addUser(userName, password);
+    }
+
+    public boolean deleteUser(String userName, String repositoryName) throws UserManagementException
{
+        UsersRepository users = getUserRepository(repositoryName);
         if (!users.contains(userName)) return false;
         users.removeUser(userName);
         return true;
     }
 
-    public boolean verifyExists(String userName) {
+    public boolean verifyExists(String userName, String repositoryName) throws UserManagementException
{
+        UsersRepository users = getUserRepository(repositoryName);
         return users.contains(userName);
     }
 
-    public long countUsers() {
+    public long countUsers(String repositoryName) throws UserManagementException {
+        UsersRepository users = getUserRepository(repositoryName);
         return users.countUsers();
     }
 
-    public String[] listAllUsers() {
+    public String[] listAllUsers(String repositoryName) throws UserManagementException {
         List userNames = new ArrayList();
+        UsersRepository users = getUserRepository(repositoryName);
         for (Iterator it = users.list(); it.hasNext();) {
             userNames.add(it.next());
         }
         return (String[])userNames.toArray(new String[]{});
     }
 
-    public boolean setPassword(String userName, String password) throws UserManagementException
{
+    public boolean setPassword(String userName, String password, String repositoryName) throws
UserManagementException {
+        UsersRepository users = getUserRepository(repositoryName);
         User user = users.getUserByName(userName);
         if (user == null) throw new UserManagementException("user not found: " + userName);
         return user.setPassword(password);
     }
 
-    public boolean setAlias(String userName, String aliasUserName) throws UserManagementException
{
-        JamesUser user = getJamesUser(userName);
-        JamesUser aliasUser = getJamesUser(aliasUserName);
+    public boolean setAlias(String userName, String aliasUserName, String repositoryName)
throws UserManagementException {
+        JamesUser user = getJamesUser(userName, null);
+        JamesUser aliasUser = getJamesUser(aliasUserName, null);
         if (aliasUser == null) return false;
 
         boolean success = user.setAlias(aliasUserName);
         user.setAliasing(true);
-        users.updateUser(user);
+        getUserRepository(repositoryName).updateUser(user);
         return success;
     }
 
-    public boolean unsetAlias(String userName) throws UserManagementException {
-        JamesUser user = getJamesUser(userName);
+    public boolean unsetAlias(String userName, String repositoryName) throws UserManagementException
{
+        JamesUser user = getJamesUser(userName, null);
         if (!user.getAliasing()) return false;
         
         user.setAliasing(false);
-        users.updateUser(user);
+        getUserRepository(repositoryName).updateUser(user);
         return true;
     }
 
-    public String getAlias(String userName) throws UserManagementException {
-        JamesUser user = getJamesUser(userName);
+    public String getAlias(String userName, String repositoryName) throws UserManagementException
{
+        JamesUser user = getJamesUser(userName, null);
         if (!user.getAliasing()) return null;
         return user.getAlias();
     }
 
-    public boolean setForwardAddress(String userName, String forwardEmailAddress) throws
UserManagementException {
+    public boolean setForwardAddress(String userName, String forwardEmailAddress, String
repositoryName) throws UserManagementException {
         MailAddress forwardAddress;
         try {
              forwardAddress = new MailAddress(forwardEmailAddress);
@@ -123,30 +147,41 @@
             throw new UserManagementException(pe);
         }
 
-        JamesUser user = getJamesUser(userName);
+        JamesUser user = getJamesUser(userName, null);
         boolean success = user.setForwardingDestination(forwardAddress);
         if (!success) return false;
         
         user.setForwarding(true);
-        users.updateUser(user);
+        getUserRepository(repositoryName).updateUser(user);
         return true;
     }
 
-    public boolean unsetForwardAddress(String userName) throws UserManagementException {
-        JamesUser user = getJamesUser(userName);
+    public boolean unsetForwardAddress(String userName, String repositoryName) throws UserManagementException
{
+        JamesUser user = getJamesUser(userName, null);
 
         if (!user.getForwarding()) return false;
         
         user.setForwarding(false);
-        users.updateUser(user);
+        getUserRepository(repositoryName).updateUser(user);
         return true;
     }
 
-    public String getForwardAddress(String userName) throws UserManagementException {
-        JamesUser user = getJamesUser(userName);
+    public String getForwardAddress(String userName, String repositoryName) throws UserManagementException
{
+        JamesUser user = getJamesUser(userName, null);
         if (!user.getForwarding()) return null;
         return user.getForwardingDestination().toString();
     }
 
+    public List getUserRepositoryNames() {
+        List result = new ArrayList();
+        if (usersStore == null) return result;
+        
+        Iterator repositoryNames = usersStore.getRepositoryNames();
+        while (repositoryNames.hasNext()) {
+            String name = (String) repositoryNames.next();
+            result.add(name);
+        }
+        return result;
+    }
 
 }

Modified: james/server/trunk/src/java/org/apache/james/management/UserManagement.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/UserManagement.xinfo?rev=415619&r1=415618&r2=415619&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/UserManagement.xinfo (original)
+++ james/server/trunk/src/java/org/apache/james/management/UserManagement.xinfo Tue Jun 20
05:00:57 2006
@@ -16,5 +16,8 @@
     <dependency>
       <service name="org.apache.james.services.UsersRepository" version="1.0"/>
     </dependency>
+    <dependency>
+      <service name="org.apache.james.services.UsersStore" version="1.0"/>
+    </dependency>
   </dependencies>
 </blockinfo>

Modified: james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java?rev=415619&r1=415618&r2=415619&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java (original)
+++ james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java Tue Jun
20 05:00:57 2006
@@ -17,6 +17,8 @@
 
 package org.apache.james.management;
 
+import java.util.List;
+
 /**
  * Expose user account management functionality through JMX.
  * 
@@ -32,10 +34,12 @@
      *
      * @param userName The name of the user being added
      * @param password The password of the user being added
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return if the operation was successfull
      */
-    boolean addUser(String userName, String password);
-    
+    boolean addUser(String userName, String password, String repositoryName) throws UserManagementException;
+
     /**
      * Deletes a user from this mail server.
      *
@@ -43,9 +47,11 @@
      * @phoenix:mx-description Delete an existing user
      *
      * @param userName The name of the user being deleted
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return if the operation was successfull
      */
-    boolean deleteUser(String userName);
+    boolean deleteUser(String userName, String repositoryName) throws UserManagementException;
 
     /**
      * Check if a user exists with the given name.
@@ -54,9 +60,11 @@
      * @phoenix:mx-description Check for existing user name
      *
      * @param userName The name of the user
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return TRUE, if the user exists
      */
-    boolean verifyExists(String userName);
+    boolean verifyExists(String userName, String repositoryName) throws UserManagementException;
 
     /**
      * Total count of existing users
@@ -64,9 +72,11 @@
      * @phoenix:mx-operation
      * @phoenix:mx-description Total count of existing users
      *
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return Total count of existing users
      */
-    long countUsers();
+    long countUsers(String repositoryName) throws UserManagementException;
 
     /**
      * List the names of all users
@@ -74,9 +84,11 @@
      * @phoenix:mx-operation
      * @phoenix:mx-description List all existing users
      *
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return List of all user names
      */
-    String[] listAllUsers();
+    String[] listAllUsers(String repositoryName) throws UserManagementException;
 
     /**
      * Set a user's password
@@ -86,10 +98,12 @@
      *
      * @param userName The name of the user whose password will be changed
      * @param password The new password 
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return if the user has been found and the password was changed successfully
      */
-    boolean setPassword(String userName, String password) throws UserManagementException;
-    
+    boolean setPassword(String userName, String password, String repositoryName) throws UserManagementException;
+
     /**
      * Set a user's alias to whom all mail is forwarded to
      *
@@ -98,10 +112,12 @@
      *
      * @param userName The name of the user whose alias is set
      * @param aliasUserName The user becoming the new alias 
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return if the user has been found and the password was changed successfully
      */
-    boolean setAlias(String userName, String aliasUserName) throws UserManagementException;
-    
+    boolean setAlias(String userName, String aliasUserName, String repositoryName) throws
UserManagementException;
+
     /**
      * Removes a user's alias which terminates local mail forwarding
      *
@@ -109,19 +125,23 @@
      * @phoenix:mx-description Removes a user's alias which terminates local mail forwarding
      *
      * @param userName The name of the user whose alias is unset
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return if the user has been found and the alias was removed
      */
-    boolean unsetAlias(String userName) throws UserManagementException;
-    
+    boolean unsetAlias(String userName, String repositoryName) throws UserManagementException;
+
     /**
      * Retrieves the user's alias, if set
      *
      * @phoenix:mx-operation
      * @phoenix:mx-description Retrieves the user's alias, if set
      *
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return User's alias, or NULL, if no alias is set
      */
-    String getAlias(String userName) throws UserManagementException;
+    String getAlias(String userName, String repositoryName) throws UserManagementException;
 
     /**
      * Set a user's forward email address to whom all mail is forwarded to
@@ -130,11 +150,13 @@
      * @phoenix:mx-description Set a user's forward email address to whom all mail is forwarded
to
      *
      * @param userName The name of the user whose forward is set
-     * @param forwardEmailAddress The new forward email address  
+     * @param forwardEmailAddress The new forward email address
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return if the user has been found and the password was changed successfully
      */
-    boolean setForwardAddress(String userName, String forwardEmailAddress) throws UserManagementException;
-    
+    boolean setForwardAddress(String userName, String forwardEmailAddress, String repositoryName)
throws UserManagementException;
+
     /**
      * Removes a user's forward email address which terminates remote mail forwarding
      *
@@ -142,18 +164,32 @@
      * @phoenix:mx-description Removes a user's forward email address which terminates remote
mail forwarding
      *
      * @param userName The name of the user whose forward is unset
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return if the user has been found and the forward was removed
      */
-    boolean unsetForwardAddress(String userName) throws UserManagementException;
-    
+    boolean unsetForwardAddress(String userName, String repositoryName) throws UserManagementException;
+
     /**
      * Retrieves the user's forward, if set
      *
      * @phoenix:mx-operation
      * @phoenix:mx-description Retrieves the user's forward, if set
      *
+     * @param userName The name of the user whose forward is set
+     * @param repositoryName The user repository, to which the operation should be applied.
If NULL, the LocalUsers
+     *        repository is used.
      * @return User's forward email address, or NULL, if no forward is set
      */
-    String getForwardAddress(String userName) throws UserManagementException;
+    String getForwardAddress(String userName, String repositoryName) throws UserManagementException;
 
+    /**
+     * Retrieves a list of the names of all available user repositories
+     *
+     * @phoenix:mx-operation
+     * @phoenix:mx-description Retrieves a list of the names of all available user repositories
+     *
+     * @return List<String> of repository names
+     */
+    public List getUserRepositoryNames();
 }

Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java?rev=415619&r1=415618&r2=415619&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java Tue Jun
20 05:00:57 2006
@@ -27,6 +27,7 @@
 import org.apache.james.services.MailServer;
 import org.apache.james.services.UsersRepository;
 import org.apache.james.services.UsersStore;
+import org.apache.james.management.UserManagement;
 
 import java.util.HashMap;
 
@@ -78,6 +79,11 @@
         = new RemoteManagerHandlerConfigurationDataImpl();
 
     /**
+     * Reference to UserManagement functionality
+     */
+    private UserManagement userManagement;
+
+    /**
      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
      */
     public void service( final ServiceManager componentManager )
@@ -201,6 +207,10 @@
          */
         public UsersStore getUserStore() {
             return RemoteManager.this.usersStore;
+        }
+
+        public UserManagement getUserManagement() {
+            return RemoteManager.this.userManagement;
         }
 
         /**

Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java?rev=415619&r1=415618&r2=415619&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java
(original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java
Tue Jun 20 05:00:57 2006
@@ -21,6 +21,7 @@
 import org.apache.james.services.MailServer;
 import org.apache.james.services.UsersRepository;
 import org.apache.james.services.UsersStore;
+import org.apache.james.management.UserManagement;
 
 import java.util.HashMap;
 
@@ -59,6 +60,11 @@
      */
     UsersStore getUserStore();
 
+    /**
+     * Accessor to User Management functionality
+     */
+    UserManagement getUserManagement();
+    
     /**
      * Returns the Administrative Account Data
      *

Modified: james/server/trunk/src/test/org/apache/james/management/UserManagementTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/management/UserManagementTest.java?rev=415619&r1=415618&r2=415619&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/management/UserManagementTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/management/UserManagementTest.java Tue Jun
20 05:00:57 2006
@@ -21,13 +21,14 @@
 import junit.framework.TestCase;
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.james.services.UsersRepository;
+import org.apache.james.services.UsersStore;
 import org.apache.james.test.mock.avalon.MockLogger;
 import org.apache.james.test.mock.avalon.MockServiceManager;
+import org.apache.james.test.mock.james.MockUsersStore;
 import org.apache.james.userrepository.MockUsersRepository;
 
-import java.io.IOException;
-import java.util.List;
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * Tests the UserManagement
@@ -47,36 +48,54 @@
         MockServiceManager serviceManager = new MockServiceManager();
         m_mockUsersRepository = new MockUsersRepository();
         serviceManager.put(UsersRepository.ROLE, m_mockUsersRepository);
+        serviceManager.put(UsersStore.ROLE, new MockUsersStore(m_mockUsersRepository));
         return serviceManager;
     }
 
-    public void testUserCount() throws IOException {
-        assertEquals("no user yet", 0, m_userManagement.countUsers());
+    public void testUserCount() throws UserManagementException {
+        assertEquals("no user yet", 0, m_userManagement.countUsers(null));
         m_mockUsersRepository.addUser("testCount1", "testCount");
-        assertEquals("1 user", 1, m_userManagement.countUsers());
+        assertEquals("1 user", 1, m_userManagement.countUsers(null));
         m_mockUsersRepository.addUser("testCount2", "testCount");
-        assertEquals("2 users", 2, m_userManagement.countUsers());
+        assertEquals("2 users", 2, m_userManagement.countUsers(null));
         m_mockUsersRepository.removeUser("testCount1");
-        assertEquals("1 user", 1, m_userManagement.countUsers());
+        assertEquals("1 user", 1, m_userManagement.countUsers(null));
+    }
+
+    public void testDefaultRepositoryIsLocalUsers() throws UserManagementException {
+        m_userManagement.addUser("testCount1", "testCount", null);
+        m_userManagement.addUser("testCount2", "testCount", "LocalUsers");
+
+        assertEquals("2 users", 2, m_userManagement.countUsers(null));
+        assertEquals("2 users", 2, m_userManagement.countUsers("LocalUsers"));
+    }
+
+    public void testNonExistingRepository() throws UserManagementException {
+        try {
+            m_userManagement.addUser("testCount1", "testCount", "NonExisting");
+            fail("retrieved non-existing repository");
+        } catch (UserManagementException e) {
+            // success
+        }
     }
 
-    public void testAddUserAndVerify() throws IOException {
+    public void testAddUserAndVerify() throws UserManagementException {
         assertTrue("user added", m_mockUsersRepository.addUser("testCount1", "testCount"));
-        assertFalse("user not there", m_userManagement.verifyExists("testNotAdded"));
-        assertTrue("user is there", m_userManagement.verifyExists("testCount1"));
+        assertFalse("user not there", m_userManagement.verifyExists("testNotAdded", null));
+        assertTrue("user is there", m_userManagement.verifyExists("testCount1", null));
         m_mockUsersRepository.removeUser("testCount1");
-        assertFalse("user not there", m_userManagement.verifyExists("testCount1"));
+        assertFalse("user not there", m_userManagement.verifyExists("testCount1", null));
     }
 
-    public void testDelUser() throws IOException {
+    public void testDelUser() throws UserManagementException {
         assertTrue("user added", m_mockUsersRepository.addUser("testDel", "test"));
-        assertFalse("user not there", m_userManagement.verifyExists("testNotDeletable"));
-        assertTrue("user is there", m_userManagement.verifyExists("testDel"));
+        assertFalse("user not there", m_userManagement.verifyExists("testNotDeletable", null));
+        assertTrue("user is there", m_userManagement.verifyExists("testDel", null));
         m_mockUsersRepository.removeUser("testDel");
-        assertFalse("user no longer there", m_userManagement.verifyExists("testDel"));
+        assertFalse("user no longer there", m_userManagement.verifyExists("testDel", null));
     }
 
-    public void testListUsers() throws IOException {
+    public void testListUsers() throws UserManagementException {
 
         String[] usersArray = new String[] {"ccc", "aaa", "dddd", "bbbbb"};
         List users = Arrays.asList(usersArray);
@@ -86,7 +105,7 @@
             assertTrue("user added", m_mockUsersRepository.addUser(user, "test"));
         }
 
-        String[] userNames = m_userManagement.listAllUsers();
+        String[] userNames = m_userManagement.listAllUsers(null);
         assertEquals("user count", users.size(), userNames.length);
 
         for (int i = 0; i < userNames.length; i++) {
@@ -100,58 +119,58 @@
 
         // do some tests when parameter users don't exist
         try {
-            m_userManagement.setAlias("testNonExist1", "testNonExist2");
+            m_userManagement.setAlias("testNonExist1", "testNonExist2", null);
             fail("user unknown to server");
         } catch (UserManagementException e) {
             // success
         }
 
-        assertTrue("user added", m_userManagement.addUser("testAlias1", "test"));
+        assertTrue("user added", m_userManagement.addUser("testAlias1", "test", null));
 
-        assertNull("no alias set", m_userManagement.getAlias("testAlias1"));
+        assertNull("no alias set", m_userManagement.getAlias("testAlias1", null));
 
         try {
-            m_userManagement.setAlias("testAlias1", "testNonExist2");
+            m_userManagement.setAlias("testAlias1", "testNonExist2", null);
             fail("alias unknown to server");
         } catch (UserManagementException e) {
             // success
         }
 
         try {
-            m_userManagement.setAlias("testNonExist1", "testAlias");
+            m_userManagement.setAlias("testNonExist1", "testAlias", null);
             fail("user unknown to server");
         } catch (UserManagementException e) {
             // success
         }
 
-        assertTrue("user added", m_userManagement.addUser("testAlias2", "test"));
+        assertTrue("user added", m_userManagement.addUser("testAlias2", "test", null));
 
         // regular alias
-        assertTrue("alias for testAlias1 set to:testAlias2", m_userManagement.setAlias("testAlias1",
"testAlias2"));
+        assertTrue("alias for testAlias1 set to:testAlias2", m_userManagement.setAlias("testAlias1",
"testAlias2", null));
 
         //TODO: is this correct? even primitive circular aliasing allowed!
-        assertTrue("alias for testAlias2 set to:testAlias1", m_userManagement.setAlias("testAlias2",
"testAlias1"));
+        assertTrue("alias for testAlias2 set to:testAlias1", m_userManagement.setAlias("testAlias2",
"testAlias1", null));
 
         // did first one persist?
-        assertEquals("Current alias for testAlias1 is: testAlias2", "testAlias2", m_userManagement.getAlias("testAlias1"));
+        assertEquals("Current alias for testAlias1 is: testAlias2", "testAlias2", m_userManagement.getAlias("testAlias1",
null));
 
         //TODO: is this correct? setting self as alias!
-        assertTrue("alias for testAlias1 set to:testAlias1", m_userManagement.setAlias("testAlias1",
"testAlias1"));
+        assertTrue("alias for testAlias1 set to:testAlias1", m_userManagement.setAlias("testAlias1",
"testAlias1", null));
 
-        assertTrue("user added", m_userManagement.addUser("testAlias3", "test"));
+        assertTrue("user added", m_userManagement.addUser("testAlias3", "test", null));
 
         // re-set, simply overwrites
-        assertTrue("alias for testAlias1 set to:testAlias3", m_userManagement.setAlias("testAlias1",
"testAlias3"));
+        assertTrue("alias for testAlias1 set to:testAlias3", m_userManagement.setAlias("testAlias1",
"testAlias3", null));
 
         // check overwrite
-        assertEquals("Current alias for testAlias1 is: testAlias3", "testAlias3", m_userManagement.getAlias("testAlias1"));
+        assertEquals("Current alias for testAlias1 is: testAlias3", "testAlias3", m_userManagement.getAlias("testAlias1",
null));
 
         // retreat
-        assertTrue("alias for testAlias1 unset", m_userManagement.unsetAlias("testAlias1"));
+        assertTrue("alias for testAlias1 unset", m_userManagement.unsetAlias("testAlias1",
null));
 
         // check removed alias
         //sendCommand("showalias testAlias1");
-        assertNull("User testAlias1 does not currently have an alias", m_userManagement.getAlias("testAlias1"));
+        assertNull("User testAlias1 does not currently have an alias", m_userManagement.getAlias("testAlias1",
null));
 
     }
 
@@ -160,55 +179,60 @@
 
         // do some tests when parameter users don't exist
         try {
-            m_userManagement.setForwardAddress("testNonExist1", "testForward1@locahost");
+            m_userManagement.setForwardAddress("testNonExist1", "testForward1@locahost",
null);
             fail("user unknown to server");
         } catch (UserManagementException e) {
             // success
         }
 
-        assertTrue("user added", m_userManagement.addUser("testForwardUser", "test"));
+        assertTrue("user added", m_userManagement.addUser("testForwardUser", "test", null));
 
-        assertNull("no forward set", m_userManagement.getForwardAddress("testForwardUser"));
+        assertNull("no forward set", m_userManagement.getForwardAddress("testForwardUser",
null));
 
-        assertTrue(m_userManagement.setForwardAddress("testForwardUser", "testForward1@locahost"));
+        assertTrue(m_userManagement.setForwardAddress("testForwardUser", "testForward1@locahost",
null));
 
         // did it persist?
-        String forwardAddress = m_userManagement.getForwardAddress("testForwardUser");
+        String forwardAddress = m_userManagement.getForwardAddress("testForwardUser", null);
         assertEquals("forward for testForwardUser is: testForward1@locahost", "testForward1@locahost",
forwardAddress);
 
         // re-set, simply overwrites
-        assertTrue(m_userManagement.setForwardAddress("testForwardUser", "testForward2@locahost"));
+        assertTrue(m_userManagement.setForwardAddress("testForwardUser", "testForward2@locahost",
null));
 
         // check overwrite
-        forwardAddress = m_userManagement.getForwardAddress("testForwardUser");
+        forwardAddress = m_userManagement.getForwardAddress("testForwardUser", null);
         assertEquals("forward for testForwardUser is: testForward2@locahost", "testForward2@locahost",
forwardAddress);
 
         // retreat
-        assertTrue("Forward for testForwardUser unset", m_userManagement.unsetForwardAddress("testForwardUser"));
+        assertTrue("Forward for testForwardUser unset", m_userManagement.unsetForwardAddress("testForwardUser",
null));
 
         // check removed forward
-        assertNull("no more forward set", m_userManagement.getForwardAddress("testForwardUser"));
+        assertNull("no more forward set", m_userManagement.getForwardAddress("testForwardUser",
null));
 
     }
 
-    public void testSetPassword() throws IOException, UserManagementException {
+    public void testSetPassword() throws UserManagementException {
 
-        assertTrue("user added", m_userManagement.addUser("testPwdUser", "pwd1"));
+        assertTrue("user added", m_userManagement.addUser("testPwdUser", "pwd1", null));
 
         assertTrue("initial password", m_mockUsersRepository.test("testPwdUser", "pwd1"));
 
         // set empty pwd
-        assertTrue("changed to empty password", m_userManagement.setPassword("testPwdUser",
""));
+        assertTrue("changed to empty password", m_userManagement.setPassword("testPwdUser",
"", null));
         assertTrue("password changed to empty", m_mockUsersRepository.test("testPwdUser",
""));
 
         // change pwd
-        assertTrue("changed password", m_userManagement.setPassword("testPwdUser", "pwd2"));
+        assertTrue("changed password", m_userManagement.setPassword("testPwdUser", "pwd2",
null));
         assertTrue("password not changed to pwd2", m_mockUsersRepository.test("testPwdUser",
"pwd2"));
 
         // assure case sensitivity
-        assertTrue("changed password", m_userManagement.setPassword("testPwdUser", "pWD2"));
+        assertTrue("changed password", m_userManagement.setPassword("testPwdUser", "pWD2",
null));
         assertFalse("password no longer pwd2", m_mockUsersRepository.test("testPwdUser",
"pwd2"));
         assertTrue("password changed to pWD2", m_mockUsersRepository.test("testPwdUser",
"pWD2"));
 
+    }
+    
+    public void testListRepositories() throws UserManagementException {
+        List userRepositoryNames = m_userManagement.getUserRepositoryNames();
+        assertTrue("default is there", userRepositoryNames.contains("LocalUsers"));
     }
 }

Modified: james/server/trunk/src/test/org/apache/james/test/mock/james/MockUsersStore.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/test/mock/james/MockUsersStore.java?rev=415619&r1=415618&r2=415619&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/james/MockUsersStore.java (original)
+++ james/server/trunk/src/test/org/apache/james/test/mock/james/MockUsersStore.java Tue Jun
20 05:00:57 2006
@@ -32,12 +32,13 @@
     }
 
     public UsersRepository getRepository(String name) {
+        if (!name.equals("LocalUsers")) return null;
         return m_usersRepository;
     }
 
     public Iterator getRepositoryNames() {
         ArrayList repositoryList = new ArrayList();
-        repositoryList.add(m_usersRepository);
+        repositoryList.add("LocalUsers");
         return repositoryList.iterator();
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message