/** * Enable the given SASL mechanisms. If you never add a mechanism to the set of enabled ones, <b>all mechanisms * known to Smack</b> will be enabled. Only explicitly enable particular SASL mechanisms if you want to limit * the used mechanisms to the enabled ones. * * @param saslMechanisms a collection of names of mechanisms to enable. * @return a reference to this builder. */ public B addEnabledSaslMechanism(Collection<String> saslMechanisms) { if (saslMechanismsSealed) { throw new IllegalStateException("The enabled SASL mechanisms are sealed, you can not add new ones"); } CollectionUtil.requireNotEmpty(saslMechanisms, "saslMechanisms"); Set<String> blacklistedMechanisms = SASLAuthentication.getBlacklistedSASLMechanisms(); for (String mechanism : saslMechanisms) { if (!SASLAuthentication.isSaslMechanismRegistered(mechanism)) { throw new IllegalArgumentException("SASL " + mechanism + " is not available. Consider registering it with Smack"); } if (blacklistedMechanisms.contains(mechanism)) { throw new IllegalArgumentException("SALS " + mechanism + " is blacklisted."); } } if (enabledSaslMechanisms == null) { enabledSaslMechanisms = new HashSet<>(saslMechanisms.size()); } enabledSaslMechanisms.addAll(saslMechanisms); return getThis(); }
/** * Perform anonymous authentication using SASL ANONYMOUS. Your XMPP service must support this authentication * mechanism. This method also calls {@link #addEnabledSaslMechanism(String)} with "ANONYMOUS" as argument. * * @return a reference to this builder. */ public B performSaslAnonymousAuthentication() { if (!SASLAuthentication.isSaslMechanismRegistered(SASLAnonymous.NAME)) { throw new IllegalArgumentException("SASL " + SASLAnonymous.NAME + " is not registered"); } throwIfEnabledSaslMechanismsSet(); allowEmptyOrNullUsernames(); addEnabledSaslMechanism(SASLAnonymous.NAME); saslMechanismsSealed = true; return getThis(); }
/** * Perform authentication using SASL EXTERNAL. Your XMPP service must support this * authentication mechanism. This method also calls {@link #addEnabledSaslMechanism(String)} with "EXTERNAL" as * argument. It also calls {@link #allowEmptyOrNullUsernames()} and {@link #setSecurityMode(ConnectionConfiguration.SecurityMode)} to * {@link SecurityMode#required}. * * @param sslContext custom SSLContext to be used. * @return a reference to this builder. */ public B performSaslExternalAuthentication(SSLContext sslContext) { if (!SASLAuthentication.isSaslMechanismRegistered(SASLMechanism.EXTERNAL)) { throw new IllegalArgumentException("SASL " + SASLMechanism.EXTERNAL + " is not registered"); } setCustomSSLContext(sslContext); throwIfEnabledSaslMechanismsSet(); allowEmptyOrNullUsernames(); setSecurityMode(SecurityMode.required); addEnabledSaslMechanism(SASLMechanism.EXTERNAL); saslMechanismsSealed = true; return getThis(); }
/** * Enable the given SASL mechanisms. If you never add a mechanism to the set of enabled ones, <b>all mechanisms * known to Smack</b> will be enabled. Only explicitly enable particular SASL mechanisms if you want to limit * the used mechanisms to the enabled ones. * * @param saslMechanisms a collection of names of mechanisms to enable. * @return a reference to this builder. */ public B addEnabledSaslMechanism(Collection<String> saslMechanisms) { if (saslMechanismsSealed) { throw new IllegalStateException("The enabled SASL mechanisms are sealed, you can not add new ones"); } CollectionUtil.requireNotEmpty(saslMechanisms, "saslMechanisms"); Set<String> blacklistedMechanisms = SASLAuthentication.getBlacklistedSASLMechanisms(); for (String mechanism : saslMechanisms) { if (!SASLAuthentication.isSaslMechanismRegistered(mechanism)) { throw new IllegalArgumentException("SASL " + mechanism + " is not available. Consider registering it with Smack"); } if (blacklistedMechanisms.contains(mechanism)) { throw new IllegalArgumentException("SALS " + mechanism + " is blacklisted."); } } if (enabledSaslMechanisms == null) { enabledSaslMechanisms = new HashSet<>(saslMechanisms.size()); } enabledSaslMechanisms.addAll(saslMechanisms); return getThis(); }
/** * Perform anonymous authentication using SASL ANONYMOUS. Your XMPP service must support this authentication * mechanism. This method also calls {@link #addEnabledSaslMechanism(String)} with "ANONYMOUS" as argument. * * @return a reference to this builder. */ public B performSaslAnonymousAuthentication() { if (!SASLAuthentication.isSaslMechanismRegistered(SASLAnonymous.NAME)) { throw new IllegalArgumentException("SASL " + SASLAnonymous.NAME + " is not registered"); } throwIfEnabledSaslMechanismsSet(); allowEmptyOrNullUsernames(); addEnabledSaslMechanism(SASLAnonymous.NAME); saslMechanismsSealed = true; return getThis(); }
/** * Perform authentication using SASL EXTERNAL. Your XMPP service must support this * authentication mechanism. This method also calls {@link #addEnabledSaslMechanism(String)} with "EXTERNAL" as * argument. It also calls {@link #allowEmptyOrNullUsernames()} and {@link #setSecurityMode(ConnectionConfiguration.SecurityMode)} to * {@link SecurityMode#required}. * * @param sslContext custom SSLContext to be used. * @return a reference to this builder. */ public B performSaslExternalAuthentication(SSLContext sslContext) { if (!SASLAuthentication.isSaslMechanismRegistered(SASLMechanism.EXTERNAL)) { throw new IllegalArgumentException("SASL " + SASLMechanism.EXTERNAL + " is not registered"); } setCustomSSLContext(sslContext); throwIfEnabledSaslMechanismsSet(); allowEmptyOrNullUsernames(); setSecurityMode(SecurityMode.required); addEnabledSaslMechanism(SASLMechanism.EXTERNAL); saslMechanismsSealed = true; return getThis(); }
logger.info("SASL PLAIN authentication enabled ? {}", SASLAuthentication.isSaslMechanismRegistered("PLAIN")); logger.info("Is compression enabled ? {}", xmppConn.isUsingCompression()); logger.info("Is the connection secure ? {}", xmppConn.isSecureConnection());