james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1720572 - in /james/project/trunk: mpt/impl/managesieve/core/src/main/java/org/apache/james/mpt/testsuite/ mpt/impl/managesieve/core/src/main/resources/org/apache/james/managesieve/scripts/ mpt/impl/managesieve/file/src/test/java/org/apach...
Date Thu, 17 Dec 2015 14:55:26 GMT
Author: btellier
Date: Thu Dec 17 14:55:25 2015
New Revision: 1720572

URL: http://svn.apache.org/viewvc?rev=1720572&view=rev
Log:
JAMES-1618 Add a UNAUTHENTICATE command - RFC-5804 compliant

Added:
    james/project/trunk/mpt/impl/managesieve/core/src/main/java/org/apache/james/mpt/testsuite/UnauthenticatedTest.java
    james/project/trunk/mpt/impl/managesieve/core/src/main/resources/org/apache/james/managesieve/scripts/unauthenticate.test
Modified:
    james/project/trunk/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/ManageSieveFileTest.java
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/CoreCommands.java
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/ManageSieveProcessor.java

Added: james/project/trunk/mpt/impl/managesieve/core/src/main/java/org/apache/james/mpt/testsuite/UnauthenticatedTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mpt/impl/managesieve/core/src/main/java/org/apache/james/mpt/testsuite/UnauthenticatedTest.java?rev=1720572&view=auto
==============================================================================
--- james/project/trunk/mpt/impl/managesieve/core/src/main/java/org/apache/james/mpt/testsuite/UnauthenticatedTest.java
(added)
+++ james/project/trunk/mpt/impl/managesieve/core/src/main/java/org/apache/james/mpt/testsuite/UnauthenticatedTest.java
Thu Dec 17 14:55:25 2015
@@ -0,0 +1,42 @@
+/****************************************************************
+ * 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.mpt.testsuite;
+
+import com.google.inject.Inject;
+import org.apache.james.mpt.host.ManageSieveHostSystem;
+import org.junit.Test;
+
+import java.util.Locale;
+
+public class UnauthenticatedTest extends ManageSieveMPTTest {
+
+    @Inject
+    private static ManageSieveHostSystem hostSystem;
+
+    public UnauthenticatedTest() throws Exception {
+        super(hostSystem);
+    }
+
+    @Test
+    public void unauthenticatedCommandShouldWork() throws Exception {
+        scriptTest("unauthenticate", Locale.US);
+    }
+
+}

Added: james/project/trunk/mpt/impl/managesieve/core/src/main/resources/org/apache/james/managesieve/scripts/unauthenticate.test
URL: http://svn.apache.org/viewvc/james/project/trunk/mpt/impl/managesieve/core/src/main/resources/org/apache/james/managesieve/scripts/unauthenticate.test?rev=1720572&view=auto
==============================================================================
--- james/project/trunk/mpt/impl/managesieve/core/src/main/resources/org/apache/james/managesieve/scripts/unauthenticate.test
(added)
+++ james/project/trunk/mpt/impl/managesieve/core/src/main/resources/org/apache/james/managesieve/scripts/unauthenticate.test
Thu Dec 17 14:55:25 2015
@@ -0,0 +1,26 @@
+################################################################
+# 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.                                           #
+################################################################
+
+C: UNAUTHENTICATE arg
+S: NO UNAUTHENTICATE do not take arguments
+
+C: UNAUTHENTICATE
+S: NO UNAUTHENTICATE command must be issued in authenticated state
+
+# todo Add authentication and test un authenticate result
\ No newline at end of file

Modified: james/project/trunk/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/ManageSieveFileTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/ManageSieveFileTest.java?rev=1720572&r1=1720571&r2=1720572&view=diff
==============================================================================
--- james/project/trunk/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/ManageSieveFileTest.java
(original)
+++ james/project/trunk/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/ManageSieveFileTest.java
Thu Dec 17 14:55:25 2015
@@ -20,6 +20,7 @@
 package org.apache.james.mpt.managesieve.file;
 
 import org.apache.james.mpt.testsuite.NoopTest;
+import org.apache.james.mpt.testsuite.UnauthenticatedTest;
 import org.apache.onami.test.OnamiSuite;
 import org.apache.onami.test.annotation.GuiceModules;
 import org.junit.runner.RunWith;
@@ -28,7 +29,8 @@ import org.junit.runners.Suite;
 @GuiceModules({ FileModule.class })
 @RunWith(OnamiSuite.class)
 @Suite.SuiteClasses({
-    NoopTest.class
+    NoopTest.class,
+    UnauthenticatedTest.class
 })
 public class ManageSieveFileTest {
 }

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java?rev=1720572&r1=1720571&r2=1720572&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java
(original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java
Thu Dec 17 14:55:25 2015
@@ -26,4 +26,8 @@ public interface Session {
 
     String getUser();
 
+    void setAuthentication(boolean isAuthenticated);
+
+    void setUser(String user);
+
 }

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/CoreCommands.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/CoreCommands.java?rev=1720572&r1=1720571&r2=1720572&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/CoreCommands.java
(original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/CoreCommands.java
Thu Dec 17 14:55:25 2015
@@ -26,6 +26,6 @@ package org.apache.james.managesieve.api
  * @see <a href=http://tools.ietf.org/html/rfc5804#section-2>RFC 5804 Commands</a>
  */
 public interface CoreCommands extends Capability, CheckScript, DeleteScript, GetScript, HaveSpace,
