Skip to content

Commit

Permalink
JAMES-1618 Add a AUTHENTICATE command - RFC-5804 compliant
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/james/project/trunk@1720575 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
chibenwa committed Dec 17, 2015
1 parent c6bcad0 commit 2111d83
Show file tree
Hide file tree
Showing 18 changed files with 427 additions and 66 deletions.
@@ -0,0 +1,47 @@
/****************************************************************
* 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.Before;
import org.junit.Test;

import java.util.Locale;

public class AuthenticateTest extends ManageSieveMPTTest {

@Inject
private static ManageSieveHostSystem hostSystem;

public AuthenticateTest() throws Exception {
super(hostSystem);
}

@Before
public void setUp() throws Exception {
super.setUp();
}

@Test
public void authenticateShouldWork() throws Exception {
scriptTest("authenticate", Locale.US);
}
}
Expand Up @@ -21,6 +21,7 @@


import com.google.inject.Inject; import com.google.inject.Inject;
import org.apache.james.mpt.host.ManageSieveHostSystem; import org.apache.james.mpt.host.ManageSieveHostSystem;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;


import java.util.Locale; import java.util.Locale;
Expand All @@ -34,6 +35,11 @@ public UnauthenticatedTest() throws Exception {
super(hostSystem); super(hostSystem);
} }


@Before
public void setUp() throws Exception {
super.setUp();
}

@Test @Test
public void unauthenticatedCommandShouldWork() throws Exception { public void unauthenticatedCommandShouldWork() throws Exception {
scriptTest("unauthenticate", Locale.US); scriptTest("unauthenticate", Locale.US);
Expand Down
@@ -0,0 +1,37 @@
################################################################
# 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: AUTHENTICATE
S: NO ManageSieve syntax is incorrect : You must specify a SASL mechanism as an argument of AUTHENTICATE command

C: AUTHENTICATE UNKNOWN
S: NO Unknown SASL mechanism UNKNOWN

C: AUTHENTICATE "PLAIN"
S: \+ ""
C: GETSCRIPT toto.sieve
S: NO ManageSieve syntax is incorrect : You must supply a password for the authentication mechanism. Formal syntax : <NULL>username<NULL>password

C: tin password
S: NO authentication failed

C: AUTHENTICATE "PLAIN"
S: \+ ""
C: user password
S: OK authentication successfull
Expand Up @@ -17,10 +17,25 @@
# under the License. # # under the License. #
################################################################ ################################################################


C: GETSCRIPT any
S: NO

C: UNAUTHENTICATE arg C: UNAUTHENTICATE arg
S: NO UNAUTHENTICATE do not take arguments S: NO UNAUTHENTICATE do not take arguments


C: UNAUTHENTICATE C: UNAUTHENTICATE
S: NO UNAUTHENTICATE command must be issued in authenticated state S: NO UNAUTHENTICATE command must be issued in authenticated state


# todo Add authentication and test un authenticate result C: AUTHENTICATE "PLAIN"
S: \+ ""
C: user password
S: OK authentication successfull

C: GETSCRIPT any
S: NO \(NONEXISTENT\) "There is no script by that name"

C: UNAUTHENTICATE
S: OK

C: GETSCRIPT any
S: NO
Expand Up @@ -19,6 +19,7 @@


package org.apache.james.mpt.managesieve.file; package org.apache.james.mpt.managesieve.file;


import org.apache.james.mpt.testsuite.AuthenticateTest;
import org.apache.james.mpt.testsuite.LogoutTest; import org.apache.james.mpt.testsuite.LogoutTest;
import org.apache.james.mpt.testsuite.NoopTest; import org.apache.james.mpt.testsuite.NoopTest;
import org.apache.james.mpt.testsuite.UnauthenticatedTest; import org.apache.james.mpt.testsuite.UnauthenticatedTest;
Expand All @@ -32,7 +33,8 @@
@Suite.SuiteClasses({ @Suite.SuiteClasses({
NoopTest.class, NoopTest.class,
UnauthenticatedTest.class, UnauthenticatedTest.class,
LogoutTest.class LogoutTest.class,
AuthenticateTest.class
}) })
public class ManageSieveFileTest { public class ManageSieveFileTest {
} }
Expand Up @@ -20,7 +20,9 @@


package org.apache.james.managesieve.api; package org.apache.james.managesieve.api;


public class AuthenticationException extends ManageSieveException public class AuthenticationException extends ManageSieveException {
{
private static final long serialVersionUID = -7564649071256099047L; public AuthenticationException(String message) {
super(message);
}
} }
@@ -0,0 +1,34 @@
/*
* 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.managesieve.api;

public interface AuthenticationProcessor {

String initialServerResponse(Session session);

/**
* @return Null if authentication failed, the authenticated username if authentication is successfull
* @throws SyntaxException
* @throws AuthenticationException
*/
String isAuthenticationSuccesfull(Session session, String suppliedClientData) throws SyntaxException, AuthenticationException;

}
Expand Up @@ -20,18 +20,29 @@


package org.apache.james.managesieve.api; package org.apache.james.managesieve.api;


import org.apache.james.managesieve.api.commands.Authenticate;

public interface Session { public interface Session {


boolean isAuthenticated(); enum State {
UNAUTHENTICATED,
AUTHENTICATION_IN_PROGRESS,
AUTHENTICATED,
TERMINATED
}


boolean isTerminated(); boolean isAuthenticated();


String getUser(); String getUser();


void setAuthentication(boolean isAuthenticated);

void setUser(String user); void setUser(String user);


void markSessionAsTerminated(); State getState();

void setState(State state);

Authenticate.SupportedMechanism getChoosedAuthenticationMechanism();

void setChoosedAuthenticationMechanism(Authenticate.SupportedMechanism choosedAuthenticationMechanism);


} }
@@ -0,0 +1,10 @@


package org.apache.james.managesieve.api;

public class UnknownSaslMechanism extends ManageSieveException {

public UnknownSaslMechanism(String unknownMechanism) {
super("Unknown SASL mechanism " + unknownMechanism);
}
}
Expand Up @@ -21,14 +21,30 @@
package org.apache.james.managesieve.api.commands; package org.apache.james.managesieve.api.commands;


import org.apache.james.managesieve.api.AuthenticationException; import org.apache.james.managesieve.api.AuthenticationException;
import org.apache.james.managesieve.api.Session;
import org.apache.james.managesieve.api.SyntaxException;
import org.apache.james.managesieve.api.UnknownSaslMechanism;




/** /**
* @see <a href=http://tools.ietf.org/html/rfc5804#section-2.1>RFC 5804 AUTHENTICATE Command</a> * @see <a href=http://tools.ietf.org/html/rfc5804#section-2.1>RFC 5804 AUTHENTICATE Command</a>
*/ */
public interface Authenticate { public interface Authenticate {

enum SupportedMechanism {
PLAIN;

public static SupportedMechanism retrieveMechanism(String serializedData) throws UnknownSaslMechanism {
for (SupportedMechanism supportedMechanism : SupportedMechanism.values()) {
if (supportedMechanism.toString().equalsIgnoreCase(serializedData)) {
return supportedMechanism;
}
}
throw new UnknownSaslMechanism(serializedData);
}
}


void authenticate(String mechanism) throws AuthenticationException; String chooseMechanism(Session session, String mechanism) throws AuthenticationException, UnknownSaslMechanism, SyntaxException;


void authenticate(String mechanism, String initialData) throws AuthenticationException; String authenticate(Session session, String suppliedData) throws AuthenticationException, SyntaxException;
} }
Expand Up @@ -26,6 +26,6 @@
* @see <a href=http://tools.ietf.org/html/rfc5804#section-2>RFC 5804 Commands</a> * @see <a href=http://tools.ietf.org/html/rfc5804#section-2>RFC 5804 Commands</a>
*/ */
public interface CoreCommands extends Capability, CheckScript, DeleteScript, GetScript, HaveSpace, public interface CoreCommands extends Capability, CheckScript, DeleteScript, GetScript, HaveSpace,
ListScripts, PutScript, RenameScript, SetActive, GetActive, Noop, Unauthenticate, Logout { ListScripts, PutScript, RenameScript, SetActive, GetActive, Noop, Unauthenticate, Logout, Authenticate {


} }

0 comments on commit 2111d83

Please sign in to comment.