directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: rev 56361 - incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp
Date Tue, 02 Nov 2004 07:08:02 GMT
Author: erodriguez
Date: Mon Nov  1 23:08:02 2004
New Revision: 56361

Added:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/Connection.java
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/Handler.java
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/Main.java
Log:
Multi-threaded UDP front-end for changepw service.

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/Connection.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/Connection.java
Mon Nov  1 23:08:02 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.changepw.udp;
+
+import org.apache.kerberos.changepw.*;
+
+import java.io.*;
+import java.net.*;
+
+public class Connection implements Runnable {
+	
+	private DatagramSocket           _socket;
+	private DatagramPacket           _packet;
+	private ChangePasswordDispatcher _changepw;
+	
+	private static Handler handler = new Handler();
+	
+	public Connection(DatagramSocket socket, DatagramPacket packet, ChangePasswordDispatcher
changepw) {
+		_socket   = socket;
+		_packet   = packet;
+		_changepw = changepw;
+	}
+
+	public void run() { 
+		try {
+			handler.process(_socket, _packet, _changepw);
+		}
+		catch (IOException ioe) {
+			System.err.println(ioe);
+		}
+	}
+}
+

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/Handler.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/Handler.java
Mon Nov  1 23:08:02 2004
@@ -0,0 +1,37 @@
+/*
+ *   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.changepw.udp;
+ 
+import org.apache.kerberos.changepw.*;
+
+import java.io.*;
+import java.net.*;
+
+public class Handler {
+	
+	public void process(DatagramSocket socket, DatagramPacket packet, ChangePasswordDispatcher
changepw)
+		throws IOException {
+		
+			byte[] replyBytes = changepw.dispatch(packet.getData());
+	
+	        InetAddress address = packet.getAddress();
+	        int port = packet.getPort();
+	        packet = new DatagramPacket(replyBytes, replyBytes.length, address, port);
+	        socket.send(packet);
+	}
+}
+

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/Main.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/udp/Main.java
Mon Nov  1 23:08:02 2004
@@ -0,0 +1,74 @@
+/*
+ *   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.changepw.udp;
+
+import org.apache.kerberos.changepw.*;
+import org.apache.kerberos.changepw.store.*;
+import org.apache.kerberos.kdc.*;
+import org.apache.kerberos.kdc.store.*;
+
+import java.io.*;
+import java.net.*;
+
+public class Main {
+
+	private static final KdcConfiguration config           = new KdcConfiguration();
+	private static final BootstrapStore bootstrap          = new BootstrapStore(config);
+	private static final PasswordStore ldap                = new LdapPasswordStore(config, bootstrap);
+	private static final ChangePasswordDispatcher changepw = new ChangePasswordDispatcher(config,
bootstrap, ldap);
+	
+	public static void main(String[] args) {
+		Main m = new Main();
+		m.go();
+	}
+
+	private void go() {
+		
+		init();
+		
+		DatagramSocket socket = null;
+		try {
+			socket = new DatagramSocket(config.getChangepwPort());
+
+			while (true) {
+				byte[] requestBytes = new byte[config.getBufferSize()];
+
+				DatagramPacket packet = new DatagramPacket(requestBytes, requestBytes.length);
+				socket.receive(packet);
+				
+				Thread worker = new Thread(new Connection(socket, packet, changepw));
+				worker.start();
+			}
+		} catch (IOException ioe) {
+			ioe.printStackTrace();
+		} finally {
+			if (socket != null)
+				socket.close();
+		}
+	}
+	
+	private void init() {
+		Thread storeInit = new Thread() {
+			public void run() {
+				bootstrap.init();
+				ldap.init();
+			}
+		};
+		storeInit.start();
+	}
+}
+

Mime
View raw message