james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [14/24] james-project git commit: JAMES-2366 UsersRepository should be case insensitive for domain part
Date Fri, 06 Apr 2018 13:20:33 GMT
JAMES-2366 UsersRepository should be case insensitive for domain part


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

Branch: refs/heads/master
Commit: 3e97f941634e108229214d3fe678f08c3e214feb
Parents: ce6e83d
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Wed Apr 4 13:53:46 2018 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Fri Apr 6 15:04:48 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/james/user/api/model/User.java    |  7 +++++++
 .../user/cassandra/CassandraUsersRepository.java      |  2 +-
 .../james/user/file/UsersFileRepositoryTest.java      |  5 +++++
 .../user/jdbc/DefaultUsersJdbcRepositoryTest.java     |  6 ++++++
 .../james/user/jdbc/JamesUsersJdbcRepositoryTest.java |  6 ++++++
 .../james/user/lib/AbstractUsersRepositoryTest.java   | 14 ++++++++++++++
 .../james/user/memory/MemoryUsersRepository.java      |  2 +-
 7 files changed, 40 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3e97f941/server/data/data-api/src/main/java/org/apache/james/user/api/model/User.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/user/api/model/User.java
b/server/data/data-api/src/main/java/org/apache/james/user/api/model/User.java
index 51d7450..fe92c3e 100644
--- a/server/data/data-api/src/main/java/org/apache/james/user/api/model/User.java
+++ b/server/data/data-api/src/main/java/org/apache/james/user/api/model/User.java
@@ -49,4 +49,11 @@ public interface User {
      * @return true if newPass successfully added
      */
     boolean setPassword(String newPass);
+
+    default boolean hasUsername(String username) {
+        org.apache.james.core.User thisUser = org.apache.james.core.User.fromUsername(getUserName());
+        org.apache.james.core.User thatUser = org.apache.james.core.User.fromUsername(username);
+
+        return thisUser.equals(thatUser);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3e97f941/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
b/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
index 3a49f9f..45504ab 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java
@@ -123,7 +123,7 @@ public class CassandraUsersRepository extends AbstractUsersRepository
{
             .join();
         return Optional.ofNullable(result.one())
             .map(row -> new DefaultUser(row.getString(REALNAME), row.getString(PASSWORD),
row.getString(ALGORITHM)))
-            .filter(user -> user.getUserName().equals(name))
+            .filter(user -> user.hasUsername(name))
             .orElse(null);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/3e97f941/server/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java
b/server/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java
index a2826cf..9de69af 100644
--- a/server/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java
+++ b/server/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java
@@ -111,4 +111,9 @@ public class UsersFileRepositoryTest extends AbstractUsersRepositoryTest
{
             LifecycleUtil.dispose(this.usersRepository);
         }
     }
+
+    @Ignore
+    @Override
+    public void testShouldReturnTrueWhenAUserHasACorrectPasswordAndOtherCaseInDomain() throws
Exception {
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3e97f941/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/DefaultUsersJdbcRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/DefaultUsersJdbcRepositoryTest.java
b/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/DefaultUsersJdbcRepositoryTest.java
index 6d4bbb3..be785fe 100644
--- a/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/DefaultUsersJdbcRepositoryTest.java
+++ b/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/DefaultUsersJdbcRepositoryTest.java
@@ -32,6 +32,7 @@ import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.lib.AbstractUsersRepository;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 
 /**
  * Test basic behaviors of UsersFileRepository
@@ -97,4 +98,9 @@ public class DefaultUsersJdbcRepositoryTest extends AbstractUsersJdbcRepositoryT
         LifecycleUtil.dispose(this.usersRepository);
     }
 
+    @Ignore
+    @Override
+    public void testShouldReturnTrueWhenAUserHasACorrectPasswordAndOtherCaseInDomain() throws
Exception {
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3e97f941/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/JamesUsersJdbcRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/JamesUsersJdbcRepositoryTest.java
b/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/JamesUsersJdbcRepositoryTest.java
index a1f8e89..66e9fd4 100644
--- a/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/JamesUsersJdbcRepositoryTest.java
+++ b/server/data/data-jdbc/src/test/java/org/apache/james/user/jdbc/JamesUsersJdbcRepositoryTest.java
@@ -32,6 +32,7 @@ import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.lib.AbstractUsersRepository;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 
 /**
  * Test basic behaviors of UsersFileRepository
@@ -96,4 +97,9 @@ public class JamesUsersJdbcRepositoryTest extends AbstractUsersJdbcRepositoryTes
         LifecycleUtil.dispose(this.usersRepository);
     }
 
+    @Ignore
+    @Override
+    public void testShouldReturnTrueWhenAUserHasACorrectPasswordAndOtherCaseInDomain() throws
Exception {
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3e97f941/server/data/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
b/server/data/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
index 83b1bbc..760c96d 100644
--- a/server/data/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
@@ -194,6 +194,20 @@ public abstract class AbstractUsersRepositoryTest {
     }
     
     @Test
+    public void testShouldReturnTrueWhenAUserHasACorrectPasswordAndOtherCaseInDomain() throws
Exception { 
+        usersRepository.setEnableVirtualHosting(true);
+
+        domainList.addDomain(Domain.of("jAmEs.oRg"));
+        String username = "myuser";
+        String password = "password";
+        usersRepository.addUser(username + "@jAmEs.oRg", password);
+
+        boolean actual = usersRepository.test(username + "@james.org", password);
+
+        assertThat(actual).isTrue();
+    }
+
+    @Test
     public void testShouldReturnFalseWhenAUserHasAnIncorrectPassword() throws UsersRepositoryException
{ 
         //Given
         usersRepository.addUser(user1, "password");

http://git-wip-us.apache.org/repos/asf/james-project/blob/3e97f941/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java
b/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java
index 7c8b03a..500ee78 100644
--- a/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java
+++ b/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java
@@ -102,7 +102,7 @@ public class MemoryUsersRepository extends AbstractUsersRepository {
 
     @Override
     public boolean test(String name, final String password) throws UsersRepositoryException
{
-        return Optional.ofNullable(userByName.get(name))
+        return Optional.ofNullable(userByName.get(org.apache.james.core.User.fromUsername(name).asString()))
             .map(user -> user.verifyPassword(password))
             .orElse(false);
     }


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