View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.geronimo.javamail.authentication;
21  
22  import javax.mail.MessagingException;
23  
24  /**
25   * Simplified version of the Java 5 SaslClient interface. This is used to
26   * implement a javamail authentication framework that mimics the Sasl framework
27   * on a 1.4.2 JVM. Only the methods required by the Javamail code are
28   * implemented here, but it should be a simple migration to the fuller SASL
29   * interface.
30   */
31  public interface ClientAuthenticator {
32      /**
33       * Evaluate a challenge and return a response that can be sent back to the
34       * server. Bot the challenge information and the response information are
35       * "raw data", minus any special encodings used by the transport. For
36       * example, SMTP DIGEST-MD5 authentication protocol passes information as
37       * Base64 encoded strings. That encoding must be removed before calling
38       * evaluateChallenge() and the resulting respose must be Base64 encoced
39       * before transmission to the server.
40       * 
41       * It is the authenticator's responsibility to keep track of the state of
42       * the evaluations. That is, if the authentication process requires multiple
43       * challenge/response cycles, then the authenticator needs to keep track of
44       * context of the challenges.
45       * 
46       * @param challenge
47       *            The challenge data.
48       * 
49       * @return An appropriate response for the challenge data.
50       */
51  
52      public byte[] evaluateChallenge(byte[] challenge) throws MessagingException;
53  
54      /**
55       * Indicates that the authenticator has data that should be sent when the
56       * authentication process is initiated. For example, the SMTP PLAIN
57       * authentication sends userid/password without waiting for a challenge
58       * response.
59       * 
60       * If this method returns true, then the initial response is retrieved using
61       * evaluateChallenge() passing null for the challenge information.
62       * 
63       * @return True if the challenge/response process starts with an initial
64       *         response on the client side.
65       */
66      public boolean hasInitialResponse();
67  
68      /**
69       * Indicates whether the client believes the challenge/response sequence is
70       * now complete.
71       * 
72       * @return true if the client has evaluated what it believes to be the last
73       *         challenge, false if there are additional stages to evaluate.
74       */
75  
76      public boolean isComplete();
77  
78      /**
79       * Return the mechanism name implemented by this authenticator.
80       * 
81       * @return The string name of the authentication mechanism. This name should
82       *         match the names commonly used by the mail servers (e.g., "PLAIN",
83       *         "LOGIN", "DIGEST-MD5", etc.).
84       */
85      public String getMechanismName();
86  }