Search in sources :

Example 16 with DomainBareJid

use of org.jxmpp.jid.DomainBareJid in project Smack by igniterealtime.

the class MultiUserChatLightManager method unblockRooms.

/**
     * Unblock rooms.
     * 
     * @param mucLightService
     * @param roomsJids
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException
     */
public void unblockRooms(DomainBareJid mucLightService, List<Jid> roomsJids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    HashMap<Jid, Boolean> rooms = new HashMap<>();
    for (Jid jid : roomsJids) {
        rooms.put(jid, true);
    }
    sendUnblockRooms(mucLightService, rooms);
}
Also used : Jid(org.jxmpp.jid.Jid) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 17 with DomainBareJid

use of org.jxmpp.jid.DomainBareJid in project Smack by igniterealtime.

the class ServiceDiscoveryManager method findServices.

/**
     * Find all services under the users service that provide a given feature.
     * 
     * @param feature the feature to search for
     * @param stopOnFirst if true, stop searching after the first service was found
     * @param useCache if true, query a cache first to avoid network I/O
     * @return a possible empty list of services providing the given feature
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException 
     */
public List<DomainBareJid> findServices(String feature, boolean stopOnFirst, boolean useCache) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<DiscoverInfo> services = findServicesDiscoverInfo(feature, stopOnFirst, useCache);
    List<DomainBareJid> res = new ArrayList<>(services.size());
    for (DiscoverInfo info : services) {
        res.add(info.getFrom().asDomainBareJid());
    }
    return res;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ArrayList(java.util.ArrayList) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 18 with DomainBareJid

use of org.jxmpp.jid.DomainBareJid in project Smack by igniterealtime.

the class MultiUserChatLowLevelIntegrationTest method testMucBookmarksAutojoin.

@SmackIntegrationTest
public void testMucBookmarksAutojoin(XMPPTCPConnection connection) throws InterruptedException, TestNotPossibleException, XMPPException, SmackException, IOException {
    final BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(connection);
    if (!bookmarkManager.isSupported()) {
        throw new TestNotPossibleException("Private data storage not supported");
    }
    final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
    final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6));
    final String randomMucName = StringUtils.randomString(6);
    final DomainBareJid mucComponent = multiUserChatManager.getXMPPServiceDomains().get(0);
    final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(Localpart.from(randomMucName), mucComponent));
    MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname);
    if (handle != null) {
        handle.makeInstant();
    }
    muc.leave();
    bookmarkManager.addBookmarkedConference("Smack Inttest: " + testRunId, muc.getRoom(), true, mucNickname, null);
    connection.disconnect();
    connection.connect().login();
    // MucBookmarkAutojoinManager is also able to do its task automatically
    // after every login, it's not determinstic when this will be finished.
    // So we trigger it manually here.
    MucBookmarkAutojoinManager.getInstanceFor(connection).autojoinBookmarkedConferences();
    assertTrue(muc.isJoined());
    // If the test went well, leave the MUC
    muc.leave();
}
Also used : TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) DomainBareJid(org.jxmpp.jid.DomainBareJid) MucCreateConfigFormHandle(org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle) BookmarkManager(org.jivesoftware.smackx.bookmarks.BookmarkManager) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 19 with DomainBareJid

use of org.jxmpp.jid.DomainBareJid in project Smack by igniterealtime.

the class SASLAuthentication method authenticate.

/**
     * Performs SASL authentication of the specified user. If SASL authentication was successful
     * then resource binding and session establishment will be performed. This method will return
     * the full JID provided by the server while binding a resource to the connection.<p>
     *
     * The server may assign a full JID with a username or resource different than the requested
     * by this method.
     *
     * @param username the username that is authenticating with the server.
     * @param password the password to send to the server.
     * @param authzid the authorization identifier (typically null).
     * @param sslSession the optional SSL/TLS session (if one was established)
     * @throws XMPPErrorException
     * @throws SASLErrorException
     * @throws IOException
     * @throws SmackException
     * @throws InterruptedException
     */
public void authenticate(String username, String password, EntityBareJid authzid, SSLSession sslSession) throws XMPPErrorException, SASLErrorException, IOException, SmackException, InterruptedException {
    currentMechanism = selectMechanism(authzid);
    final CallbackHandler callbackHandler = configuration.getCallbackHandler();
    final String host = connection.getHost();
    final DomainBareJid xmppServiceDomain = connection.getXMPPServiceDomain();
    synchronized (this) {
        if (callbackHandler != null) {
            currentMechanism.authenticate(host, xmppServiceDomain, callbackHandler, authzid, sslSession);
        } else {
            currentMechanism.authenticate(username, host, xmppServiceDomain, password, authzid, sslSession);
        }
        final long deadline = System.currentTimeMillis() + connection.getReplyTimeout();
        while (!authenticationSuccessful && saslException == null) {
            final long now = System.currentTimeMillis();
            if (now >= deadline)
                break;
            // Wait until SASL negotiation finishes
            wait(deadline - now);
        }
    }
    if (saslException != null) {
        if (saslException instanceof SmackException) {
            throw (SmackException) saslException;
        } else if (saslException instanceof SASLErrorException) {
            throw (SASLErrorException) saslException;
        } else {
            throw new IllegalStateException("Unexpected exception type", saslException);
        }
    }
    if (!authenticationSuccessful) {
        throw NoResponseException.newWith(connection, "successful SASL authentication");
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) SASLErrorException(org.jivesoftware.smack.sasl.SASLErrorException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Aggregations

DomainBareJid (org.jxmpp.jid.DomainBareJid)19 Jid (org.jxmpp.jid.Jid)11 EntityBareJid (org.jxmpp.jid.EntityBareJid)10 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 WeakHashMap (java.util.WeakHashMap)4 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)4 MUCLightBlockingIQ (org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ)3 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)2 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)2 EntityFullJid (org.jxmpp.jid.EntityFullJid)2 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)1 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)1 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1