1package CyrusSasl; 2 3import java.util.Hashtable; 4import javax.security.auth.callback.*; 5 6class ClientFactory implements SaslClientFactory 7{ 8 9 public ClientFactory() 10 { 11 12 } 13 14 /* JNI functions */ 15 private native int jni_sasl_client_init(String appname); 16 private native int jni_sasl_client_new(String service, 17 String serverFQDN, 18 int secflags, boolean successdata); 19 20 21 private boolean init_client(String appname) 22 { 23 /* load library */ 24 try { 25 System.loadLibrary("javasasl"); 26 } catch (UnsatisfiedLinkError e) { 27 /* xxx */ 28 System.out.println("Unable to load javasasl library"); 29 } 30 31 jni_sasl_client_init(appname); 32 33 return true; 34 } 35 36 /* initialize the client when the class is loaded */ 37 { 38 init_client("javasasl application"); 39 } 40 41 public SaslClient createSaslClient(String[] mechanisms, 42 String authorizationId, 43 String protocol, 44 String serverName, 45 Hashtable props, 46 javax.security.auth.callback.CallbackHandler cbh) 47 throws SaslException 48 { 49 int cptr; 50 boolean successdata = true; 51 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")) { 56 successdata = false; 57 } 58 59 cptr = jni_sasl_client_new(protocol, serverName, 0, successdata); 60 61 if (cptr == 0) { 62 throw new SaslException("Unable to create new Client connection object", new Throwable()); 63 } 64 65 /* create the mechlist the way our library likes to see it */ 66 String mechlist=""; 67 68 for (int lup=0;lup<mechanisms.length;lup++) { 69 mechlist+=mechanisms[lup]; 70 mechlist+=" "; 71 } 72 73 74 return new GenericClient(cptr, mechlist,props,cbh); 75 } 76 77 78 79} 80