org.jivesoftware.smack.ConnectionConfiguration Java Examples

The following examples show how to use org.jivesoftware.smack.ConnectionConfiguration. 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: XmppConnectionDescriptor.java    From Smack with Apache License 2.0 6 votes vote down vote up
public C construct(Configuration sinttestConfiguration,
        Collection<ConnectionConfigurationBuilderApplier> customConnectionConfigurationAppliers)
        throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    CCB connectionConfigurationBuilder = getNewBuilder();
    if (extraBuilder != null) {
        extraBuilder.accept(connectionConfigurationBuilder);
    }
    for (ConnectionConfigurationBuilderApplier customConnectionConfigurationApplier : customConnectionConfigurationAppliers) {
        customConnectionConfigurationApplier.applyConfigurationTo(connectionConfigurationBuilder);
    }
    sinttestConfiguration.configurationApplier.applyConfigurationTo(connectionConfigurationBuilder);
    ConnectionConfiguration connectionConfiguration = connectionConfigurationBuilder.build();
    CC concreteConnectionConfiguration = connectionConfigurationClass.cast(connectionConfiguration);

    C connection = connectionConstructor.newInstance(concreteConnectionConfiguration);

    connection.setReplyTimeout(sinttestConfiguration.replyTimeout);

    return connection;
}
 
Example #2
Source File: XmppManager.java    From weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 与服务器建立连接
 * 
 * @return
 */
public boolean connectServer() {
	ConnectionConfiguration connConfig = new ConnectionConfiguration(xmppHost, Integer.parseInt(xmppPort));
	//设置安全模式
	connConfig.setSecurityMode(SecurityMode.required);
	//设置SASL认证是否启用
	connConfig.setSASLAuthenticationEnabled(false);
	//设置数据压缩是否启用
	connConfig.setCompressionEnabled(false);
	//是否启用调试模式
	connConfig.setDebuggerEnabled(true);

	/** 创建connection连接 */
	XMPPConnection connection = new XMPPConnection(connConfig);
	this.setConnection(connection);

	try {
		// 连接到服务器
		connection.connect();
		L.i(LOGTAG, "XMPP connected successfully");
		return true;
	} catch (XMPPException e) {
		L.e(LOGTAG, "XMPP connection failed", e);
	}
	return false;
}
 
Example #3
Source File: CompressionModule.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public StateTransitionResult.TransitionImpossible isTransitionToPossible(
                WalkStateGraphContext walkStateGraphContext) {
    final ConnectionConfiguration config = connectionInternal.connection.getConfiguration();
    if (!config.isCompressionEnabled()) {
        return new StateTransitionResult.TransitionImpossibleReason("Stream compression disabled by connection configuration");
    }

    Compress.Feature compressFeature = connectionInternal.connection.getFeature(Compress.Feature.ELEMENT, Compress.NAMESPACE);
    if (compressFeature == null) {
        return new StateTransitionResult.TransitionImpossibleReason("Stream compression not supported or enabled by service");
    }

    selectedCompressionFactory = XmppCompressionManager.getBestFactory(compressFeature);
    if (selectedCompressionFactory == null) {
        return new StateTransitionResult.TransitionImpossibleReason(
                        "No matching compression factory for " + compressFeature.getMethods());
    }

    usedXmppInputOutputCompressionFitler = selectedCompressionFactory.fabricate(config);

    return null;
}
 
Example #4
Source File: LolChat.java    From League-of-Legends-XMPP-Chat-Library with MIT License 6 votes vote down vote up
/**
 * Represents a single connection to a League of Legends chatserver.
 * 
 * @param server
 *            The chatserver of the region you want to connect to
 * @param friendRequestPolicy
 *            Determines how new Friend requests are treated.
 * @param riotApiKey
 *            Your apiKey used to convert summonerId's to name. You can get
 *            your key here <a
 *            href="https://developer.riotgames.com/">developer
 *            .riotgames.com</a>
 * 
 * @see LolChat#setFriendRequestPolicy(FriendRequestPolicy)
 * @see LolChat#setFriendRequestListener(FriendRequestListener)
 */
