1 /** 2 * $RCSfile$ 3 * $Revision$ 4 * $Date$ 5 * 6 * Copyright 2003-2007 Jive Software. 7 * 8 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package org.jivesoftware.smack; 22 23 import org.apache.harmony.javax.security.auth.callback.CallbackHandler; 24 25 /** 26 * There are two ways to authenticate a user with a server. Using SASL or Non-SASL 27 * authentication. This interface makes {@link SASLAuthentication} and 28 * {@link NonSASLAuthentication} polyphormic. 29 * 30 * @author Gaston Dombiak 31 * @author Jay Kline 32 */ 33 interface UserAuthentication { 34 35 /** 36 * Authenticates the user with the server. This method will return the full JID provided by 37 * the server. The server may assign a full JID with a username and resource different than 38 * requested by this method. 39 * 40 * Note that using callbacks is the prefered method of authenticating users since it allows 41 * more flexability in the mechanisms used. 42 * 43 * @param username the requested username (authorization ID) for authenticating to the server 44 * @param resource the requested resource. 45 * @param cbh the CallbackHandler used to obtain authentication ID, password, or other 46 * information 47 * @return the full JID provided by the server while binding a resource for the connection. 48 * @throws XMPPException if an error occurs while authenticating. 49 */ 50 String authenticate(String username, String resource, CallbackHandler cbh) throws 51 XMPPException; 52 53 /** 54 * Authenticates the user with the server. This method will return the full JID provided by 55 * the server. The server may assign a full JID with a username and resource different than 56 * the requested by this method. 57 * 58 * It is recommended that @{link #authenticate(String, String, CallbackHandler)} be used instead 59 * since it provides greater flexability in authenticaiton and authorization. 60 * 61 * @param username the username that is authenticating with the server. 62 * @param password the password to send to the server. 63 * @param resource the desired resource. 64 * @return the full JID provided by the server while binding a resource for the connection. 65 * @throws XMPPException if an error occures while authenticating. 66 */ 67 String authenticate(String username, String password, String resource) throws 68 XMPPException; 69 70 /** 71 * Performs an anonymous authentication with the server. The server will created a new full JID 72 * for this connection. An exception will be thrown if the server does not support anonymous 73 * authentication. 74 * 75 * @return the full JID provided by the server while binding a resource for the connection. 76 * @throws XMPPException if an error occures while authenticating. 77 */ 78 String authenticateAnonymously() throws XMPPException; 79 } 80