OK, I got some time to run the test and the results were what I expected: putting the SASL mechanisms in the META-INF/smack-config.xml didn't translate into support for those mechanisms during the authentication process. Here was my test setup:
TestConfig.java
Code:
package org.mycompany.xmpp;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class TestConfig
{
static ApplicationContext ctx = new FileSystemXmlApplicationContext(
"src/org/mycompany/xmpp/application-context.xml");
public static void main(String[] args) throws Exception
{
XmppConnectionFactoryBean bean = (XmppConnectionFactoryBean) ctx
.getBean(XmppConnectionFactoryBean.class);
bean.createInstance();
System.out.println("SmackConfiguration.getSaslMechs()=> "
+ (SmackConfiguration.getSaslMechs()));
bean.start();
}
}
application-context.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:xmpp="http://www.springframework.org/schema/integration/xmpp"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp-2.0.xsd">
<bean id="xmppConn" class="org.mycompany.xmpp.XmppConnectionFactoryBean">
<constructor-arg>
<bean class="org.jivesoftware.smack.ConnectionConfiguration">
<constructor-arg name="host" value="localhost" />
<constructor-arg name="port" value="5222" />
<property name="SASLAuthenticationEnabled" value="true" />
</bean>
</constructor-arg>
<property name="user" value="test" />
<property name="password" value="test" />
</bean>
</beans>
META-INF/smack-config.xml:
Code:
<smack>
<mechName>EXTERNAL</mechName>
</smack>
I also took the liberty to add some debug info inside of XmppConnectionFactoryBean:
Code:
@Override
public void start()
{
try
{
connection.connect();
System.out.println("before=>"
+ (SASLAuthentication.getRegisterSASLMechanisms()));
SASLAuthentication.supportSASLMechanism("EXTERNAL", 0);
System.out.println("after=>"
+ (SASLAuthentication.getRegisterSASLMechanisms()));
...
Here was the result of running TestConfig:
Code:
Nov 7, 2010 12:25:50 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@145d068: startup date [Sun Nov 07 12:25:50 EST 2010]; root of context hierarchy
Nov 7, 2010 12:25:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\Users\mccusln\workspace-sts-2.3.2\test\src\org\mycompany\xmpp\application-context.xml]
Nov 7, 2010 12:25:51 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@f7f540: defining beans [xmppConn]; root of factory hierarchy
SmackConfiguration.getSaslMechs()=> [EXTERNAL, EXTERNAL]
before=>[class org.jivesoftware.smack.sasl.SASLGSSAPIMechanism, class org.jivesoftware.smack.sasl.SASLDigestMD5Mechanism, class org.jivesoftware.smack.sasl.SASLCramMD5Mechanism, class org.jivesoftware.smack.sasl.SASLPlainMechanism, class org.jivesoftware.smack.sasl.SASLAnonymous]
after=>[class org.jivesoftware.smack.sasl.SASLExternalMechanism, class org.jivesoftware.smack.sasl.SASLGSSAPIMechanism, class org.jivesoftware.smack.sasl.SASLDigestMD5Mechanism, class org.jivesoftware.smack.sasl.SASLCramMD5Mechanism, class org.jivesoftware.smack.sasl.SASLPlainMechanism, class org.jivesoftware.smack.sasl.SASLAnonymous]
You can see that before I called SASLAuthentication.supportSASLMechanism("EXTERNAL" , 0); inside of XmppConnectionFactoryBean, smack never registered SASLExternalMechanism as a registered mechanism. Regardless of what the output from SmackConfiguration.getSaslMechs() says, I know that smack uses the mechanisms stored inside of SASLAuthentication when determining how or handle authentication requests. My guess is most people are using the mechanisms registered by default (i.e. plain or anonymous) so this issue never has come up as people have never had to specify anything other than the defaults. In my case, I need X.509 client authentication by all my smack clients.
Maybe this is why the previous XmppConnectionFactory class was doing it the way it was.