public LolChat(ChatServer server, FriendRequestPolicy friendRequestPolicy,
		RiotApiKey riotApiKey) {
	this.friendRequestPolicy = friendRequestPolicy;
	this.server = server;
	if (riotApiKey != null && server.api != null) {
		this.riotApi = RiotApi.build(riotApiKey, server);
	}
	Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
	final ConnectionConfiguration config = new ConnectionConfiguration(
			server.host, 5223, "pvp.net");
	config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
	config.setSocketFactory(SSLSocketFactory.getDefault());
	config.setCompressionEnabled(true);
	connection = new XMPPTCPConnection(config);

	addListeners();
}
 
Example #5
Source File: SecurityLoginSettingsPanel.java    From Spark with Apache License 2.0 6 votes vote down vote up
public void saveSettings()
{
    if ( modeRequiredRadio.isSelected() )
    {
        localPreferences.setSecurityMode( ConnectionConfiguration.SecurityMode.required );
    }
    if ( modeIfPossibleRadio.isSelected() )
    {
        localPreferences.setSecurityMode( ConnectionConfiguration.SecurityMode.ifpossible );
    }
    if ( modeDisabledRadio.isSelected() )
    {
        localPreferences.setSecurityMode( ConnectionConfiguration.SecurityMode.disabled );
    }
    localPreferences.setSSL( useSSLBox.isSelected() );
    localPreferences.setDisableHostnameVerification( disableHostnameVerificationBox.isSelected() );
    localPreferences.setAllowClientSideAuthentication( allowClientSideAuthentication.isSelected() );
    SettingsManager.saveSettings();
}
 
Example #6
Source File: XMPPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(XMPPIntegrationTest.class.getResourceAsStream("/server.jks"), "secret".toCharArray());

    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keyStore);

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());

    String port = AvailablePortFinder.readServerData("xmpp-port");

    ConnectionConfiguration connectionConfig = XMPPTCPConnectionConfiguration.builder()
        .setXmppDomain(JidCreate.domainBareFrom("apache.camel"))
        .setHostAddress(InetAddress.getLocalHost())
        .setPort(Integer.parseInt(port))
        .setCustomSSLContext(sslContext)
        .setHostnameVerifier((hostname, session) -> true)
        .build();

    context.bind("customConnectionConfig", connectionConfig);
}
 
Example #7
Source File: SmackGcmSenderChannel.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
/**
 * Connects to GCM Cloud Connection Server using the supplied credentials.
 *
 * @param senderId
 *            Your GCM project number
 * @param apiKey
 *            API Key of your project
 */
protected void connect(long senderId, String apiKey, int keepAliveInterval) throws XMPPException, IOException, SmackException {

    // Configure connection
    ConnectionConfiguration config = new ConnectionConfiguration(GcmServiceConstants.GCM_SERVER, GcmServiceConstants.GCM_PORT);
    config.setSecurityMode(SecurityMode.enabled);
    config.setReconnectionAllowed(true);
    config.setRosterLoadedAtLogin(false);
    config.setSendPresence(false);
    config.setSocketFactory(SSLSocketFactory.getDefault());

    // Create connection object and initiate connection
    connection = new XMPPTCPConnection(config);
    pingManager = PingManager.getInstanceFor(connection);
    pingManager.setPingInterval(keepAliveInterval);
    pingManager.registerPingFailedListener(this);
    connection.connect();

    // Register listener to log connection state events
    connection.addConnectionListener(new SmackLoggingConnectionListener());

    // Handle incoming messages (delivery receipts and Google control messages)
    connection.addPacketListener(upstreamListener, new PacketTypeFilter(Message.class));

    // Log in...
    connection.login(senderId + "@" + GcmServiceConstants.GCM_SERVER, apiKey);
}
 
