directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: rev 55316 - in incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server: . udp
Date Fri, 22 Oct 2004 12:02:50 GMT
Author: erodriguez
Date: Fri Oct 22 05:02:49 2004
New Revision: 55316

Added:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/Connection.java
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/Handler.java
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/Main.java
Log:
Multi-threaded UDP frontend.

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/Connection.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/Connection.java
Fri Oct 22 05:02:49 2004
@@ -0,0 +1,47 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.kerberos.kdc.server.udp;
+
+import org.apache.kerberos.kdc.*;
+
+import java.io.*;
+import java.net.*;
+
+public class Connection implements Runnable {
+	
+	private DatagramSocket _socket;
+	private DatagramPacket _packet;
+	private KdcDispatcher  _kdc;
+	
+	private static Handler handler = new Handler();
+	
+	public Connection(DatagramSocket socket, DatagramPacket packet, KdcDispatcher kdc) {
+		_socket = socket;
+		_packet = packet;
+		_kdc    = kdc;
+	}
+
+	public void run() { 
+		try {
+			handler.process(_socket, _packet, _kdc);
+		}
+		catch (IOException ioe) {
+			System.err.println(ioe);
+		}
+	}
+}
+

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/Handler.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/Handler.java
Fri Oct 22 05:02:49 2004
@@ -0,0 +1,46 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.kerberos.kdc.server.udp;
+ 
+import org.apache.kerberos.kdc.*;
+
+import java.io.*;
+import java.net.*;
+
+public class Handler {
+	
+	public void process(DatagramSocket socket, DatagramPacket packet, KdcDispatcher kdc)
+			throws IOException {
+		
+		try {
+	        System.out.println("Received request with " + packet.getLength() + " bytes.");
+			
+			byte[] replyBytes = kdc.dispatch(packet.getData());
+	
+	        InetAddress address = packet.getAddress();
+	        int port = packet.getPort();
+	        packet = new DatagramPacket(replyBytes, replyBytes.length, address, port);
+	        socket.send(packet);
+	        
+	        System.out.println("Sent reply with " + packet.getLength() + " bytes.");
+
+		} catch (KerberosException ke) {
+			ke.printStackTrace();
+		}
+	}
+}
+

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/Main.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/server/udp/Main.java
Fri Oct 22 05:02:49 2004
@@ -0,0 +1,70 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.kerberos.kdc.server.udp;
+
+import org.apache.kerberos.kdc.*;
+import org.apache.kerberos.kdc.store.*;
+
+import java.io.*;
+import java.net.*;
+
+public class Main {
+
+	public static final int DEFAULT_PORT = 88;
+	public static final int BUFFER_SIZE  = 1024;
+
+	private static final PrincipalStore ldap = new LdapStore();
+	private static final KdcDispatcher kdc   = new KdcDispatcher(ldap);
+	
+	public static void main(String[] args) {
+		System.setProperty("sun.security.krb5.debug", "true");
+		Main m = new Main();
+		m.go();
+	}
+
+	private void go() {
+		DatagramSocket socket = null;
+		try {
+			socket = new DatagramSocket(DEFAULT_PORT);
+			initStore();
+
+			while (true) {
+				byte[] requestBytes = new byte[BUFFER_SIZE];
+
+				DatagramPacket packet = new DatagramPacket(requestBytes, requestBytes.length);
+				socket.receive(packet);
+				
+				Thread worker = new Thread(new Connection(socket, packet, kdc));
+				worker.start();
+			}
+		} catch (IOException ioe) {
+		} finally {
+			if (socket != null)
+				socket.close();
+		}
+	}
+
+	private void initStore() {
+		Thread storeInit = new Thread() {
+			public void run() {
+				ldap.init();
+			}
+		};
+		storeInit.start();
+	}
+}
+

Mime
View raw message