1 36 package org.columba.ristretto.auth.mechanism; 37 38 import java.io.IOException ; 39 import java.util.Arrays ; 40 import java.util.LinkedList ; 41 import java.util.List ; 42 43 import org.columba.ristretto.auth.AuthenticationException; 44 import org.columba.ristretto.auth.AuthenticationServer; 45 46 public class TestAuthServer implements AuthenticationServer { 47 48 private String result; 49 private boolean ok = true; 50 51 private List calls; 52 private List responses; 53 private int call_nr; 54 private int response_nr; 55 56 public TestAuthServer() { 57 calls = new LinkedList (); 58 responses = new LinkedList (); 59 60 response_nr = call_nr = 0; 61 } 62 63 66 public void authSend(byte[] call) throws IOException { 67 if( calls.size() > call_nr) { 68 ok = ok && Arrays.equals(call, (byte[]) calls.get(call_nr++)); 69 } 70 } 71 72 75 public byte[] authReceive() throws AuthenticationException, IOException { 76 if( !ok ) throw new AuthenticationException(); 77 if( response_nr < responses.size()) { 78 return (byte[]) responses.get(response_nr++); 79 } else { 80 return new byte[0]; 81 } 82 } 83 84 public void addCall(byte[] call) { 85 calls.add(call); 86 } 87 88 public void addResponse(byte[] response) { 89 responses.add( response ); 90 } 91 92 95 public TestAuthServer(byte[] result) { 96 this(); 97 98 calls.add(result); 99 } 100 103 public String getHostName() { 104 return "testserver"; 105 } 106 109 public String getService() { 110 return "test"; 111 } 112 115 public boolean isOk() { 116 return ok; 117 } 118 } 119 | Popular Tags |