Example #8
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static boolean addConnectionDescriptor(
                XmppConnectionDescriptor<? extends AbstractXMPPConnection, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> connectionDescriptor) {
    String nickname = connectionDescriptor.getNickname();
    Class<? extends AbstractXMPPConnection> connectionClass = connectionDescriptor.getConnectionClass();

    boolean alreadyExisted;
    synchronized (CONNECTION_DESCRIPTORS) {
        alreadyExisted = removeConnectionDescriptor(nickname);

        CONNECTION_DESCRIPTORS.put(connectionClass, connectionDescriptor);
        NICKNAME_CONNECTION_DESCRIPTORS.put(connectionDescriptor.getNickname(), connectionDescriptor);
    }
    return alreadyExisted;
}
 
Example #9
Source File: XmppConnectionDescriptor.java    From Smack with Apache License 2.0 5 votes vote down vote up
private static <CC extends ConnectionConfiguration> Method getBuilderMethod(Class<CC> connectionConfigurationClass)
        throws NoSuchMethodException, SecurityException {
    Method builderMethod = connectionConfigurationClass.getMethod("builder");
    if (!Modifier.isStatic(builderMethod.getModifiers())) {
        throw new IllegalArgumentException();
    }
    Class<?> returnType = builderMethod.getReturnType();
    if (!ConnectionConfiguration.Builder.class.isAssignableFrom(returnType)) {
        throw new IllegalArgumentException();
    }
    return builderMethod;
}
 
Example #10
Source File: MultiUserChatTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
public void testManyResources() throws Exception {
        // Create 5 more connections for user2
        XMPPTCPConnection[] conns = new XMPPConnection[5];
        for (int i = 0; i < conns.length; i++) {
            ConnectionConfiguration connectionConfiguration =
                    new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
            connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
            conns[i] = new XMPPTCPConnection(connectionConfiguration);
            conns[i].connect();
            conns[i].login(getUsername(1), getPassword(1), "resource-" + i);
            Thread.sleep(20);
        }

        // Join the 5 connections to the same room
        MultiUserChat[] mucs = new MultiUserChat[5];
        for (int i = 0; i < mucs.length; i++) {
            mucs[i] = new MultiUserChat(conns[i], room);
            mucs[i].join("resource-" + i);
        }

        Thread.sleep(200);

        // Each connection has something to say
        for (int i = 0; i < mucs.length; i++) {
            mucs[i].sendMessage("I'm resource-" + i);
        }

        Thread.sleep(200);

        // Each connection leaves the room and closes the connection
        for (MultiUserChat muc1 : mucs) {
            muc1.leave();
        }

        Thread.sleep(200);

        for (int i = 0; i < mucs.length; i++) {
            conns[i].disconnect();
        }
}
 
Example #11
Source File: MultiUserChatTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
public void testAnonymousParticipant() {
    try {
        // Anonymous user joins the new room
        ConnectionConfiguration connectionConfiguration =
                new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
        XMPPTCPConnection anonConnection = new XMPPConnection(connectionConfiguration);
        anonConnection.connect();
        anonConnection.loginAnonymously();
        MultiUserChat muc2 = new MultiUserChat(anonConnection, room);
        muc2.join("testbot2");
        Thread.sleep(400);

        // User1 checks the presence of Anonymous user in the room
        Presence presence = muc.getOccupantPresence(room + "/testbot2");
        assertNotNull("Presence of user2 in room is missing", presence);
        assertTrue(
            "Presence mode of user2 is wrong",
            presence.getMode() == null || presence.getMode() == Presence.Mode.available);

        // Anonymous user leaves the room
        muc2.leave();
        anonConnection.disconnect();
        Thread.sleep(250);
        // User1 checks the presence of Anonymous user in the room
        presence = muc.getOccupantPresence(room + "/testbot2");
        assertNull("Presence of participant testbotII still exists", presence);

    }
    catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
Example #12
Source File: SmackTestCase.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new XMPPTCPConnection using the connection preferences. This is useful when
 * not using a connection from the connection pool in a test case.
 *
 * @return a new XMPP connection.
 */
protected XMPPTCPConnection createConnection() {
    // Create the configuration for this new connection
    ConnectionConfiguration config = new ConnectionConfiguration(host, port);
    config.setCompressionEnabled(compressionEnabled);
    config.setSendPresence(sendInitialPresence());
    if (getSocketFactory() == null) {
        config.setSocketFactory(getSocketFactory());
    }
    return new XMPPTCPConnection(config);
}
 
Example #13
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private <C extends AbstractXMPPConnection> C constructConnectedConnection(
                XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> connectionDescriptor)
                throws InterruptedException, SmackException, IOException, XMPPException {
    C connection = constructConnection(connectionDescriptor, null);

    connection.connect();
    connection.login();

    return connection;
}
 
Example #14
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private <C extends AbstractXMPPConnection> C constructConnection(
        XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> connectionDescriptor,
        Collection<ConnectionConfigurationBuilderApplier> customConnectionConfigurationAppliers)
        throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    String username = "sinttest-" + testRunId + '-' + (connections.size() + 1);
    String password = StringUtils.randomString(24);

    return constructConnection(username, password, connectionDescriptor, customConnectionConfigurationAppliers);
}
 
