Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: SSL XMPPConnection

  1. #11
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Brandon

    It will do the same thing as what we were doing before and that is to initialize DSmackConfiguration statically. We actually have a test cases that validates it. If you are in SI source code then look at XmppConnectionParserTest.testSmackSasl(), otherwise here is the test:
    Code:
    @Test
    public void testSmackSasl(){
    	/*
    	 * Possible SASL mechanisms
    	 * EXTERNAL, GSSAPI, DIGEST-MD5, CRAM-MD5, PLAIN, ANONYMOUS
    	 */
    	// values are set in META-INF/smack-config.xml
    	List<String> saslMechNames = SmackConfiguration.getSaslMechs();
    	assertEquals(2, saslMechNames.size());
    	assertEquals("PLAIN", saslMechNames.get(0));
    }
    Let me know

  2. #12
    Join Date
    Jul 2010
    Posts
    139

    Default

    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.
    Last edited by jzcfk9; Nov 7th, 2010 at 11:49 AM.

  3. #13
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    I am pretty sure it doesn't see your smack-config.xml. Let's try to figure out why. Attached is he simplest Maven project (no spring or spring integration), just two lines of java code
    Code:
    public static void main(String[] args) {
    	List<String> saslMechanisms = SmackConfiguration.getSaslMechs();
    	System.out.println("SASL mechanisms: " + saslMechanisms);
    }
    and two lines of XML in META-INF/smack-config.xml
    Code:
    <smack>
    	<mechName>PLAIN</mechName>
    	<mechName>EXTERNAL</mechName>
    </smack>
    and the output:
    Code:
    SASL mechanisms: [PLAIN, EXTERNAL, PLAIN, EXTERNAL]
    Look at the project structure and let me know what is different
    Attached Files Attached Files

  4. #14
    Join Date
    Jul 2010
    Posts
    139

    Default

    It's definitely seeing the smack-config.xml. I just updated it to add "PLAIN" and now get the following output:

    Code:
    SmackConfiguration.getSaslMechs()=> [EXTERNAL, PLAIN, EXTERNAL, PLAIN]
    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]

  5. #15
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    So, what is the issue?

  6. #16
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Never mind, I see what you are saying, let me look into that more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •