3 import java.util.Hashtable;
4 import javax.security.auth.callback.*;
6 class ClientFactory implements SaslClientFactory
15 private native int jni_sasl_client_init(String appname);
16 private native int jni_sasl_client_new(String service,
18 int secflags, boolean successdata);
21 private boolean init_client(String appname)
25 System.loadLibrary("javasasl");
26 } catch (UnsatisfiedLinkError e) {
28 System.out.println("Unable to load javasasl library");
31 jni_sasl_client_init(appname);
36 /* initialize the client when the class is loaded */
38 init_client("javasasl application");
41 public SaslClient createSaslClient(String[] mechanisms,
42 String authorizationId,
46 javax.security.auth.callback.CallbackHandler cbh)
50 boolean successdata = true;
52 // here's a list of protocols we know don't have success data
53 if (protocol.equals("imap") ||
54 protocol.equals("pop3") ||
55 protocol.equals("smtp")) {
59 cptr = jni_sasl_client_new(protocol, serverName, 0, successdata);
62 throw new SaslException("Unable to create new Client connection object", new Throwable());
65 /* create the mechlist the way our library likes to see it */
68 for (int lup=0;lup<mechanisms.length;lup++) {
69 mechlist+=mechanisms[lup];
74 return new GenericClient(cptr, mechlist,props,cbh);