Example #15
Source File: XMPPTCPConnection.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected void afterFeaturesReceived() throws NotConnectedException, InterruptedException, SecurityRequiredByServerException {
    StartTls startTlsFeature = getFeature(StartTls.ELEMENT, StartTls.NAMESPACE);
    if (startTlsFeature != null) {
        if (startTlsFeature.required() && config.getSecurityMode() == SecurityMode.disabled) {
            SecurityRequiredByServerException smackException = new SecurityRequiredByServerException();
            currentSmackException = smackException;
            notifyWaitingThreads();
            throw smackException;
        }

        if (config.getSecurityMode() != ConnectionConfiguration.SecurityMode.disabled) {
            sendNonza(new StartTls());
        } else {
            tlsHandled = true;
            notifyWaitingThreads();
        }
    } else {
        tlsHandled = true;
        notifyWaitingThreads();
    }

    if (isSaslAuthenticated()) {
        // If we have received features after the SASL has been successfully completed, then we
        // have also *maybe* received, as it is an optional feature, the compression feature
        // from the server.
        streamFeaturesAfterAuthenticationReceived = true;
        notifyWaitingThreads();
    }
}
 
Example #16
Source File: ClientConService.java    From weixin with Apache License 2.0 5 votes vote down vote up
public boolean login(String account, String password) {
	ConnectionConfiguration connConfig = new ConnectionConfiguration(xmppHost, Integer.parseInt(xmppPort));
	//设置安全模式
	connConfig.setSecurityMode(SecurityMode.required);
	//设置SASL认证是否启用
	connConfig.setSASLAuthenticationEnabled(false);
	//设置数据压缩是否启用
	connConfig.setCompressionEnabled(false);
	//是否启用调试模式
	connConfig.setDebuggerEnabled(true);

	/** 创建connection连接 */
	XMPPConnection connection = new XMPPConnection(connConfig);
	setConnection(connection);

	try {
		// 连接到服务器
		connection.connect();
		L.i(LOGTAG, "XMPP connected successfully");

		//登陆
		connection.login(account, password);

		/** 开启读写线程,并加入到管理类中 */
		//ClientSendThread cst = new ClientSendThread(connection);
		//cst.start();
		//ManageClientThread.addClientSendThread(account,cst);

		return true;
	} catch (XMPPException e) {
		L.e(LOGTAG, "XMPP connection failed", e);
	}
	return false;
}
 
Example #17
Source File: LocalPreferences.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
    * Return the desirability of encryption.
    *
    * @return The security mode.
    * @see org.jivesoftware.smack.ConnectionConfiguration.SecurityMode
    */
public ConnectionConfiguration.SecurityMode getSecurityMode()
   {
       try
       {
           final String securityMode = props.getProperty( "securityMode", Default.getString(Default.SECURITY_MODE) );
           return ConnectionConfiguration.SecurityMode.valueOf( securityMode );
       }
       catch ( Exception e )
       {
           Log.warning( "Unable to parse 'securityMode' value. Using default instead.", e );
           return ConnectionConfiguration.SecurityMode.ifpossible;
       }
   }
 
