org.jivesoftware.smackx.iqregister.AccountManager Java Examples

The following examples show how to use org.jivesoftware.smackx.iqregister.AccountManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmppTools.java    From Smack with Apache License 2.0 6 votes vote down vote up
public static boolean createAccount(DomainBareJid xmppDomain, Localpart username, String password)
        throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException,
        InterruptedException {
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder()
            .setXmppDomain(xmppDomain);
    TLSUtils.acceptAllCertificates(configBuilder);
    XMPPTCPConnectionConfiguration config = configBuilder.build();
    XMPPTCPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    try {
        if (!supportsIbr(connection))
            return false;

        AccountManager accountManager = AccountManager.getInstance(connection);
        accountManager.createAccount(username, password);
        return true;
    } finally {
        connection.disconnect();
    }
}
 
Example #2
Source File: ChatPreference.java    From Spark with Apache License 2.0 5 votes vote down vote up
@Override
public void commit() {
       LocalPreferences pref = SettingsManager.getLocalPreferences();
       pref.setTimeDisplayedInChat(panel.getShowTime());
       if( panel.getShowTime() )
       {
     	  pref.setTimeFormat(panel.getFormatTime());
       }
       pref.setChatRoomNotifications(panel.isGroupChatNotificationsOn());
       pref.setChatHistoryEnabled(!panel.isChatHistoryHidden());
       pref.setPrevChatHistoryEnabled(!panel.isPrevChatHistoryHidden());
       pref.setChatLengthDefaultTimeout(panel.getChatTimeoutTime());
       pref.setTabsOnTop(panel.isTabsOnTop());
       pref.setBuzzEnabled(panel.isBuzzEnabled());
       pref.setChatHistoryAscending(panel.isSortChatHistoryAscending());

       SettingsManager.saveSettings();

       // Do not commit if not changed.
       if (ModelUtil.hasLength(panel.getPassword()) && ModelUtil.hasLength(panel.getConfirmationPassword())) {
           try {
               AccountManager.getInstance( SparkManager.getConnection() ).changePassword(panel.getPassword());
           }
           catch (XMPPException | SmackException | InterruptedException passwordEx) {
           	UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
               JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.unable.to.save.password"),
                   Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
               Log.error("Unable to change password", passwordEx);
           }
       }
   }
 
Example #3
Source File: SmackIntegrationTestFramework.java    From Smack with Apache License 2.0 4 votes vote down vote up
public synchronized TestRunResult run()
        throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException,
        InterruptedException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    // The DNS resolver is not really a per sinttest run setting. It is not even a per connection setting. Instead
    // it is a global setting, but we treat it like a per sinttest run setting.
    switch (config.dnsResolver) {
    case minidns:
        MiniDnsResolver.setup();
        break;
    case javax:
        JavaxResolver.setup();
        break;
    case dnsjava:
        DNSJavaResolver.setup();
        break;
    }
    testRunResult = new TestRunResult();

    // Create a connection manager *after* we created the testRunId (in testRunResult).
    this.connectionManager = new XmppConnectionManager(this);

    LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting\nSmack version: " + SmackConfiguration.getVersion());
    if (config.debugger != Configuration.Debugger.none) {
        // JUL Debugger will not print any information until configured to print log messages of
        // level FINE
        // TODO configure JUL for log?
        SmackConfiguration.addDisabledSmackClass("org.jivesoftware.smack.debugger.JulDebugger");
        SmackConfiguration.DEBUG = true;
    }
    if (config.replyTimeout > 0) {
        SmackConfiguration.setDefaultReplyTimeout(config.replyTimeout);
    }
    if (config.securityMode != SecurityMode.required && config.accountRegistration == AccountRegistration.inBandRegistration) {
        AccountManager.sensitiveOperationOverInsecureConnectionDefault(true);
    }
    // TODO print effective configuration

    String[] testPackages;
    if (config.testPackages == null || config.testPackages.isEmpty()) {
        testPackages = new String[] { "org.jivesoftware.smackx", "org.jivesoftware.smack" };
    }
    else {
        testPackages = config.testPackages.toArray(new String[config.testPackages.size()]);
    }
    Reflections reflections = new Reflections(testPackages, new SubTypesScanner(),
                    new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new MethodParameterScanner());
    Set<Class<? extends AbstractSmackIntegrationTest>> inttestClasses = reflections.getSubTypesOf(AbstractSmackIntegrationTest.class);
    Set<Class<? extends AbstractSmackLowLevelIntegrationTest>> lowLevelInttestClasses = reflections.getSubTypesOf(AbstractSmackLowLevelIntegrationTest.class);

    Set<Class<? extends AbstractSmackIntTest>> classes = new HashSet<>(inttestClasses.size()
                    + lowLevelInttestClasses.size());
    classes.addAll(inttestClasses);
    classes.addAll(lowLevelInttestClasses);

    {
        // Remove all abstract classes.
        // TODO: This may be a good candidate for Java stream filtering once Smack is Android API 24 or higher.
        Iterator<Class<? extends AbstractSmackIntTest>> it = classes.iterator();
        while (it.hasNext()) {
            Class<? extends AbstractSmackIntTest> clazz = it.next();
            if (Modifier.isAbstract(clazz.getModifiers())) {
                it.remove();
            }
        }
    }

    if (classes.isEmpty()) {
        throw new IllegalStateException("No test classes found");
    }

    LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId
                    + "]: Finished scanning for tests, preparing environment");
    environment = prepareEnvironment();

    try {
        runTests(classes);
    }
    catch (Throwable t) {
        // Log the thrown Throwable to prevent it being shadowed in case the finally block below also throws.
        LOGGER.log(Level.SEVERE, "Unexpected abort because runTests() threw throwable", t);
        throw t;
    }
    finally {
        // Ensure that the accounts are deleted and disconnected before we continue
        connectionManager.disconnectAndCleanup();
    }

    return testRunResult;
}
 
