1package CyrusSasl; 2 3import javax.security.auth.callback.*; 4import java.io.*; 5 6public class GenericServer extends GenericCommon implements SaslServer 7{ 8 9 private byte[]initial_response; 10 private String mechanism; 11 private javax.security.auth.callback.CallbackHandler cbh; 12 private boolean started = false; 13 14 /* JNI functions */ 15 private native byte[] jni_sasl_server_start(int ptr, 16 String mech, byte[]in, int inlen); 17 18 private native byte[] jni_sasl_server_step(int ptr, 19 byte[] in, 20 int inlen); 21 22 GenericServer(int cptr, String mechanism, 23 java.util.Hashtable props, 24 javax.security.auth.callback.CallbackHandler cbh) 25 { 26 ptr=cptr; 27 this.cbh = cbh; 28 this.mechanism = mechanism; 29 started = false; 30 31 32 /* set properties */ 33 super.setcommonproperties(props); 34 } 35 36 37 public byte[] evaluateResponse(byte[] response) throws SaslException 38 { 39 byte[] out; 40 byte[] in; 41 int inlen; 42 43 if (response == null) 44 { 45 in=null; 46 inlen = 0; 47 } else { 48 in = response; 49 inlen = response.length; 50 } 51 52 if (started == false) { 53 out=jni_sasl_server_start(ptr, mechanism,in,inlen); 54 started = true; 55 } else { 56 out=jni_sasl_server_step(ptr,in,inlen); 57 } 58 59 return out; 60 } 61 62 public String getMechanismName() 63 { 64 return mechanism; 65 } 66 67 public InputStream getInputStream(InputStream source) throws IOException 68 { 69 if (getSecurity() > 0) { 70 return new SaslInputStream(source,this); 71 } else { 72 // no security layer, no indirection needed 73 return source; 74 } 75 } 76 77 public OutputStream getOutputStream(OutputStream dest) throws IOException 78 { 79 if (getSecurity() > 0) { 80 return new SaslOutputStream(dest,this); 81 } else { 82 // no security layer, no indirection needed 83 return dest; 84 } 85 } 86} 87