You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/11/19 02:43:36 UTC

[james-project] 34/43: JAMES-2982 dedicated exception of validating username in UserRepository

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit dedc4385009e4b38398556b3500d6b4502d74c0c
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Fri Nov 15 09:50:45 2019 +0700

    JAMES-2982 dedicated exception of validating username in UserRepository
---
 .../james/user/api/InvalidUsernameException.java   | 31 ++++++++++++++++++++++
 .../james/user/lib/AbstractUsersRepository.java    |  7 ++---
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/server/data/data-api/src/main/java/org/apache/james/user/api/InvalidUsernameException.java b/server/data/data-api/src/main/java/org/apache/james/user/api/InvalidUsernameException.java
new file mode 100644
index 0000000..d0aa0a1
--- /dev/null
+++ b/server/data/data-api/src/main/java/org/apache/james/user/api/InvalidUsernameException.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.user.api;
+
+public class InvalidUsernameException extends UsersRepositoryException {
+
+    public InvalidUsernameException(String msg, Throwable t) {
+        super(msg, t);
+    }
+
+    public InvalidUsernameException(String msg) {
+        super(msg);
+    }
+}
diff --git a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractUsersRepository.java b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractUsersRepository.java
index 2e26359..58d17a5 100644
--- a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractUsersRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractUsersRepository.java
@@ -33,6 +33,7 @@ import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.domainlist.api.DomainListException;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.user.api.AlreadyExistInUsersRepositoryException;
+import org.apache.james.user.api.InvalidUsernameException;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.UsersRepositoryException;
 
@@ -75,12 +76,12 @@ public abstract class AbstractUsersRepository implements UsersRepository, Config
         if (supportVirtualHosting()) {
             // need a @ in the username
             if (!username.hasDomainPart()) {
-                throw new UsersRepositoryException("Given Username needs to contain a @domainpart");
+                throw new InvalidUsernameException("Given Username needs to contain a @domainpart");
             } else {
                 Domain domain = username.getDomainPart().get();
                 try {
                     if (!domainList.containsDomain(domain)) {
-                        throw new UsersRepositoryException("Domain does not exist in DomainList");
+                        throw new InvalidUsernameException("Domain does not exist in DomainList");
                     }
                 } catch (DomainListException e) {
                     throw new UsersRepositoryException("Unable to query DomainList", e);
@@ -89,7 +90,7 @@ public abstract class AbstractUsersRepository implements UsersRepository, Config
         } else {
             // @ only allowed when virtualhosting is supported
             if (username.hasDomainPart()) {
-                throw new UsersRepositoryException("Given Username contains a @domainpart but virtualhosting support is disabled");
+                throw new InvalidUsernameException("Given Username contains a @domainpart but virtualhosting support is disabled");
             }
         }
     }


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