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