Example #18
Source File: MPAuthenticationProvider.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection to the XMPP server with the available configuration details given in
 * the identity.xml
 *
 * @return XMPPConnection
 */
private XMPPConnection createConnection() {
    String xmppServer = IdentityUtil.getProperty(IdentityConstants.ServerConfig.XMPP_SETTINGS_SERVER);
    int xmppPort = Integer.parseInt(IdentityUtil.getProperty(IdentityConstants.ServerConfig.XMPP_SETTINGS_PORT));
    String xmppExt = IdentityUtil.getProperty(IdentityConstants.ServerConfig.XMPP_SETTINGS_EXT);

    ConnectionConfiguration config = new ConnectionConfiguration(xmppServer, xmppPort, xmppExt);
    config.setSASLAuthenticationEnabled(true);
    return new XMPPConnection(config);
}
 
Example #19
Source File: XmppManager.java    From androidpn-client with Apache License 2.0 5 votes vote down vote up
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");
    boolean connected = false;
    if (!xmppManager.isConnected()) {
        // Create the configuration for this new connection
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());
            connected = true;

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
        }

        if (connected) {
            xmppManager.runTask();
        }

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        xmppManager.runTask();
    }
}
 
Example #20
Source File: XMPP.java    From XMPPSample_Studio with Apache License 2.0 5 votes vote down vote up
private XMPPTCPConnectionConfiguration buildConfiguration() throws XmppStringprepException {
    XMPPTCPConnectionConfiguration.Builder builder =
            XMPPTCPConnectionConfiguration.builder();


    builder.setHost(HOST1);
    builder.setPort(PORT);
    builder.setCompressionEnabled(false);
    builder.setDebuggerEnabled(true);
    builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    builder.setSendPresence(true);
    if (Build.VERSION.SDK_INT >= 14) {
        builder.setKeystoreType("AndroidCAStore");
        // config.setTruststorePassword(null);
        builder.setKeystorePath(null);
    } else {
        builder.setKeystoreType("BKS");
        String str = System.getProperty("javax.net.ssl.trustStore");
        if (str == null) {
            str = System.getProperty("java.home") + File.separator + "etc" + File.separator + "security"
                    + File.separator + "cacerts.bks";
        }
        builder.setKeystorePath(str);
    }
    DomainBareJid serviceName = JidCreate.domainBareFrom(HOST);
    builder.setServiceName(serviceName);


    return builder.build();
}
 
Example #21
Source File: XmppTool.java    From xmpp with Apache License 2.0 5 votes vote down vote up
/**
 * <b>function:</b> ��ʼSmack��openfire���������ӵĻ�������
 * 
 * @author hoojo
 * @createDate 2012-6-25 ����04:06:42
 */

public static void init() {
	try {
		// connection = new XMPPConnection(server);
		// connection.connect();

		/**
		 * 5222��openfire������Ĭ�ϵ�ͨ�Ŷ˿ڣ�����Ե�¼http://192.168.8.32:9090/
		 * ������Ա����̨�鿴�ͻ��˵��������˿�
		 */
		config = new ConnectionConfiguration(server, 5222);

		/** �Ƿ�����ѹ�� */
		config.setCompressionEnabled(true);
		/** �Ƿ����ð�ȫ��֤ */
		config.setSASLAuthenticationEnabled(false);
		/** �Ƿ����õ��� */
		config.setDebuggerEnabled(false);
		// config.setReconnectionAllowed(true);
		// config.setRosterLoadedAtLogin(true);

		/** ����connection���� */
		connection = new XMPPConnection(config);
		/** �������� */
		connection.connect();
	} catch (XMPPException e) {
		e.printStackTrace();
	}
	// fail(connection);
	// fail(connection.getConnectionID());
}
 
