Smack

org.jivesoftware.smack
Class AccountManager

java.lang.Object
  extended by org.jivesoftware.smack.AccountManager

public class AccountManager
extends Object

Allows creation and management of accounts on an XMPP server.

Author:
Matt Tucker
See Also:
Connection.getAccountManager()

Constructor Summary
AccountManager(Connection connection)
          Creates a new AccountManager instance.
 
Method Summary
 void changePassword(String newPassword)
          Changes the password of the currently logged-in account.
 void createAccount(String username, String password)
          Creates a new account using the specified username and password.
 void createAccount(String username, String password, Map<String,String> attributes)
          Creates a new account using the specified username, password and account attributes.
 void deleteAccount()
          Deletes the currently logged-in account from the server.
 String getAccountAttribute(String name)
          Returns the value of a given account attribute or null if the account attribute wasn't found.
 Collection<String> getAccountAttributes()
          Returns an unmodifiable collection of the names of the required account attributes.
 String getAccountInstructions()
          Returns the instructions for creating a new account, or null if there are no instructions.
 boolean supportsAccountCreation()
          Returns true if the server supports creating new accounts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AccountManager

public AccountManager(Connection connection)
Creates a new AccountManager instance.

Parameters:
connection - a connection to a XMPP server.
Method Detail

supportsAccountCreation

public boolean supportsAccountCreation()
Returns true if the server supports creating new accounts. Many servers require that you not be currently authenticated when creating new accounts, so the safest behavior is to only create new accounts before having logged in to a server.

Returns:
true if the server support creating new accounts.

getAccountAttributes

public Collection<String> getAccountAttributes()
Returns an unmodifiable collection of the names of the required account attributes. All attributes must be set when creating new accounts. The standard set of possible attributes are as follows:

Typically, servers require no attributes when creating new accounts, or just the user's email address.

Returns:
the required account attributes.

getAccountAttribute

public String getAccountAttribute(String name)
Returns the value of a given account attribute or null if the account attribute wasn't found.

Parameters:
name - the name of the account attribute to return its value.
Returns:
the value of the account attribute or null if an account attribute wasn't found for the requested name.

getAccountInstructions

public String getAccountInstructions()
Returns the instructions for creating a new account, or null if there are no instructions. If present, instructions should be displayed to the end-user that will complete the registration process.

Returns:
the account creation instructions, or null if there are none.

createAccount

public void createAccount(String username,
                          String password)
                   throws XMPPException
Creates a new account using the specified username and password. The server may require a number of extra account attributes such as an email address and phone number. In that case, Smack will attempt to automatically set all required attributes with blank values, which may or may not be accepted by the server. Therefore, it's recommended to check the required account attributes and to let the end-user populate them with real values instead.

Parameters:
username - the username.
password - the password.
Throws:
XMPPException - if an error occurs creating the account.

createAccount

public void createAccount(String username,
                          String password,
                          Map<String,String> attributes)
                   throws XMPPException
Creates a new account using the specified username, password and account attributes. The attributes Map must contain only String name/value pairs and must also have values for all required attributes.

Parameters:
username - the username.
password - the password.
attributes - the account attributes.
Throws:
XMPPException - if an error occurs creating the account.
See Also:
getAccountAttributes()

changePassword

public void changePassword(String newPassword)
                    throws XMPPException
Changes the password of the currently logged-in account. This operation can only be performed after a successful login operation has been completed. Not all servers support changing passwords; an XMPPException will be thrown when that is the case.

Throws:
IllegalStateException - if not currently logged-in to the server.
XMPPException - if an error occurs when changing the password.

deleteAccount

public void deleteAccount()
                   throws XMPPException
Deletes the currently logged-in account from the server. This operation can only be performed after a successful login operation has been completed. Not all servers support deleting accounts; an XMPPException will be thrown when that is the case.

Throws:
IllegalStateException - if not currently logged-in to the server.
XMPPException - if an error occurs when deleting the account.

Smack

Copyright © 2003-2007 Jive Software.