-        ListScripts, PutScript, RenameScript, SetActive, GetActive, Noop {
+        ListScripts, PutScript, RenameScript, SetActive, GetActive, Noop, Unauthenticate
{
 
 }

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java?rev=1720572&r1=1720571&r2=1720572&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java
(original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/commands/Unauthenticate.java
Thu Dec 17 14:55:25 2015
@@ -20,7 +20,7 @@
 
 package org.apache.james.managesieve.api.commands;
 
-import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.Session;
 
 
 /**
@@ -28,6 +28,6 @@ import org.apache.james.managesieve.api.
  */
 public interface Unauthenticate {
    
-    void unauthenticate() throws AuthenticationRequiredException;
+    String unauthenticate(Session session);
 
 }

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java?rev=1720572&r1=1720571&r2=1720572&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
(original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
Thu Dec 17 14:55:25 2015
@@ -64,6 +64,7 @@ public class CoreProcessor implements Co
         this.capabilitiesBase = precomputeCapabilitiesBase(parser);
     }
 
+    @Override
     public Map<Capabilities, String> capability(Session session) {
         Map<Capabilities, String> capabilities = Maps.newHashMap(capabilitiesBase);
         if (session.isAuthenticated()) {
@@ -72,11 +73,13 @@ public class CoreProcessor implements Co
         return capabilities;
     }
 
+    @Override
     public List<String> checkScript(Session session, String content) throws AuthenticationRequiredException,
SyntaxException {
         authenticationCheck(session);
         return parser.parse(content);
     }
 
+    @Override
     public void deleteScript(Session session, String name) throws AuthenticationRequiredException,
ScriptNotFoundException, IsActiveException {
         authenticationCheck(session);
         try {
@@ -88,6 +91,7 @@ public class CoreProcessor implements Co
         }
     }
 
+    @Override
     public String getScript(Session session, String name) throws AuthenticationRequiredException,
ScriptNotFoundException, StorageException {
         authenticationCheck(session);
         try {
@@ -100,6 +104,7 @@ public class CoreProcessor implements Co
         }
     }
 
+    @Override
     public void haveSpace(Session session, String name, long size) throws AuthenticationRequiredException,
QuotaExceededException {
         authenticationCheck(session);
         try {
@@ -109,6 +114,7 @@ public class CoreProcessor implements Co
         }
     }
 
+    @Override
     public List<ScriptSummary> listScripts(Session session) throws AuthenticationRequiredException
{
         authenticationCheck(session);
         try {
@@ -118,6 +124,7 @@ public class CoreProcessor implements Co
         }
     }
 
+    @Override
     public List<String> putScript(Session session, String name, String content) throws
AuthenticationRequiredException, SyntaxException, QuotaExceededException {
         authenticationCheck(session);
         List<String> warnings = parser.parse(content);
@@ -131,6 +138,7 @@ public class CoreProcessor implements Co
         return warnings;
     }
 
+    @Override
     public void renameScript(Session session, String oldName, String newName) throws AuthenticationRequiredException,
ScriptNotFoundException, DuplicateException {
         authenticationCheck(session);
         try {
@@ -142,6 +150,7 @@ public class CoreProcessor implements Co
         }
     }
 
+    @Override
     public void setActive(Session session, String name) throws AuthenticationRequiredException,
ScriptNotFoundException {
         authenticationCheck(session);
         try {
@@ -153,6 +162,7 @@ public class CoreProcessor implements Co
         }
     }
 
+    @Override
     public String getActive(Session session) throws AuthenticationRequiredException, ScriptNotFoundException,
StorageException {
         authenticationCheck(session);
         try {
@@ -163,7 +173,25 @@ public class CoreProcessor implements Co
             throw new ManageSieveRuntimeException(e);
         }
     }
-    
+
+    @Override
+    public String noop(String tag) {
+        if(Strings.isNullOrEmpty(tag)) {
+            return "OK \"NOOP completed\"";
+        }
+        return "OK " + taggify(tag) + " \"DONE\"";
+    }
+
+    @Override
+    public String unauthenticate(Session session) {
+        if (session.isAuthenticated()) {
+            session.setAuthentication(false);
+            return "OK";
+        } else {
+            return "NO UNAUTHENTICATE command must be issued in authenticated state";
+        }
+    }
+
     protected void authenticationCheck(Session session) throws AuthenticationRequiredException
{
         ensureUser(session);
         if (!session.isAuthenticated()) {
@@ -192,14 +220,6 @@ public class CoreProcessor implements Co
         return builder.toString().trim();
     }
 
-    @Override
-    public String noop(String tag) {
-        if(Strings.isNullOrEmpty(tag)) {
-            return "OK \"NOOP completed\"";
-        }
-        return "OK " + taggify(tag) + " \"DONE\"";
-    }
-
     private String taggify(String tag) {
         String sanitizedTag = unquotaIfNeeded(tag.trim());
         return "(TAG {" + sanitizedTag.length() + "}\r\n" + sanitizedTag + ")";

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java?rev=1720572&r1=1720571&r2=1720572&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java
(original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCore.java
Thu Dec 17 14:55:25 2015
@@ -20,6 +20,7 @@
 
 package org.apache.james.managesieve.transcode;
 
+import com.google.common.base.Strings;
 import org.apache.james.managesieve.api.ArgumentException;
 import org.apache.james.managesieve.api.AuthenticationRequiredException;
 import org.apache.james.managesieve.api.Session;
@@ -61,6 +62,14 @@ public class LineToCore{
     public String noop(String args) {
         return core.noop(args);
     }
+
+    public String unauthenticate(Session session, String args) {
+        if (Strings.isNullOrEmpty(args)) {
+            return core.unauthenticate(session);
+        } else {
+            return "NO UNAUTHENTICATE do not take arguments";
+        }
+    }
     
     public void deleteScript(Session session, String args) throws AuthenticationRequiredException,
ScriptNotFoundException, IsActiveException, ArgumentException {
         String scriptName = ParserUtils.getScriptName(args);

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java?rev=1720572&r1=1720571&r2=1720572&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java
(original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/LineToCoreToLine.java
Thu Dec 17 14:55:25 2015
@@ -73,6 +73,10 @@ public class LineToCoreToLine {
         return lineToCore.noop(args);
     }
 
+    public String unauthenticate(Session session, String args) {
+        return lineToCore.unauthenticate(session, args);
+    }
+
     public String checkScript(Session session, String args) {
         try {
             List<String> warnings = lineToCore.checkScript(session, args);

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/ManageSieveProcessor.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/ManageSieveProcessor.java?rev=1720572&r1=1720571&r2=1720572&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/ManageSieveProcessor.java
(original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/transcode/ManageSieveProcessor.java
Thu Dec 17 14:55:25 2015
@@ -73,7 +73,7 @@ public class ManageSieveProcessor {
 
     private String parseArguments(String request, int firstWordEndIndex) {
         if (request.contains(" ")) {
-            return request.substring(firstWordEndIndex);
+            return request.substring(firstWordEndIndex).trim();
         } else {
             return "";
         }
@@ -109,7 +109,7 @@ public class ManageSieveProcessor {
         } else if (command.equals(STARTTLS)) {
             return "NO STARTTLS command not yet implemented";
         } else if (command.equals(UNAUTHENTICATE)) {
-            return "NO UNAUTHENTICATE command not yet handled";
+            return lineToCoreToLine.unauthenticate(session, arguments);
         } else {
             return "NO unknown " + command + " command";
         }



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