Example #4
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
XmppConnectionManager(SmackIntegrationTestFramework sinttestFramework)
        throws SmackException, IOException, XMPPException, InterruptedException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    synchronized (CONNECTION_DESCRIPTORS) {
        connectionDescriptors = CONNECTION_DESCRIPTORS.clone();
        nicknameConnectionDescriptors = new HashMap<>(NICKNAME_CONNECTION_DESCRIPTORS);
    }

    this.sinttestFramework = sinttestFramework;
    this.sinttestConfiguration = sinttestFramework.config;
    this.testRunId = sinttestFramework.testRunResult.testRunId;

    String configuredDefaultConnectionNickname = sinttestConfiguration.defaultConnectionNickname;
    if (configuredDefaultConnectionNickname != null) {
        defaultConnectionDescriptor = nicknameConnectionDescriptors.get(configuredDefaultConnectionNickname);
        if (defaultConnectionDescriptor == null) {
            throw new IllegalArgumentException("Could not find a connection descriptor for connection nickname '" + configuredDefaultConnectionNickname + "'");
        }
    } else {
        defaultConnectionDescriptor = DEFAULT_CONNECTION_DESCRIPTOR;
    }

    switch (sinttestConfiguration.accountRegistration) {
    case serviceAdministration:
    case inBandRegistration:
        accountRegistrationConnection = defaultConnectionDescriptor.construct(sinttestConfiguration);
        accountRegistrationConnection.connect();
        accountRegistrationConnection.login(sinttestConfiguration.adminAccountUsername,
                        sinttestConfiguration.adminAccountPassword);

        if (sinttestConfiguration.accountRegistration == AccountRegistration.inBandRegistration) {

            adminManager = null;
            accountManager = AccountManager.getInstance(accountRegistrationConnection);
        } else {
            adminManager = ServiceAdministrationManager.getInstanceFor(accountRegistrationConnection);
            accountManager = null;
        }
        break;
    case disabled:
        accountRegistrationConnection = null;
        adminManager = null;
        accountManager = null;
        break;
    default:
        throw new AssertionError();
    }
}
 
Example #5
Source File: XmppTools.java    From Smack with Apache License 2.0 4 votes vote down vote up
public static boolean supportsIbr(XMPPConnection connection)
        throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    AccountManager accountManager = AccountManager.getInstance(connection);
    return accountManager.supportsAccountCreation();
}