Cyrus SASL + Java

Tan Bock Hoe Joe bockhoe at ncs.com.sg
Mon Oct 23 01:36:47 EDT 2006


Hi,

I have Cyrus IMAP installed on a machine together with SASL.
Have done :
1)	saslauthd –v and it works
2)	testsaslauthd –u somebody –p somepassword and it works with entries in LDAP ( verified it by changing password of users in LDAP and running the command )
3)	Checked the configuration files ie. Imapd.conf, saslauthd, cyrus.conf

However when I try to run some java code to create a IMAP session using SASL SSO, it fails :


import javax.mail.Authenticator;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Folder;
import java.util.Properties;

// Probably would not work because IMAP does not have AUTH=PLAIN in 142.254

public class SSOTest {
	public static void main(final String[] args) throws MessagingException {

        // Standard JavaMail stuff
        Properties globalProps = new Properties(System.getProperties());
        globalProps.setProperty("mail.store.protocol", "imap"); // Change to "imaps" if you need IMAP SSL

        final String protocol = globalProps.getProperty("mail.store.protocol");
        globalProps.setProperty("mail." + protocol + ".host", "192.168.142.254");
        if ("imap".equals(protocol)) {
            globalProps.setProperty("mail." + protocol + ".port", "143");
        } else if ("imaps".equals(protocol)) {
            globalProps.setProperty("mail." + protocol + ".port", "993");
        }
        
        //196.168.142.254

        // JavaMail SASL stuff
        Properties props = new Properties(globalProps);
        props.setProperty("mail.imap.sasl.authorizationid", "testuser1");
        //props.setProperty("mail.imap.sasl.enable", "true");
        //props.setProperty("mail.imap.sasl.mechanisms", "plain"); 

        AdminAuthenticator adminAuthenticator = new AdminAuthenticator("testuser2", "password");

        // Back to standard JavaMail stuff
        Session session = Session.getInstance(props, adminAuthenticator);
        session.setDebug(true);

        Store store = session.getStore();

        // This wil throw an exception if the login fails
        store.connect();
                      
        Folder folder = store.getDefaultFolder();
        Folder afolder[] = folder.list();

        // Mail box information
        for(int i = 0; i < afolder.length; i++) {
            System.out.println("Folder =" + afolder[i].getName() + " Message Count= " + afolder[i].getMessageCount());
        }

        store.close();
    }

    private static class AdminAuthenticator extends Authenticator {
        String authorizationid, authorizationpass;
        public AdminAuthenticator(final String authorizationid, final String authorizationpass) {
            this.authorizationid = authorizationid;
            this.authorizationpass = authorizationpass;
        }
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(authorizationid, authorizationpass);
        }
    }

}


It keeps getting the folders for the AuthenticatorID instead of the authorizationID. I think it is because the IMAP does not support
AUTH=PLAIN but does AUTH=PLAIN comes with Cyrus IMAP by default?

I’ve read on Java SASL API and tried createSASLClient without much success.

Can anyone provide any pointers to this? Thanks.

Rgds,
joe

-- 
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.1.407 / Virus Database: 268.13.1/466 - Release Date: 10/7/2006
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.andrew.cmu.edu/mailman/private/cyrus-sasl/attachments/20061023/29a08705/attachment.html


More information about the Cyrus-sasl mailing list