Class AccountManager


  • public final class AccountManager
    extends org.jivesoftware.smack.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​(java.lang.String newPassword)
      Changes the password of the currently logged-in account.
      void createAccount​(org.jxmpp.jid.parts.Localpart username, java.lang.String password)
      Creates a new account using the specified username and password.
      void createAccount​(org.jxmpp.jid.parts.Localpart username, java.lang.String password, java.util.Map<java.lang.String,​java.lang.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.
      java.lang.String getAccountAttribute​(java.lang.String name)
      Returns the value of a given account attribute or null if the account attribute wasn't found.
      java.util.Set<java.lang.String> getAccountAttributes()
      Returns an unmodifiable collection of the names of the required account attributes.
      java.lang.String getAccountInstructions()
      Returns the instructions for creating a new account, or null if there are no instructions.
      static AccountManager getInstance​(org.jivesoftware.smack.XMPPConnection connection)
      Returns the AccountManager instance associated with a given XMPPConnection.
      boolean isSupported()  
      void sensitiveOperationOverInsecureConnection​(boolean allow)
      Set to true to allow sensitive operation over insecure connection.
      static void sensitiveOperationOverInsecureConnectionDefault​(boolean allow)
      The default value used by new account managers for allowSensitiveOperationOverInsecureConnection.
      boolean supportsAccountCreation()
      Returns true if the server supports creating new accounts.
      • Methods inherited from class org.jivesoftware.smack.Manager

        connection, getAuthenticatedConnectionOrThrow, schedule, schedule, scheduleBlocking
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInstance

        public static AccountManager getInstance​(org.jivesoftware.smack.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 for allowSensitiveOperationOverInsecureConnection.
        Parameters:
        allow - TODO javadoc me please
        Since:
        4.1
        See Also:
        sensitiveOperationOverInsecureConnection(boolean)
      • sensitiveOperationOverInsecureConnection

        public void sensitiveOperationOverInsecureConnection​(boolean allow)
        Set to true 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 org.jivesoftware.smack.SmackException.NoResponseException,
                                               org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                               org.jivesoftware.smack.SmackException.NotConnectedException,
                                               java.lang.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:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • getAccountAttributes

        public java.util.Set<java.lang.String> getAccountAttributes()
                                                             throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                                    org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                                    org.jivesoftware.smack.SmackException.NotConnectedException,
                                                                    java.lang.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:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • getAccountAttribute

        public java.lang.String getAccountAttribute​(java.lang.String name)
                                             throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                    org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                    org.jivesoftware.smack.SmackException.NotConnectedException,
                                                    java.lang.InterruptedException
        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.
        Throws:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • getAccountInstructions

        public java.lang.String getAccountInstructions()
                                                throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                       org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                       org.jivesoftware.smack.SmackException.NotConnectedException,
                                                       java.lang.InterruptedException
        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.
        Throws:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • createAccount

        public void createAccount​(org.jxmpp.jid.parts.Localpart username,
                                  java.lang.String password)
                           throws org.jivesoftware.smack.SmackException.NoResponseException,
                                  org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                  org.jivesoftware.smack.SmackException.NotConnectedException,
                                  java.lang.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:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • createAccount

        public void createAccount​(org.jxmpp.jid.parts.Localpart username,
                                  java.lang.String password,
                                  java.util.Map<java.lang.String,​java.lang.String> attributes)
                           throws org.jivesoftware.smack.SmackException.NoResponseException,
                                  org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                  org.jivesoftware.smack.SmackException.NotConnectedException,
                                  java.lang.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:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if an error occurs creating the account.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the server.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
        See Also:
        getAccountAttributes()
      • changePassword

        public void changePassword​(java.lang.String newPassword)
                            throws org.jivesoftware.smack.SmackException.NoResponseException,
                                   org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                   org.jivesoftware.smack.SmackException.NotConnectedException,
                                   java.lang.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:
        java.lang.IllegalStateException - if not currently logged-in to the server.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if an error occurs when changing the password.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the server.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • deleteAccount

        public void deleteAccount()
                           throws org.jivesoftware.smack.SmackException.NoResponseException,
                                  org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                  org.jivesoftware.smack.SmackException.NotConnectedException,
                                  java.lang.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:
        java.lang.IllegalStateException - if not currently logged-in to the server.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if an error occurs when deleting the account.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the server.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • isSupported

        public boolean isSupported()
                            throws org.jivesoftware.smack.SmackException.NoResponseException,
                                   org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                   org.jivesoftware.smack.SmackException.NotConnectedException,
                                   java.lang.InterruptedException
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException
        org.jivesoftware.smack.XMPPException.XMPPErrorException
        org.jivesoftware.smack.SmackException.NotConnectedException
        java.lang.InterruptedException