Class AccountManager
- java.lang.Object
-
- org.jivesoftware.smack.Manager
-
- org.jivesoftware.smackx.iqregister.AccountManager
-
public final class AccountManager extends Manager
Allows creation and management of accounts on an XMPP server.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changePassword(String newPassword)
Changes the password of the currently logged-in account.void
createAccount(Localpart username, String password)
Creates a new account using the specified username and password.void
createAccount(Localpart 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 ornull
if the account attribute wasn't found.Set<String>
getAccountAttributes()
Returns an unmodifiable collection of the names of the required account attributes.String
getAccountInstructions()
Returns the instructions for creating a new account, ornull
if there are no instructions.static AccountManager
getInstance(XMPPConnection connection)
Returns the AccountManager instance associated with a given XMPPConnection.boolean
isSupported()
void
sensitiveOperationOverInsecureConnection(boolean allow)
Set totrue
to allow sensitive operation over insecure connection.static void
sensitiveOperationOverInsecureConnectionDefault(boolean allow)
The default value used by new account managers forallowSensitiveOperationOverInsecureConnection
.boolean
supportsAccountCreation()
Returns true if the server supports creating new accounts.-
Methods inherited from class org.jivesoftware.smack.Manager
connection, getAuthenticatedConnectionOrThrow, schedule, schedule, scheduleBlocking
-
-
-
-
Method Detail
-
getInstance
public static AccountManager getInstance(XMPPConnection connection)
Returns the AccountManager instance associated with a given XMPPConnection.- Parameters:
connection
- the connection used to look for the proper ServiceDiscoveryManager.- Returns:
- the AccountManager associated with a given XMPPConnection.
-
sensitiveOperationOverInsecureConnectionDefault
public static void sensitiveOperationOverInsecureConnectionDefault(boolean allow)
The default value used by new account managers forallowSensitiveOperationOverInsecureConnection
.- Parameters:
allow
- TODO javadoc me please- Since:
- 4.1
- See Also:
sensitiveOperationOverInsecureConnection(boolean)
-
sensitiveOperationOverInsecureConnection
public void sensitiveOperationOverInsecureConnection(boolean allow)
Set totrue
to allow sensitive operation over insecure connection.Set to true to allow sensitive operations like account creation or password changes over an insecure (e.g. unencrypted) connections.
- Parameters:
allow
- TODO javadoc me please- Since:
- 4.1
-
supportsAccountCreation
public boolean supportsAccountCreation() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
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.
- Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NoResponseException
- if there was no response from the remote entity.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
getAccountAttributes
public Set<String> getAccountAttributes() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
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:- name -- the user's name.
- first -- the user's first name.
- last -- the user's last name.
- email -- the user's email address.
- city -- the user's city.
- state -- the user's state.
- zip -- the user's ZIP code.
- phone -- the user's phone number.
- url -- the user's website.
- date -- the date the registration took place.
- misc -- other miscellaneous information to associate with the account.
- text -- textual information to associate with the account.
- remove -- empty flag to remove account.
Typically, servers require no attributes when creating new accounts, or just the user's email address.
- Returns:
- the required account attributes.
- Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NoResponseException
- if there was no response from the remote entity.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
getAccountAttribute
public String getAccountAttribute(String name) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
Returns the value of a given account attribute ornull
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. - Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NoResponseException
- if there was no response from the remote entity.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
getAccountInstructions
public String getAccountInstructions() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
Returns the instructions for creating a new account, ornull
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. - Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NoResponseException
- if there was no response from the remote entity.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
createAccount
public void createAccount(Localpart username, String password) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
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.XMPPErrorException
- if there was an XMPP error returned.SmackException.NoResponseException
- if there was no response from the remote entity.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
createAccount
public void createAccount(Localpart username, String password, Map<String,String> attributes) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
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.XMPPErrorException
- if an error occurs creating the account.SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.- See Also:
getAccountAttributes()
-
changePassword
public void changePassword(String newPassword) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
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.- Parameters:
newPassword
- new password.- Throws:
IllegalStateException
- if not currently logged-in to the server.XMPPException.XMPPErrorException
- if an error occurs when changing the password.SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
deleteAccount
public void deleteAccount() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
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.XMPPErrorException
- if an error occurs when deleting the account.SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
isSupported
public boolean isSupported() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
-
-