Example #22
Source File: XmppManager.java    From android-demo-xmpp-androidpn with Apache License 2.0 4 votes vote down vote up
public void run() {
    Log.i(LOGTAG, "ConnectTask.run()...");

    if (!xmppManager.isConnected()) {		//未连接到XMPP服务器
        // Create the configuration for this new connection
    	/**
    	 * 设置连接的一些参数
    	 */
        ConnectionConfiguration connConfig = new ConnectionConfiguration(
                xmppHost, xmppPort);
        // connConfig.setSecurityMode(SecurityMode.disabled);
        connConfig.setSecurityMode(SecurityMode.required);
        connConfig.setSASLAuthenticationEnabled(false);
        connConfig.setCompressionEnabled(false);

        XMPPConnection connection = new XMPPConnection(connConfig);
        xmppManager.setConnection(connection);

        try {
            // Connect to the server
            connection.connect();
            Log.i(LOGTAG, "XMPP connected successfully");

            // packet provider
            /** 
             * 这个就是对于通信的xml文本进行解析的解析器,再把信息转换成IQ,这个相当于QQ的聊天信息 
             * 如果要用这个协议,其IQ的子类(NotificationIQ)
             * 和IQProvider的子类(NotificationIQProvider)要进行重写 
             */
            ProviderManager.getInstance().addIQProvider("notification",
                    "androidpn:iq:notification",
                    new NotificationIQProvider());

        } catch (XMPPException e) {
            Log.e(LOGTAG, "XMPP connection failed", e);
            running = false;
        }
        //执行任务
        xmppManager.runTask();

    } else {
        Log.i(LOGTAG, "XMPP connected already");
        //执行任务
        xmppManager.runTask();
    }
}
 
