james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1055589 [2/2] - in /james/server/trunk: container-spring/src/main/java/org/apache/james/container/spring/tool/ fetchmail/src/main/java/org/apache/james/fetchmail/ lmtpserver/src/main/java/org/apache/james/lmtpserver/ mailbox-adapter/src/ma...
Date Wed, 05 Jan 2011 19:22:09 GMT
Modified: james/server/trunk/user-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java?rev=1055589&r1=1055588&r2=1055589&view=diff
==============================================================================
--- james/server/trunk/user-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java
(original)
+++ james/server/trunk/user-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java
Wed Jan  5 19:22:07 2011
@@ -41,6 +41,7 @@ import org.apache.commons.logging.Log;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.lifecycle.api.LogEnabled;
 import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.api.model.User;
 
 /**
@@ -389,7 +390,7 @@ public class ReadOnlyUsersLDAPRepository
      * 
      * @see org.apache.james.api.user.UsersRepository#contains(java.lang.String)
      */
-    public boolean contains(String name) {
+    public boolean contains(String name) throws UsersRepositoryException {
         if (getUserByName(name) != null) {
             return true;
         }
@@ -403,7 +404,7 @@ public class ReadOnlyUsersLDAPRepository
      * org.apache.james.api.user.UsersRepository#containsCaseInsensitive(java
      * .lang.String)
      */
-    public boolean containsCaseInsensitive(String name) {
+    public boolean containsCaseInsensitive(String name) throws UsersRepositoryException {
         if (getUserByNameCaseInsensitive(name) != null) {
             return true;
         }
@@ -415,13 +416,14 @@ public class ReadOnlyUsersLDAPRepository
      * 
      * @see org.apache.james.api.user.UsersRepository#countUsers()
      */
-    public int countUsers() {
+    public int countUsers() throws UsersRepositoryException {
         try {
             return getValidUsers().size();
         } catch (NamingException e) {
             log.error("Unable to retrieve user count from ldap", e);
+            throw new UsersRepositoryException("Unable to retrieve user count from ldap",
e);
+
         }
-        return 0;
     }
 
     /*
@@ -430,7 +432,7 @@ public class ReadOnlyUsersLDAPRepository
      * @see
      * org.apache.james.api.user.UsersRepository#getRealName(java.lang.String)
      */
-    public String getRealName(String name) {
+    public String getRealName(String name) throws UsersRepositoryException {
         User u = getUserByNameCaseInsensitive(name);
         if (u != null) {
             return u.getUserName();
@@ -445,7 +447,7 @@ public class ReadOnlyUsersLDAPRepository
      * @see
      * org.apache.james.api.user.UsersRepository#getUserByName(java.lang.String)
      */
-    public User getUserByName(String name) {
+    public User getUserByName(String name) throws UsersRepositoryException {
         try {
             Iterator<ReadOnlyLDAPUser> userIt = buildUserCollection(getValidUsers()).iterator();
             while (userIt.hasNext()) {
@@ -457,6 +459,8 @@ public class ReadOnlyUsersLDAPRepository
 
         } catch (NamingException e) {
             log.error("Unable to retrieve user from ldap", e);
+            throw new UsersRepositoryException("Unable to retrieve user from ldap", e);
+
         }
         return null;
 
@@ -469,7 +473,7 @@ public class ReadOnlyUsersLDAPRepository
      * org.apache.james.api.user.UsersRepository#getUserByNameCaseInsensitive
      * (java.lang.String)
      */
-    public User getUserByNameCaseInsensitive(String name) {
+    public User getUserByNameCaseInsensitive(String name) throws UsersRepositoryException
{
         try {
             Iterator<ReadOnlyLDAPUser> userIt = buildUserCollection(getValidUsers()).iterator();
             while (userIt.hasNext()) {
@@ -481,6 +485,8 @@ public class ReadOnlyUsersLDAPRepository
 
         } catch (NamingException e) {
             log.error("Unable to retrieve user from ldap", e);
+            throw new UsersRepositoryException("Unable to retrieve user from ldap", e);
+
         }
         return null;
     }
@@ -490,7 +496,7 @@ public class ReadOnlyUsersLDAPRepository
      * 
      * @see org.apache.james.api.user.UsersRepository#list()
      */
-    public Iterator<String> list() {
+    public Iterator<String> list() throws UsersRepositoryException {
         List<String> result = new ArrayList<String>();
         try {
 
@@ -500,7 +506,7 @@ public class ReadOnlyUsersLDAPRepository
                 result.add(userIt.next().getUserName());
             }
         } catch (NamingException namingException) {
-            throw new RuntimeException("Unable to retrieve users list from LDAP due to unknown
naming error.", namingException);
+            throw new UsersRepositoryException("Unable to retrieve users list from LDAP due
to unknown naming error.", namingException);
         }
 
         return result.iterator();
@@ -533,8 +539,10 @@ public class ReadOnlyUsersLDAPRepository
      * @see
      * org.apache.james.api.user.UsersRepository#removeUser(java.lang.String)
      */
-    public void removeUser(String name) {
+    public void removeUser(String name) throws UsersRepositoryException {
         log.warn("This user-repository is read-only. Modifications are not permitted.");
+        throw new UsersRepositoryException("This user-repository is read-only. Modifications
are not permitted.");
+
     }
 
     /*
@@ -543,7 +551,7 @@ public class ReadOnlyUsersLDAPRepository
      * @see org.apache.james.api.user.UsersRepository#test(java.lang.String,
      * java.lang.String)
      */
-    public boolean test(String name, String password) {
+    public boolean test(String name, String password) throws UsersRepositoryException {
         User u = getUserByName(name);
         if (u != null) {
             return u.verifyPassword(password);
@@ -551,27 +559,6 @@ public class ReadOnlyUsersLDAPRepository
         return false;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.api.user.UsersRepository#addUser(org.apache.james.api
-     * .user.User)
-     */
-    public boolean addUser(User user) {
-        log.warn("This user-repository is read-only. Modifications are not permitted.");
-        return false;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.james.api.user.UsersRepository#addUser(java.lang.String,
-     * java.lang.Object)
-     */
-    public void addUser(String name, Object attributes) {
-        log.warn("This user-repository is read-only. Modifications are not permitted.");
-    }
 
     /*
      * (non-Javadoc)
@@ -579,9 +566,9 @@ public class ReadOnlyUsersLDAPRepository
      * @see org.apache.james.api.user.UsersRepository#addUser(java.lang.String,
      * java.lang.String)
      */
-    public boolean addUser(String username, String password) {
+    public void addUser(String username, String password) throws UsersRepositoryException
{
         log.warn("This user-repository is read-only. Modifications are not permitted.");
-        return false;
+        throw new UsersRepositoryException("This user-repository is read-only. Modifications
are not permitted.");
     }
 
     /*
@@ -591,9 +578,9 @@ public class ReadOnlyUsersLDAPRepository
      * org.apache.james.api.user.UsersRepository#updateUser(org.apache.james
      * .api.user.User)
      */
-    public boolean updateUser(User user) {
+    public void updateUser(User user) throws UsersRepositoryException {
         log.warn("This user-repository is read-only. Modifications are not permitted.");
-        return false;
+        throw new UsersRepositoryException("This user-repository is read-only. Modifications
are not permitted.");
     }
 
     /*
@@ -610,7 +597,7 @@ public class ReadOnlyUsersLDAPRepository
     /**
      * VirtualHosting not supported
      */
-    public boolean supportVirtualHosting() {
+    public boolean supportVirtualHosting() throws UsersRepositoryException{
         return false;
     }
 

Modified: james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java?rev=1055589&r1=1055588&r2=1055589&view=diff
==============================================================================
--- james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
(original)
+++ james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
Wed Jan  5 19:22:07 2011
@@ -25,6 +25,7 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.user.api.JamesUsersRepository;
 import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.api.model.JamesUser;
 import org.apache.james.user.api.model.User;
 import org.apache.james.user.lib.model.DefaultJamesUser;
@@ -81,7 +82,7 @@ public abstract class AbstractJamesUsers
      * @param user
      *            the user to add
      */
-    protected abstract void doAddUser(User user);
+    protected abstract void doAddUser(User user) throws UsersRepositoryException;
 
     /**
      * Updates a user record to match the supplied User.
@@ -89,7 +90,7 @@ public abstract class AbstractJamesUsers
      * @param user
      *            the user to update
      */
-    protected abstract void doUpdateUser(User user);
+    protected abstract void doUpdateUser(User user) throws UsersRepositoryException;
 
 
 
@@ -98,11 +99,10 @@ public abstract class AbstractJamesUsers
      * (non-Javadoc)
      * @see org.apache.james.user.lib.AbstractUsersRepository#doAddUser(java.lang.String,
java.lang.String)
      */
-    protected boolean doAddUser(String username, String password) {
+    protected void doAddUser(String username, String password) throws UsersRepositoryException{
         User newbie = new DefaultJamesUser(username, "SHA");
         newbie.setPassword(password);
         doAddUser(newbie);
-        return true;
     }
 
     /**
@@ -113,51 +113,50 @@ public abstract class AbstractJamesUsers
      *            the user to be updated
      * 
      * @return true if successful.
+     * @throws UsersRepositoryException 
      */
-    public boolean updateUser(User user) {
+    public void updateUser(User user) throws UsersRepositoryException {
         // Return false if it's not found.
         if (!contains(user.getUserName())) {
-            return false;
+            throw new UsersRepositoryException("User " + user.getUserName() + " does not
exist");
         } else {
             doUpdateUser(user);
-            return true;
         }
     }
 
     /**
+     * @throws VirtualUserTableException 
      * @see org.apache.james.vut.api.VirtualUserTable#getMappings(java.lang.String,
      *      java.lang.String)
      */
     public Collection<String> getMappings(String username, String domain)
-            throws ErrorMappingException {
+            throws ErrorMappingException, VirtualUserTableException {
         Collection<String> mappings = new ArrayList<String>();
-        User user = getUserByName(username);
+        try {
+            User user = getUserByName(username);
 
-        if (user instanceof JamesUser) {
-            JamesUser jUser = (JamesUser) user;
+            if (user instanceof JamesUser) {
+                JamesUser jUser = (JamesUser) user;
 
-            if (enableAliases && jUser.getAliasing()) {
-                String alias = jUser.getAlias();
-                if (alias != null) {
-                    mappings.add(alias + "@" + domain);
+                if (enableAliases && jUser.getAliasing()) {
+                    String alias = jUser.getAlias();
+                    if (alias != null) {
+                        mappings.add(alias + "@" + domain);
+                    }
                 }
-            }
 
-            if (enableForwarding && jUser.getForwarding()) {
-                String forward = null;
-                if (jUser.getForwardingDestination() != null
-                        && ((forward = jUser.getForwardingDestination()
-                                .toString()) != null)) {
-                    mappings.add(forward);
-                } else {
-                    StringBuffer errorBuffer = new StringBuffer(128)
-                            .append("Forwarding was enabled for ")
-                            .append(username)
-                            .append(
-                                    " but no forwarding address was set for this account.");
-                    getLogger().error(errorBuffer.toString());
+                if (enableForwarding && jUser.getForwarding()) {
+                    String forward = null;
+                    if (jUser.getForwardingDestination() != null && ((forward = jUser.getForwardingDestination().toString())
!= null)) {
+                        mappings.add(forward);
+                    } else {
+                        StringBuffer errorBuffer = new StringBuffer(128).append("Forwarding
was enabled for ").append(username).append(" but no forwarding address was set for this account.");
+                        getLogger().error(errorBuffer.toString());
+                    }
                 }
             }
+        } catch (UsersRepositoryException e) {
+            throw new VirtualUserTableException("Unable to lookup forwards/aliases", e);
         }
         if (mappings.size() == 0) {
             return null;
@@ -195,25 +194,29 @@ public abstract class AbstractJamesUsers
     public Map<String, Collection<String>> getAllMappings() throws VirtualUserTableException{
         Map<String, Collection<String>> mappings = new HashMap<String, Collection<String>>();
         if (enableAliases == true || enableForwarding == true) {
-            Iterator<String> users = list();
-            while(users.hasNext()) {
-                String user = users.next();
-                int index = user.indexOf("@");
-                String username;
-                String domain;
-                if (index != -1) {
-                    username = user.substring(0, index);
-                    domain = user.substring(index +1, user.length());
-                } else {
-                    username = user;
-                    domain = "localhost";
-                }
-                try {
-                    mappings.put(user, getMappings(username, domain));
-                } catch (ErrorMappingException e) {
-                    // shold never happen here
+            try {
+                Iterator<String> users = list();
+                while (users.hasNext()) {
+                    String user = users.next();
+                    int index = user.indexOf("@");
+                    String username;
+                    String domain;
+                    if (index != -1) {
+                        username = user.substring(0, index);
+                        domain = user.substring(index + 1, user.length());
+                    } else {
+                        username = user;
+                        domain = "localhost";
+                    }
+                    try {
+                        mappings.put(user, getMappings(username, domain));
+                    } catch (ErrorMappingException e) {
+                        // shold never happen here
+                    }
                 }
-            }        
+            } catch (UsersRepositoryException e) {
+                throw new VirtualUserTableException("Unable to access forwards/aliases",
e);
+            }
         }
        
         return mappings;
@@ -247,7 +250,7 @@ public abstract class AbstractJamesUsers
     }
 
     public void addErrorMapping(String user, String domain, String error) throws VirtualUserTableException
{
-        // TODO Auto-generated method stub
+        throw new VirtualUserTableException("Read-Only VirtualUserTable");        
         
     }
 

Modified: james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/AbstractUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/AbstractUsersRepository.java?rev=1055589&r1=1055588&r2=1055589&view=diff
==============================================================================
--- james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/AbstractUsersRepository.java
(original)
+++ james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/AbstractUsersRepository.java
Wed Jan  5 19:22:07 2011
@@ -30,6 +30,7 @@ import org.apache.james.domainlist.api.D
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.lifecycle.api.LogEnabled;
 import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.api.UsersRepositoryException;
 
 public abstract class AbstractUsersRepository implements UsersRepository, LogEnabled, Configurable{
 
@@ -76,27 +77,30 @@ public abstract class AbstractUsersRepos
         this.domainList = domainList;
     }
     
-    protected boolean isValidUsername(String username) throws DomainListException {
+    protected void isValidUsername(String username) throws  UsersRepositoryException {
         int i = username.indexOf("@");
         if (supportVirtualHosting()) {
             // need a @ in the username
             if (i == -1) {
-                return false;
+                throw new UsersRepositoryException("Given Username needs to contain a @domainpart");
             } else {
                 String domain = username.substring(i + 1);
-                if (domainList.containsDomain(domain) == false) {
-                    return false;
-                } else {
-                    return true;
+                try {
+                    if (domainList.containsDomain(domain) == false) {
+                        throw new UsersRepositoryException("Domain does not exist in DomainList");
+                    } else {
+                        return;
+                    }
+                } catch (DomainListException e) {
+                    throw new UsersRepositoryException("Unable to query DomainList", e);
                 }
             }
         } else {
             // @ only allowed when virtualhosting is supported
             if (i != -1) {
-                return false;
+                throw new UsersRepositoryException("Given Username contains a @domainpart
but virtualhosting support is disabled");
             }
         }
-        return true;
     }
 
 
@@ -104,24 +108,22 @@ public abstract class AbstractUsersRepos
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepository#addUser(java.lang.String, java.lang.String)
      */
-    public boolean addUser(String username, String password) {
-        
-        try {
-            if (contains(username) == false && isValidUsername(username)) {
-                return doAddUser(username, password);
-            }
-        } catch (DomainListException e) {
-            logger.error("Unable to access DomainList" ,e);
-            return false;
+    public void addUser(String username, String password) throws UsersRepositoryException
{
+
+        if (contains(username) == false) {
+            isValidUsername(username);
+            doAddUser(username, password);
+        } else {
+            throw new UsersRepositoryException("User with username " + username + " already
exist!");
         }
-        return false;
+
     }
 
     /*
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepository#supportVirtualHosting()
      */
-    public boolean supportVirtualHosting() {
+    public boolean supportVirtualHosting() throws UsersRepositoryException{
         return virtualHosting;
     }
     
@@ -132,5 +134,5 @@ public abstract class AbstractUsersRepos
      * @param password
      * @return successful
      */
-    protected abstract boolean doAddUser(String username, String password);
+    protected abstract void doAddUser(String username, String password) throws UsersRepositoryException;
 }

Modified: james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/UsersRepositoryManagement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/UsersRepositoryManagement.java?rev=1055589&r1=1055588&r2=1055589&view=diff
==============================================================================
--- james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/UsersRepositoryManagement.java
(original)
+++ james/server/trunk/user-library/src/main/java/org/apache/james/user/lib/UsersRepositoryManagement.java
Wed Jan  5 19:22:07 2011
@@ -30,6 +30,7 @@ import javax.annotation.Resource;
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
 
+import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.api.UsersRepositoryManagementMBean;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.model.JamesUser;
@@ -53,7 +54,7 @@ public class UsersRepositoryManagement e
     }
 
 
-    private JamesUser getJamesUser(String userName) {
+    private JamesUser getJamesUser(String userName) throws UsersRepositoryException {
         User baseuser = localUsers.getUserByName(userName);
         if (baseuser == null) throw new IllegalArgumentException("user not found: " + userName);
         if (! (baseuser instanceof JamesUser ) ) throw new IllegalArgumentException("user
is not of type JamesUser: " + userName);
@@ -66,18 +67,16 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#addUser(java.lang.String,
java.lang.String)
      */
-    public boolean addUser(String userName, String password) {
-        return localUsers.addUser(userName, password);
+    public void addUser(String userName, String password) throws UsersRepositoryException
{
+        localUsers.addUser(userName, password);
     }
 
     /*
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#deleteUser(java.lang.String)
      */
-    public boolean deleteUser(String userName) {
-        if (!localUsers.contains(userName)) return false;
+    public void deleteUser(String userName) throws UsersRepositoryException {
         localUsers.removeUser(userName);
-        return true;
     }
 
 
@@ -85,7 +84,7 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#verifyExists(java.lang.String)
      */
-    public boolean verifyExists(String userName) {
+    public boolean verifyExists(String userName) throws UsersRepositoryException {
         return localUsers.contains(userName);
     }
 
@@ -94,7 +93,7 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#countUsers()
      */
-    public long countUsers() {
+    public long countUsers() throws UsersRepositoryException {
         return localUsers.countUsers();
     }
 
@@ -104,7 +103,7 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#listAllUsers()
      */
-    public String[] listAllUsers() {
+    public String[] listAllUsers() throws UsersRepositoryException {
         List<String> userNames = new ArrayList<String>();
         for (Iterator<String> it = localUsers.list(); it.hasNext();) {
             userNames.add(it.next());
@@ -118,10 +117,13 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#setPassword(java.lang.String,
java.lang.String)
      */
-    public boolean setPassword(String userName, String password) {
+    public void setPassword(String userName, String password) throws UsersRepositoryException
{
         User user = localUsers.getUserByName(userName);
-        if (user == null) throw new IllegalArgumentException("user not found: " + userName);
-        return user.setPassword(password);
+        if (user == null) throw new UsersRepositoryException("user not found: " + userName);
+        if (user.setPassword(password) == false) {
+            throw new UsersRepositoryException("Unable to update password for user " + user);
+        }
+        localUsers.updateUser(user);
     }
 
 
@@ -129,13 +131,12 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#unsetAlias(java.lang.String)
      */
-    public boolean unsetAlias(String userName) {
+    public void unsetAlias(String userName) throws UsersRepositoryException {
         JamesUser user = getJamesUser(userName);
-        if (!user.getAliasing()) return false;
+        if (!user.getAliasing()) throw new UsersRepositoryException("User " + user + " is
no alias");
         
         user.setAliasing(false);
         localUsers.updateUser(user);
-        return true;
     }
 
 
@@ -143,7 +144,7 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#getAlias(java.lang.String)
      */
-    public String getAlias(String userName) {
+    public String getAlias(String userName) throws UsersRepositoryException {
         JamesUser user = getJamesUser(userName);
         if (!user.getAliasing()) return null;
         return user.getAlias();
@@ -154,14 +155,13 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#unsetForwardAddress(java.lang.String)
      */
-    public boolean unsetForwardAddress(String userName) {
+    public void unsetForwardAddress(String userName) throws UsersRepositoryException {
         JamesUser user = getJamesUser(userName);
 
-        if (!user.getForwarding()) return false;
+        if (!user.getForwarding()) throw new UsersRepositoryException("User " + user + "
is no forward");
         
         user.setForwarding(false);
         localUsers.updateUser(user);
-        return true;
     }
 
 
@@ -169,7 +169,7 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#getForwardAddress(java.lang.String)
      */
-    public String getForwardAddress(String userName) {
+    public String getForwardAddress(String userName) throws UsersRepositoryException {
         JamesUser user = getJamesUser(userName);
         if (!user.getForwarding()) return null;
         return user.getForwardingDestination().toString();
@@ -179,7 +179,7 @@ public class UsersRepositoryManagement e
      * (non-Javadoc)
      * @see org.apache.james.user.api.UsersRepositoryManagementMBean#getVirtualHostingEnabled()
      */
-    public boolean getVirtualHostingEnabled() {
+    public boolean getVirtualHostingEnabled() throws UsersRepositoryException {
         return localUsers.supportVirtualHosting();
     }
 

Modified: james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java?rev=1055589&r1=1055588&r2=1055589&view=diff
==============================================================================
--- james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
(original)
+++ james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
Wed Jan  5 19:22:07 2011
@@ -26,6 +26,7 @@ import junit.framework.TestCase;
 
 import org.apache.james.lifecycle.api.LifecycleUtil;
 import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.api.model.User;
 
 /**
@@ -46,30 +47,33 @@ public abstract class AbstractUsersRepos
      */
     protected abstract UsersRepository getUsersRepository() throws Exception;
 
-    public void testUsersRepositoryEmpty() {
+    public void testUsersRepositoryEmpty() throws UsersRepositoryException {
         assertEquals("users repository not empty", 0, usersRepository.countUsers());
         assertFalse("users repository not empty", usersRepository.list().hasNext());
     }
-    
-    public void testAddUserOnce() {
-        boolean res = usersRepository.addUser("username", "password");
-        assertTrue("User not added", res);
-        res = usersRepository.addUser("username", "password2");
-        assertFalse("User added twice!", res);
+
+    public void testAddUserOnce() throws UsersRepositoryException {
+        usersRepository.addUser("username", "password");
+        try {
+            usersRepository.addUser("username", "password2");
+            fail("User added twice!");
+
+        } catch (UsersRepositoryException e) {
+
+        }
         try {
             usersRepository.addUser("username2", "password2");
             assertTrue(usersRepository.contains("username2"));
             usersRepository.addUser("username3", "password3");
             assertTrue(usersRepository.contains("username3"));
         } catch (UnsupportedOperationException e) {
-            
+
         }
-        
+
     }
-    
-    public void testUserAddedIsFound() {
-        boolean res = usersRepository.addUser("username", "password");
-        assertTrue("User not added", res);
+
+    public void testUserAddedIsFound() throws UsersRepositoryException {
+        usersRepository.addUser("username", "password");
         User user = usersRepository.getUserByName("username");
         assertNotNull(user);
         assertEquals("username does not match", user.getUserName(), "username");
@@ -78,20 +82,19 @@ public abstract class AbstractUsersRepos
         User u = usersRepository.getUserByName("uSERNAMe");
         assertNull("found the user searching for a different case!", u);
         
-        String realname = usersRepository.getRealName("uSERNAMe");
-        assertNull("name is not null", realname);
+        //String realname = usersRepository.getRealName("uSERNAMe");
+        //assertNull("name is not null", realname);
         // assertEquals("name is different", "username", realname);
     }
     
-    public void testUserListing() {
+    public void testUserListing() throws UsersRepositoryException {
         ArrayList<String> keys = new ArrayList<String>(3);
         keys.add("username1");
         keys.add("username2");
         keys.add("username3");
         for (Iterator<String> i = keys.iterator(); i.hasNext(); ) {
             String username = i.next();
-            boolean res = usersRepository.addUser(username, username);
-            assertTrue("User "+username+" not added", res);
+             usersRepository.addUser(username, username);
         }
         assertEquals("Wrong number of users found", keys.size(), usersRepository.countUsers());
 
@@ -103,7 +106,7 @@ public abstract class AbstractUsersRepos
                 assertTrue(usersRepository.test(username, username));
                 User u = usersRepository.getUserByName(username);
                 u.setPassword("newpass");
-                assertTrue(usersRepository.updateUser(u));
+                usersRepository.updateUser(u);
             }
             assertTrue(check.contains(username));
             check.remove(username);
@@ -111,8 +114,8 @@ public abstract class AbstractUsersRepos
         assertEquals("Some user has not be found", 0, check.size());
     }
     
-    public void testUserPassword() {
-        assertTrue("user not added", usersRepository.addUser("username","password"));
+    public void testUserPassword() throws UsersRepositoryException {
+        usersRepository.addUser("username","password");
         assertEquals("didn't accept the correct password ", usersRepository.test("username",
"password"), getPasswordsEnabled());
         assertFalse("accepted the wrong password #1", usersRepository.test("username", "password2"));
         assertFalse("accepted the wrong password #2", usersRepository.test("username2", "password"));
@@ -125,7 +128,7 @@ public abstract class AbstractUsersRepos
         return true;
     }
 
-    public void testUserAddRemoveCycle() {
+    public void testUserAddRemoveCycle() throws UsersRepositoryException {
         assertFalse("accepted login when no user existed", usersRepository.test("username",
"password"));
         try {
             usersRepository.removeUser("username");
@@ -134,12 +137,12 @@ public abstract class AbstractUsersRepos
         } catch (Exception e) {
             e.printStackTrace();
         }
-        assertTrue("user not added", usersRepository.addUser("username","password"));
+        usersRepository.addUser("username","password");
         assertEquals("didn't accept the correct password", usersRepository.test("username",
"password"),getPasswordsEnabled());
         User user = usersRepository.getUserByName("username");
         user.setPassword("newpass");
         try {
-            assertTrue("user not updated", usersRepository.updateUser(user));
+            usersRepository.updateUser(user);
             assertEquals("new password accepted", usersRepository.test("username", "newpass"),
getPasswordsEnabled());
             assertFalse("old password rejected", usersRepository.test("username", "password"));
         } catch (UnsupportedOperationException e) {
@@ -154,7 +157,12 @@ public abstract class AbstractUsersRepos
         }
         assertFalse("user not existing", usersRepository.contains("username"));
         assertFalse("new password rejected", usersRepository.test("username", "newpass"));
-        assertFalse("updated a non existing user: should fail!", usersRepository.updateUser(user));
+        try {
+            usersRepository.updateUser(user);
+            fail();
+        } catch (UsersRepositoryException e) {
+            
+        }
     }
     
     
@@ -192,8 +200,9 @@ public abstract class AbstractUsersRepos
 
     /**
      * Dispose the repository
+     * @throws UsersRepositoryException 
      */
-    protected void disposeUsersRepository() {
+    protected void disposeUsersRepository() throws UsersRepositoryException {
         if (usersRepository != null) {
             LifecycleUtil.dispose(this.usersRepository);
         }

Modified: james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/UsersRepositoryManagementTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/UsersRepositoryManagementTest.java?rev=1055589&r1=1055588&r2=1055589&view=diff
==============================================================================
--- james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/UsersRepositoryManagementTest.java
(original)
+++ james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/UsersRepositoryManagementTest.java
Wed Jan  5 19:22:07 2011
@@ -26,6 +26,7 @@ import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.lib.UsersRepositoryManagement;
 import org.apache.james.user.lib.mock.MockUsersRepository;
 
@@ -46,7 +47,7 @@ public class UsersRepositoryManagementTe
 
    
 
-    public void testUserCount() {
+    public void testUserCount() throws UsersRepositoryException {
         assertEquals("no user yet", 0, m_userManagement.countUsers());
         m_mockUsersRepository.addUser("testCount1", "testCount");
         assertEquals("1 user", 1, m_userManagement.countUsers());
@@ -58,30 +59,30 @@ public class UsersRepositoryManagementTe
 
 
 
-    public void testAddUserAndVerify() {
-        assertTrue("user added", m_mockUsersRepository.addUser("testCount1", "testCount"));
+    public void testAddUserAndVerify() throws UsersRepositoryException {
+        m_mockUsersRepository.addUser("testCount1", "testCount");
         assertFalse("user not there", m_userManagement.verifyExists("testNotAdded"));
         assertTrue("user is there", m_userManagement.verifyExists("testCount1"));
         m_mockUsersRepository.removeUser("testCount1");
         assertFalse("user not there", m_userManagement.verifyExists("testCount1"));
     }
 
-    public void testDelUser() {
-        assertTrue("user added", m_mockUsersRepository.addUser("testDel", "test"));
+    public void testDelUser() throws UsersRepositoryException {
+        m_mockUsersRepository.addUser("testDel", "test");
         assertFalse("user not there", m_userManagement.verifyExists("testNotDeletable"));
         assertTrue("user is there", m_userManagement.verifyExists("testDel"));
         m_mockUsersRepository.removeUser("testDel");
         assertFalse("user no longer there", m_userManagement.verifyExists("testDel"));
     }
 
-    public void testListUsers() {
+    public void testListUsers() throws UsersRepositoryException {
 
         String[] usersArray = new String[] {"ccc", "aaa", "dddd", "bbbbb"};
         List<String> users = Arrays.asList(usersArray);
 
         for (int i = 0; i < users.size(); i++) {
             String user = users.get(i);
-            assertTrue("user added", m_mockUsersRepository.addUser(user, "test"));
+            m_mockUsersRepository.addUser(user, "test");
         }
 
         String[] userNames = m_userManagement.listAllUsers();
@@ -94,22 +95,22 @@ public class UsersRepositoryManagementTe
     }
 
     
-    public void testSetPassword() {
+    public void testSetPassword() throws UsersRepositoryException {
 
-        assertTrue("user added", m_userManagement.addUser("testPwdUser", "pwd1"));
+        m_userManagement.addUser("testPwdUser", "pwd1");
 
         assertTrue("initial password", m_mockUsersRepository.test("testPwdUser", "pwd1"));
 
         // set empty pwd
-        assertTrue("changed to empty password", m_userManagement.setPassword("testPwdUser",
""));
+        m_userManagement.setPassword("testPwdUser", "");
         assertTrue("password changed to empty", m_mockUsersRepository.test("testPwdUser",
""));
 
         // change pwd
-        assertTrue("changed password", m_userManagement.setPassword("testPwdUser", "pwd2"));
+        m_userManagement.setPassword("testPwdUser", "pwd2");
         assertTrue("password not changed to pwd2", m_mockUsersRepository.test("testPwdUser",
"pwd2"));
 
         // assure case sensitivity
-        assertTrue("changed password", m_userManagement.setPassword("testPwdUser", "pWD2"));
+        m_userManagement.setPassword("testPwdUser", "pWD2");
         assertFalse("password no longer pwd2", m_mockUsersRepository.test("testPwdUser",
"pwd2"));
         assertTrue("password changed to pWD2", m_mockUsersRepository.test("testPwdUser",
"pWD2"));
 

Modified: james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/mock/MockUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/mock/MockUsersRepository.java?rev=1055589&r1=1055588&r2=1055589&view=diff
==============================================================================
--- james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/mock/MockUsersRepository.java
(original)
+++ james/server/trunk/user-library/src/test/java/org/apache/james/user/lib/mock/MockUsersRepository.java
Wed Jan  5 19:22:07 2011
@@ -19,19 +19,18 @@
 
 package org.apache.james.user.lib.mock;
 
-import org.apache.james.user.api.model.User;
-import org.apache.james.user.lib.AbstractJamesUsersRepository;
-import org.apache.james.user.lib.model.DefaultJamesUser;
-import org.apache.james.user.lib.model.DefaultUser;
-import org.apache.james.user.lib.util.DigestUtil;
-
-import java.security.NoSuchAlgorithmException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 
+import org.apache.james.user.api.UsersRepositoryException;
+import org.apache.james.user.api.model.User;
+import org.apache.james.user.lib.AbstractJamesUsersRepository;
+import org.apache.james.user.lib.model.DefaultJamesUser;
+import org.apache.james.user.lib.model.DefaultUser;
+
 public class MockUsersRepository extends AbstractJamesUsersRepository {
 
     private final HashMap<String,User> m_users = new HashMap<String,User>();
@@ -48,67 +47,10 @@ public class MockUsersRepository extends
         m_forceUseJamesUser = true;
     }
 
-    public boolean addUser(User user) {
-
-        if (m_forceUseJamesUser && user instanceof DefaultUser ) {
-            DefaultUser aUser = (DefaultUser)user;
-            user = new DefaultJamesUser(aUser.getUserName(),
-                                             aUser.getHashedPassword(),
-                                             aUser.getHashAlgorithm());
-        }
-
-        String key = user.getUserName();
-        if (m_users.containsKey(key)) return false;
-        m_users.put(key, user);
-        return true;
-    }
-
-    public void addUser(String name, Object attributes) {
-        if (!(attributes instanceof String)) {
-            throw new IllegalArgumentException();
-        }
-        try {
-            String passwordHash = DigestUtil.digestString(((String) attributes), "SHA");
-
-            User user;
-
-            if (m_forceUseJamesUser) {
-                user = new DefaultJamesUser(name, passwordHash, "SHA");
-            } else {
-                user = new DefaultUser(name, passwordHash, "SHA");
-            }
-           
-            addUser(user);
-        } catch (Exception e) {
-            e.printStackTrace();  // encoding failed
-        }
-    }
-
-    public boolean addUser(String username, String password) {
-        if (m_users.containsKey(username)) return false;
-        try {
-            String passwordHash = DigestUtil.digestString((password), "SHA");
+ 
 
-            User user;
-
-            if (m_forceUseJamesUser) {
-                user = new DefaultJamesUser(username, passwordHash, "SHA");
-            } else {
-                user = new DefaultUser(username, passwordHash, "SHA");
-            }
-           
-            return addUser(user);
-        } catch (NoSuchAlgorithmException e) {
-            e.printStackTrace();  // encoding failed
-        }
-        return false;
-    }
-
-    public Object getAttributes(String name) {
-        return null;  // trivial implementation
-    }
 
-    public User getUserByName(String name) {
+    public User getUserByName(String name) throws UsersRepositoryException{
         if (ignoreCase) {
             return getUserByNameCaseInsensitive(name);
         } else {
@@ -116,11 +58,11 @@ public class MockUsersRepository extends
         }
     }
 
-    public User getUserByNameCaseInsensitive(String name) {
+    public User getUserByNameCaseInsensitive(String name)throws UsersRepositoryException
{
         return (User) m_users.get(name.toLowerCase(Locale.US));
     }
 
-    public String getRealName(String name) {
+    public String getRealName(String name) throws UsersRepositoryException{
         if (ignoreCase) {
             return m_users.get(name.toLowerCase(Locale.US)) != null ? ((User) m_users.get(name.toLowerCase(Locale.US))).getUserName()
: null;
         } else {
@@ -128,18 +70,16 @@ public class MockUsersRepository extends
         }
     }
 
-    public boolean updateUser(User user) {
-        if (m_users.containsKey(user.getUserName())) {
-            m_users.put(user.getUserName(), user);
-            return true;
-        } else return false;  // trivial implementation
-    }
 
-    public void removeUser(String name) {
-        m_users.remove(name);
+    public void removeUser(String name) throws UsersRepositoryException{
+       if ( m_users.containsKey(name) == false) {
+           throw new UsersRepositoryException("No such user");
+       } else {
+           m_users.remove(name);
+       }
     }
 
-    public boolean contains(String name) {
+    public boolean contains(String name) throws UsersRepositoryException {
         if (ignoreCase) {
             return containsCaseInsensitive(name);
         } else {
@@ -151,17 +91,14 @@ public class MockUsersRepository extends
         throw new UnsupportedOperationException("mock");
     }
 
-    public boolean test(String name, Object attributes) {
-        throw new UnsupportedOperationException("mock");
-    }
 
-    public boolean test(String name, String password) {
+    public boolean test(String name, String password) throws UsersRepositoryException{
         User user = getUserByName(name);
         if (user == null) return false;
         return user.verifyPassword(password);
     }
 
-    public int countUsers() {
+    public int countUsers() throws UsersRepositoryException{
         return m_users.size();
     }
 
@@ -175,21 +112,28 @@ public class MockUsersRepository extends
 
         return userNames;
     }
-    public Iterator<String> list() {
+    public Iterator<String> list() throws UsersRepositoryException{
         return listUserNames().iterator(); 
     }
 
-    protected void doAddUser(User user) {
-        // unused
-    }
+    protected void doAddUser(User user)  throws UsersRepositoryException{
+        if (m_forceUseJamesUser && user instanceof DefaultUser ) {
+            DefaultUser aUser = (DefaultUser)user;
+            user = new DefaultJamesUser(aUser.getUserName(),
+                                             aUser.getHashedPassword(),
+                                             aUser.getHashAlgorithm());
+        }
 
-    protected void doUpdateUser(User user) {
-        // unused
+        String key = user.getUserName();
+        m_users.put(key, user);
     }
 
-    @Override
-    protected boolean doAddUser(String username, String password) {
-        // TODO Auto-generated method stub
-        return false;
+    protected void doUpdateUser(User user) throws UsersRepositoryException{
+        if (m_users.containsKey(user.getUserName())) {
+            m_users.put(user.getUserName(), user);
+        } else {
+            throw new UsersRepositoryException("No such user");
+        }
     }
+
 }



---------------------------------------------------------------------
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