@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;
    }
Ejemplo n.º 2
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);
    }
  }
Ejemplo n.º 3
0
 public String getLoginUserNickname() throws SmackInvocationException {
   try {
     return AccountManager.getInstance(con).getAccountAttribute("name");
   } catch (Exception e) {
     throw new SmackInvocationException(e);
   }
 }
Ejemplo n.º 4
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;
    }
  }
Ejemplo n.º 5
0
  /*
   * (non-Javadoc)
   *
   * @see
   * fr.univartois.ili.fsnet.commons.talk.ITalk#initConnexion(java.lang.String
   * , int, java.lang.String, java.lang.String, java.util.Map)
   */
  @Override
  public void initConnexion(
      String xmppServer, int port, String login, String pssword, Map<String, String> map)
      throws TalkException {
    config = new ConnectionConfiguration(xmppServer, port);

    connection = new XMPPConnection(config);
    try {
      if (!connection.isConnected()) {
        connection.connect();
      }

      accountManager = connection.getAccountManager();
      connection.login(login, pssword);

    } catch (XMPPException e) {
      if ((e.getLocalizedMessage().contains("authentication failed")
              || e.getLocalizedMessage().contains("SASL authentication"))
          && accountManager.supportsAccountCreation()) {
        createAccount(login, pssword, map);

      } else {
        Logger.getAnonymousLogger().log(Level.SEVERE, "", e);
      }
    }

    /* It is only at that moment where the Listener is correctly initialized */
    ChatStateManager.getInstance(connection);
  }
Ejemplo n.º 6
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;
  }
Ejemplo n.º 7
0
  public void signupAndLogin(String user, String password, String nickname, byte[] avatar)
      throws SmackInvocationException {
    connect();

    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("name", nickname);
    try {
      AccountManager.getInstance(con).createAccount(user, password, attributes);
    } catch (Exception e) {
      throw new SmackInvocationException(e);
    }

    login(user, password);

    vCardHelper.save(nickname, avatar);
  }
Ejemplo n.º 8
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);
    }
  }