Example #23
Source File: SecurityLoginSettingsPanel.java    From Spark with Apache License 2.0 4 votes vote down vote up
public SecurityLoginSettingsPanel( LocalPreferences localPreferences, JDialog optionsDialog )
{
    this.localPreferences = localPreferences;
    this.optionsDialog = optionsDialog;

    setLayout( new GridBagLayout() );

    // The titled-border panel labeled 'encryption mode'
    final JPanel encryptionModePanel = new JPanel();
    encryptionModePanel.setLayout( new GridBagLayout() );
    encryptionModePanel.setBorder( BorderFactory.createTitledBorder( Res.getString( "group.encryption_mode" ) ) );

    // The radio buttons that config the 'encryption mode'
    modeRequiredRadio = new JRadioButton();
    modeRequiredRadio.setToolTipText( Res.getString( "tooltip.encryptionmode.required" ) );
    modeIfPossibleRadio = new JRadioButton();
    modeIfPossibleRadio.setToolTipText( Res.getString( "tooltip.encryptionmode.ifpossible" ) );
    modeDisabledRadio = new JRadioButton();
    modeDisabledRadio.setToolTipText( Res.getString( "tooltip.encryptionmode.disabled" ) );

    useSSLBox = new JCheckBox();
    disableHostnameVerificationBox = new JCheckBox();
    allowClientSideAuthentication  = new JCheckBox();
    
    // .. Set labels/text for all the components.
    ResourceUtils.resButton( modeRequiredRadio,              Res.getString( "radio.encryptionmode.required" ) );
    ResourceUtils.resButton( modeIfPossibleRadio,            Res.getString( "radio.encryptionmode.ifpossible" ) );
    ResourceUtils.resButton( modeDisabledRadio,              Res.getString( "radio.encryptionmode.disabled" ) );
    ResourceUtils.resButton( useSSLBox,                      Res.getString( "label.old.ssl" ) );
    ResourceUtils.resButton( disableHostnameVerificationBox, Res.getString( "checkbox.disable.hostname.verification" ) );
    ResourceUtils.resButton( allowClientSideAuthentication,  Res.getString( "checkbox.allow.client.side.authentication" ) );
    
    // ... add the radio buttons to a group to make them interdependent.
    final ButtonGroup modeGroup = new ButtonGroup();
    modeGroup.add( modeRequiredRadio );
    modeGroup.add( modeIfPossibleRadio );
    modeGroup.add( modeDisabledRadio );

    // ... add event handler that disables the UI of encryption-related config, when encryption itself is disabled.
    modeDisabledRadio.addChangeListener( e -> {
        final boolean encryptionPossible = !modeDisabledRadio.isSelected();
        useSSLBox.setEnabled( encryptionPossible );
        disableHostnameVerificationBox.setEnabled( encryptionPossible );
        allowClientSideAuthentication.setEnabled( encryptionPossible );
    } );

    // ... apply the correct state, either based on saves settings, or defaults.
    modeRequiredRadio.setSelected( localPreferences.getSecurityMode() == ConnectionConfiguration.SecurityMode.required );
    modeIfPossibleRadio.setSelected( localPreferences.getSecurityMode() == ConnectionConfiguration.SecurityMode.ifpossible );
    modeDisabledRadio.setSelected( localPreferences.getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled );
    useSSLBox.setSelected( localPreferences.isSSL() );
    disableHostnameVerificationBox.setSelected( localPreferences.isDisableHostnameVerification() );
    allowClientSideAuthentication.setSelected(true);
    // ... place the components on the titled-border panel.
    encryptionModePanel.add( modeRequiredRadio,   new GridBagConstraints( 0, 0, 1, 1, 1.0, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );
    encryptionModePanel.add( modeIfPossibleRadio, new GridBagConstraints( 0, 1, 1, 1, 1.0, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );
    encryptionModePanel.add( modeDisabledRadio,   new GridBagConstraints( 0, 2, 1, 1, 1.0, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );
    encryptionModePanel.add( useSSLBox,           new GridBagConstraints( 0, 3, 2, 1, 1.0, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );

    // ... place the titled-border panel on the global panel.
    add( encryptionModePanel,            new GridBagConstraints( 0, 0, 1, 1, 1.0, 0.0, NORTHWEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );

    // ... place the other components under the titled-border panel.
    add( disableHostnameVerificationBox, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, NORTHWEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );
    add( allowClientSideAuthentication,  new GridBagConstraints( 0, 2, 1, 1, 0.0, 1.0, NORTHWEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );
}
 
Example #24
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
<C extends AbstractXMPPConnection> C constructConnection(
                XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> connectionDescriptor)
                throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    return constructConnection(connectionDescriptor, null);
}
 
Example #25
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <C extends AbstractXMPPConnection> XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> getConnectionDescriptorFor(
                Class<C> connectionClass) {
    return (XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>>) connectionDescriptors.getFirst(
                    connectionClass);
}
 
Example #26
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
public Collection<XmppConnectionDescriptor<? extends AbstractXMPPConnection, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>>> getConnectionDescriptors() {
    return Collections.unmodifiableCollection(nicknameConnectionDescriptors.values());
}
 
Example #27
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
public XmppConnectionDescriptor<? extends AbstractXMPPConnection, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> getDefaultConnectionDescriptor() {
    return defaultConnectionDescriptor;
}
 
Example #28
Source File: JabberWorkItemHandler.java    From jbpm-work-items with Apache License 2.0 4 votes vote down vote up
public void setConf(ConnectionConfiguration conf) {
    this.conf = conf;
}
 
Example #29
Source File: XmppConnectionDescriptor.java    From Smack with Apache License 2.0 4 votes vote down vote up
public static <C extends AbstractXMPPConnection, CC extends ConnectionConfiguration, CCB extends ConnectionConfiguration.Builder<?, CC>>
        Builder<C, CC, CCB> buildWith(Class<C> connectionClass, Class<CC> connectionConfigurationClass, Class<CCB> connectionConfigurationBuilderClass) {
    return new Builder<>(connectionClass, connectionConfigurationClass, connectionConfigurationBuilderClass);
}
 
Example #30
Source File: XmppConnectionDescriptor.java    From Smack with Apache License 2.0 4 votes vote down vote up
public static <C extends AbstractXMPPConnection, CC extends ConnectionConfiguration, CCB extends ConnectionConfiguration.Builder<?, CC>>
        Builder<C, CC, CCB> buildWith(Class<C> connectionClass, Class<CC> connectionConfigurationClass) {
    return buildWith(connectionClass, connectionConfigurationClass, null);
}