@Override
    protected Boolean doInBackground(String... params) {
      Log.d(TAG, "Xmpp login task");
      jid = params[0];
      password = params[1];
      Log.d(TAG, "jid " + jid + " server  " + server);

      int port = -1;
      if (params.length > 2) {
        server = params[2];
      }
      if (params.length > 3) {
        if (!TextUtils.isEmpty(params[3])) {
          port = Integer.parseInt(params[3]);
        }
      }
      Connection connection = prepareConnection(jid, server, port);
      try {
        connection.connect();
        AccountManager accountManager = new AccountManager(connection);
        accountManager.createAccount(StringUtils.parseName(jid), password);
      } catch (XMPPException e) {
        Log.e(TAG, "Unable to create account", e);
        exception = e;
        return false;
      } finally {
        connection.disconnect();
      }
      return true;
    }
Exemplo n.º 2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * fr.univartois.ili.fsnet.commons.talk.ITalk#createAccount(java.lang.String
   * , java.lang.String, java.util.Map)
   */
  @Override
  public boolean createAccount(String userName, String password, Map<String, String> map) {
    {
      if (!connection.isConnected()) {
        try {
          connection.connect();
        } catch (XMPPException e3) {

          Logger.getAnonymousLogger().log(Level.SEVERE, "", e3);
        }
      }

      try {
        Map<String, String> finalMap = map;
        if (finalMap == null) {
          finalMap = new HashMap<String, String>();
        }
        accountManager.createAccount(userName, password, finalMap);

        connection.disconnect();
        // Thread.sleep(6000);
        connection.connect();
        connection.login(userName, password);

        return true;
      } catch (XMPPException e2) {
        Logger.getAnonymousLogger().log(Level.SEVERE, "", e2);
      }
      return false;
    }
  }
Exemplo n.º 3
0
 /**
  * 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.
  *
  * @param username the username.
  * @param password the password.
  * @throws XMPPException if an error occurs creating the account.
  */
 public void createAccount(String username, String password) throws XMPPException {
   if (!supportsAccountCreation()) {
     throw new XMPPException("Server does not support account creation.");
   }
   // Create a map for all the required attributes, but give them blank values.
   Map<String, String> attributes = new HashMap<String, String>();
   for (String attributeName : getAccountAttributes()) {
     attributes.put(attributeName, "");
   }
   createAccount(username, password, attributes);
 }
Exemplo n.º 4
0
  private void tryToConnect(boolean create_account) throws ClientException {
    try {
      if (extXMPPConnection.isConnected()) {
        try {
          streamHandler.quickShutdown();
        } catch (Exception e) {
          Log.d(TAG, "conn.shutdown() failed: " + e);
        }
      }
      registerRosterListener();
      boolean need_bind = !streamHandler.isResumePossible();

      if (connectionListener != null)
        extXMPPConnection.removeConnectionListener(connectionListener);
      connectionListener =
          new ConnectionListener() {
            public void connectionClosedOnError(Exception e) {
              onDisconnected(e);
            }

            public void connectionClosed() {

              updateConnectionState(ConnectionState.OFFLINE);
            }

            public void reconnectingIn(int seconds) {}

            public void reconnectionFailed(Exception e) {}

            public void reconnectionSuccessful() {}
          };
      extXMPPConnection.addConnectionListener(connectionListener);

      extXMPPConnection.connect(need_bind);
      if (!extXMPPConnection.isAuthenticated()) {
        if (create_account) {
          AccountManager am = new AccountManager(extXMPPConnection);
          am.createAccount(configuration.userName, configuration.password);
        }
        extXMPPConnection.login(
            configuration.userName, configuration.password, configuration.ressource);
      }
      if (need_bind) {
        streamHandler.notifyInitialLogin();
        setStatusFromConfig();
      }

    } catch (Exception e) {

      throw new ClientException("tryToConnect failed", e);
    }
  }
Exemplo n.º 5
0
  public XMPPConnection findOrCreateXmppConnection(UMOEndpointURI endpointURI)
      throws XMPPException {
    logger.info("Trying to find XMPP connection for uri: " + endpointURI);
    XMPPConnection xmppConnection = null;

    String username = endpointURI.getUsername();
    String hostname = endpointURI.getHost();
    String password = endpointURI.getPassword();
    String resource = endpointURI.getPath();

    if (resource == null || "".equals(resource)) {
      resource = DEFAULT_RESOURCE;
    } else {
      resource = resource.substring(1);
    }

    xmppConnection = findOrCreateConnection(endpointURI);

    logger.info("*************************************");
    logger.info("*            JABBER LOGIN           *");
    logger.info("*************************************");

    if (!xmppConnection.isAuthenticated()) {
      // Make sure we have an account.  If we don't, make one.
      try {
        AccountManager accManager = new AccountManager(xmppConnection);
        accManager.createAccount(username, password);
      } catch (XMPPException ex) {
        // User probably already exists, throw away...
        logger.info("*** account (" + username + ") already exists ***");
      }

      logger.info("Logging in as: " + username);
      logger.info("pw is        : " + password);
      logger.info("server       : " + hostname);
      logger.info("resource     : " + resource);
      xmppConnection.login(username, password, resource);
    } else {
      logger.info("Already authenticated on this connection, no need to log in again.");
    }

    logger.info("XMPP LOGIN COMPLETE!");

    return xmppConnection;
  }
Exemplo n.º 6
0
  private void tryToConnect(boolean create_account) throws YaximXMPPException {
    try {
      if (mXMPPConnection.isConnected()) {
        try {
          mStreamHandler.quickShutdown(); // blocking shutdown prior to re-connection
        } catch (Exception e) {
          debugLog("conn.shutdown() failed: " + e);
        }
      }
      registerRosterListener();
      boolean need_bind = !mStreamHandler.isResumePossible();

      mXMPPConnection.connect(need_bind);
      // the following should not happen as of smack 3.3.1
      if (!mXMPPConnection.isConnected()) {
        throw new YaximXMPPException("SMACK connect failed without exception!");
      }
      if (mConnectionListener != null)
        mXMPPConnection.removeConnectionListener(mConnectionListener);
      mConnectionListener =
          new ConnectionListener() {
            public void connectionClosedOnError(Exception e) {
              onDisconnected(e);
            }

            public void connectionClosed() {
              // TODO: fix reconnect when we got kicked by the server or SM failed!
              // onDisconnected(null);
              updateConnectionState(ConnectionState.OFFLINE);
            }

            public void reconnectingIn(int seconds) {}

            public void reconnectionFailed(Exception e) {}

            public void reconnectionSuccessful() {}
          };
      mXMPPConnection.addConnectionListener(mConnectionListener);

      // SMACK auto-logins if we were authenticated before
      if (!mXMPPConnection.isAuthenticated()) {
        if (create_account) {
          Log.d(TAG, "creating new server account...");
          AccountManager am = new AccountManager(mXMPPConnection);
          am.createAccount(mConfig.userName, mConfig.password);
        }
        mXMPPConnection.login(mConfig.userName, mConfig.password, mConfig.ressource);
      }
      Log.d(
          TAG, "SM: can resume = " + mStreamHandler.isResumePossible() + " needbind=" + need_bind);
      if (need_bind) {
        mStreamHandler.notifyInitialLogin();
        setStatusFromConfig();
      }

    } catch (YaximXMPPException e) {
      throw e;
    } catch (Exception e) {
      // actually we just care for IllegalState or NullPointer or XMPPEx.
      throw new YaximXMPPException("tryToConnect failed", e);
    }
  }