directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r537722 - in /directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo: GSSClient.java GSSClientApplet.java GSSServer.java GSSServerThread.java
Date Mon, 14 May 2007 06:12:14 GMT
Author: erodriguez
Date: Sun May 13 23:12:14 2007
New Revision: 537722

URL: http://svn.apache.org/viewvc?view=rev&rev=537722
Log:
Updates to old GSS example code:
o  Reformat.
o  Organize imports.

Modified:
    directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClient.java
    directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClientApplet.java
    directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServer.java
    directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServerThread.java

Modified: directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClient.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClient.java?view=diff&rev=537722&r1=537721&r2=537722
==============================================================================
--- directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClient.java
(original)
+++ directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClient.java
Sun May 13 23:12:14 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.kerberos.examples.gssdemo;
 
+
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -27,7 +28,7 @@
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
 
-import org.apache.kerberos.jaas.CallbackHandlerBean;
+import org.apache.directory.server.kerberos.shared.jaas.CallbackHandlerBean;
 import org.ietf.jgss.GSSContext;
 import org.ietf.jgss.GSSCredential;
 import org.ietf.jgss.GSSException;
@@ -36,173 +37,177 @@
 import org.ietf.jgss.MessageProp;
 import org.ietf.jgss.Oid;
 
+
 class GSSClient implements PrivilegedAction
 {
 
-	private CallbackHandlerBean beanCallbackHandler = null;
+    private CallbackHandlerBean beanCallbackHandler = null;
 
-	private static final int TEN_MINUTES = 10 * 60;
+    private static final int TEN_MINUTES = 10 * 60;
 
-	private GSSContext context = null;
+    private GSSContext context = null;
 
-	private LoginContext peerLC = null;
+    private LoginContext peerLC = null;
 
-	private Socket socket = null;
-	private DataInputStream inStream;
-	private DataOutputStream outStream;
+    private Socket socket = null;
+    private DataInputStream inStream;
+    private DataOutputStream outStream;
 
-	private String clientName = null;
-	private String serverName = null;
-	private String serverAddress = null;
-	private int serverPort;
+    private String clientName = null;
+    private String serverName = null;
+    private String serverAddress = null;
+    private int serverPort;
 
-	public GSSClient(String clientName, String password, String serverName, String serverAddress,
-			int serverPort, String kerberosRealm, String kdcAddress)
+
+    public GSSClient( String clientName, String password, String serverName, String serverAddress,
int serverPort,
+        String kerberosRealm, String kdcAddress )
     {
-		beanCallbackHandler = new CallbackHandlerBean(clientName, password);
-		this.clientName = clientName;
-		this.serverName = serverName;
-		this.serverAddress = serverAddress;
-		this.serverPort = serverPort;
-		System.setProperty("java.security.krb5.realm", kerberosRealm);
-		System.setProperty("java.security.krb5.kdc", kdcAddress);
+        beanCallbackHandler = new CallbackHandlerBean( clientName, password );
+        this.clientName = clientName;
+        this.serverName = serverName;
+        this.serverAddress = serverAddress;
+        this.serverPort = serverPort;
+        System.setProperty( "java.security.krb5.realm", kerberosRealm );
+        System.setProperty( "java.security.krb5.kdc", kdcAddress );
+
+        System.setProperty( "sun.security.krb5.debug", "true" );
+        Security.setProperty( "login.configuration.provider", "org.apache.kerberos.kdc.jaas.Krb5LoginConfiguration"
);
+    }
 
-		System.setProperty("sun.security.krb5.debug", "true");
-		Security.setProperty("login.configuration.provider",
-				"org.apache.kerberos.kdc.jaas.Krb5LoginConfiguration");
-	}
 
-	public void login()
+    public void login()
     {
-		try
+        try
         {
-			peerLC = new LoginContext(clientName, beanCallbackHandler);
-			peerLC.login();
+            peerLC = new LoginContext( clientName, beanCallbackHandler );
+            peerLC.login();
 
-			socket = new Socket(serverAddress, serverPort);
-			inStream = new DataInputStream(socket.getInputStream());
-			outStream = new DataOutputStream(socket.getOutputStream());
+            socket = new Socket( serverAddress, serverPort );
+            inStream = new DataInputStream( socket.getInputStream() );
+            outStream = new DataOutputStream( socket.getOutputStream() );
 
-			context = (GSSContext) Subject.doAs(peerLC.getSubject(), this);
-		}
-        catch (Exception e)
+            context = ( GSSContext ) Subject.doAs( peerLC.getSubject(), this );
+        }
+        catch ( Exception e )
         {
-			System.out.println(">>> GSSClient ... Secure Context not established.");
-			System.out.println(">>> GSSClient ... ERROR:  " + e.getMessage());
-		}
-	}
+            System.out.println( ">>> GSSClient ... Secure Context not established."
);
+            System.out.println( ">>> GSSClient ... ERROR:  " + e.getMessage() );
+        }
+    }
 
-	public boolean hasConfidentialContext()
+
+    public boolean hasConfidentialContext()
     {
-		return context != null && context.getConfState();
-	}
+        return context != null && context.getConfState();
+    }
+
 
-	// PrivilegedAction method
-	public Object run()
+    // PrivilegedAction method
+    public Object run()
     {
-		try
+        try
         {
-			GSSManager manager = GSSManager.getInstance();
-			
-			Oid kerberos = new Oid("1.2.840.113554.1.2.2");
+            GSSManager manager = GSSManager.getInstance();
 
-			GSSName clientPeerName = manager.createName(clientName, GSSName.NT_USER_NAME);
+            Oid kerberos = new Oid( "1.2.840.113554.1.2.2" );
 
-			GSSName remotePeerName = manager.createName(serverName, GSSName.NT_USER_NAME);
+            GSSName clientPeerName = manager.createName( clientName, GSSName.NT_USER_NAME
);
 
-			System.out.println(">>> GSSClient ... Getting client credentials");
+            GSSName remotePeerName = manager.createName( serverName, GSSName.NT_USER_NAME
);
 
-			GSSCredential peerCredentials = manager.createCredential(clientPeerName, TEN_MINUTES,
-					kerberos, GSSCredential.INITIATE_ONLY);
+            System.out.println( ">>> GSSClient ... Getting client credentials" );
 
-			System.out.println(">>> GSSClient ... GSSManager creating security context");
-			GSSContext peerContext = manager.createContext(remotePeerName, kerberos,
-					peerCredentials, GSSContext.DEFAULT_LIFETIME);
+            GSSCredential peerCredentials = manager.createCredential( clientPeerName, TEN_MINUTES,
kerberos,
+                GSSCredential.INITIATE_ONLY );
 
-			peerContext.requestConf(true);
-			byte[] byteToken = new byte[0];
+            System.out.println( ">>> GSSClient ... GSSManager creating security
context" );
+            GSSContext peerContext = manager.createContext( remotePeerName, kerberos, peerCredentials,
+                GSSContext.DEFAULT_LIFETIME );
 
-			System.out.println(">>> GSSClient ... Sending token to server over secure context");
+            peerContext.requestConf( true );
+            byte[] byteToken = new byte[0];
 
-			while (!peerContext.isEstablished())
+            System.out.println( ">>> GSSClient ... Sending token to server over
secure context" );
+
+            while ( !peerContext.isEstablished() )
             {
-				byteToken = peerContext.initSecContext(byteToken, 0, byteToken.length);
+                byteToken = peerContext.initSecContext( byteToken, 0, byteToken.length );
 
-				if (byteToken != null)
+                if ( byteToken != null )
                 {
-					outStream.writeInt(byteToken.length);
-					outStream.write(byteToken);
-					outStream.flush();
-				}
+                    outStream.writeInt( byteToken.length );
+                    outStream.write( byteToken );
+                    outStream.flush();
+                }
 
-				if (!peerContext.isEstablished())
+                if ( !peerContext.isEstablished() )
                 {
-					byteToken = new byte[inStream.readInt()];
-					inStream.readFully(byteToken);
-				}
-			}
-
-			return peerContext;
-		}
-        catch (GSSException ge)
-        {
-			System.out.println(">>> GSSClient ... GSS Exception " + ge.getMessage());
-		}
-        catch (IOException e)
-        {
-			System.out.println(">>> GSSClient ... Exception " + e.getMessage());
-		}
-		return null;
-	}
-
-	public String sendMessageReturnReply(String message)
-    {
-		MessageProp msgProp = new MessageProp(0, true);
-
-		try
-        {
-			System.out.println(">>> GSSClient ... Client message is [" + message + "]");
-			byte[] clientMessage = context.wrap(message.getBytes(), 0, message.getBytes().length,
-					msgProp);
-			outStream.writeInt(clientMessage.length);
-			outStream.write(clientMessage);
-			outStream.flush();
-
-			// Receiving server response and sending back to client.
-			byte[] serverMessage = new byte[inStream.readInt()];
-			inStream.readFully(serverMessage);
-			serverMessage = context.unwrap(serverMessage, 0, serverMessage.length, msgProp);
-			System.out.print(">>> GSSClient ... Server message is [");
-			System.out.println(new String(serverMessage) + "]");
-			return new String(serverMessage);
-		}
-        catch (GSSException ge)
-        {
-			ge.printStackTrace();
-			return null;
-		}
-        catch (IOException ioe)
-        {
-			ioe.printStackTrace();
-			return null;
-		}
-	}
-
-	public void logout()
-    {
-		try
-        {
-			peerLC.logout();
-			context.dispose();
-		}
-        catch (LoginException le)
-        {
-			le.printStackTrace();
-		}
-        catch (GSSException ge)
-        {
-			ge.printStackTrace();
-		}
-	}
+                    byteToken = new byte[inStream.readInt()];
+                    inStream.readFully( byteToken );
+                }
+            }
+
+            return peerContext;
+        }
+        catch ( GSSException ge )
+        {
+            System.out.println( ">>> GSSClient ... GSS Exception " + ge.getMessage()
);
+        }
+        catch ( IOException e )
+        {
+            System.out.println( ">>> GSSClient ... Exception " + e.getMessage()
);
+        }
+        return null;
+    }
+
+
+    public String sendMessageReturnReply( String message )
+    {
+        MessageProp msgProp = new MessageProp( 0, true );
+
+        try
+        {
+            System.out.println( ">>> GSSClient ... Client message is [" + message
+ "]" );
+            byte[] clientMessage = context.wrap( message.getBytes(), 0, message.getBytes().length,
msgProp );
+            outStream.writeInt( clientMessage.length );
+            outStream.write( clientMessage );
+            outStream.flush();
+
+            // Receiving server response and sending back to client.
+            byte[] serverMessage = new byte[inStream.readInt()];
+            inStream.readFully( serverMessage );
+            serverMessage = context.unwrap( serverMessage, 0, serverMessage.length, msgProp
);
+            System.out.print( ">>> GSSClient ... Server message is [" );
+            System.out.println( new String( serverMessage ) + "]" );
+            return new String( serverMessage );
+        }
+        catch ( GSSException ge )
+        {
+            ge.printStackTrace();
+            return null;
+        }
+        catch ( IOException ioe )
+        {
+            ioe.printStackTrace();
+            return null;
+        }
+    }
+
+
+    public void logout()
+    {
+        try
+        {
+            peerLC.logout();
+            context.dispose();
+        }
+        catch ( LoginException le )
+        {
+            le.printStackTrace();
+        }
+        catch ( GSSException ge )
+        {
+            ge.printStackTrace();
+        }
+    }
 }
-

Modified: directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClientApplet.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClientApplet.java?view=diff&rev=537722&r1=537721&r2=537722
==============================================================================
--- directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClientApplet.java
(original)
+++ directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSClientApplet.java
Sun May 13 23:12:14 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.kerberos.examples.gssdemo;
 
+
 import java.applet.Applet;
 import java.awt.Button;
 import java.awt.Color;
@@ -26,102 +27,104 @@
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
+
 public class GSSClientApplet extends Applet
 {
+    private GSSClient gssClient = null;
 
-	private GSSClient gssClient = null;
+    // UI parameters
+    private Label lblUserName = new Label( "Username:" );
+    private Label lblPassword = new Label( "Password:" );
 
-	// UI parameters
-	private Label lblUserName = new Label("Username:");
-	private Label lblPassword = new Label("Password:");
+    private TextField tfUserName = new TextField( 12 );
+    private TextField tfPassword = new TextField( 12 );
 
-	private TextField tfUserName = new TextField(12);
-	private TextField tfPassword = new TextField(12);
+    private Button buttonPartner1 = new Button( "  Login to ldap  " );
 
-	private Button buttonPartner1 = new Button("  Login to ldap  ");
+    private Color bgColor = new Color( 204, 204, 255 );
 
-	private Color bgColor = new Color(204, 204, 255);
+    private TextArea taResponse = null;
 
-	private TextArea taResponse = null;
+    // GSS parameters.
+    private String remotePeer = null;
+    private String kerberosRealm = null;
+    private String kdcAddress = null;
+    private String addressOfRemotePeer = null;
+    private int portOfRemotePeer;
 
-	// GSS parameters.
-	private String remotePeer = null;
-	private String kerberosRealm = null;
-	private String kdcAddress = null;
-	private String addressOfRemotePeer = null;
-	private int portOfRemotePeer;
 
-	public void init()
+    public void init()
     {
-		setLayout(new FlowLayout(FlowLayout.CENTER));
-		add(lblUserName);
-		add(tfUserName);
-		add(lblPassword);
-		add(tfPassword);
-
-		buttonPartner1.setBackground(bgColor);
-
-		kerberosRealm       = "25OZ.COM";
-		kdcAddress          = "localhost";
-		addressOfRemotePeer = "localhost";
-
-		add(buttonPartner1);
-		buttonPartner1.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent evt) {
-				remotePeer = "ldap";
-				portOfRemotePeer = 1082;
-				login();
-			}
-		});
-
-		taResponse = new TextArea("[Output Window] ...\n\r", 12, 58);
-		taResponse.setBackground(Color.white);
-		add(taResponse);
-	}
+        setLayout( new FlowLayout( FlowLayout.CENTER ) );
+        add( lblUserName );
+        add( tfUserName );
+        add( lblPassword );
+        add( tfPassword );
+
+        buttonPartner1.setBackground( bgColor );
+
+        kerberosRealm = "25OZ.COM";
+        kdcAddress = "localhost";
+        addressOfRemotePeer = "localhost";
+
+        add( buttonPartner1 );
+        buttonPartner1.addActionListener( new ActionListener()
+        {
+            public void actionPerformed( ActionEvent evt )
+            {
+                remotePeer = "ldap";
+                portOfRemotePeer = 1082;
+                login();
+            }
+        } );
+
+        taResponse = new TextArea( "[Output Window] ...\n\r", 12, 58 );
+        taResponse.setBackground( Color.white );
+        add( taResponse );
+    }
 
-	private void login()
+
+    private void login()
     {
-		try
+        try
         {
-			if (tfUserName.getText().equals("") && tfPassword.getText().equals(""))
-				taResponse.append("Please use your username to login ...\n\r");
-			else
+            if ( tfUserName.getText().equals( "" ) && tfPassword.getText().equals(
"" ) )
+                taResponse.append( "Please use your username to login ...\n\r" );
+            else
             {
-				gssClient = new GSSClient(tfUserName.getText() + "@" + kerberosRealm,
-						tfPassword.getText(), remotePeer, addressOfRemotePeer,
-						portOfRemotePeer, kerberosRealm, kdcAddress);
-
-				taResponse.append(tfUserName.getText() + " being logged in ...\n\r");
-				
-				gssClient.login();
-				
-				if (gssClient.hasConfidentialContext())
+                gssClient = new GSSClient( tfUserName.getText() + "@" + kerberosRealm, tfPassword.getText(),
+                    remotePeer, addressOfRemotePeer, portOfRemotePeer, kerberosRealm, kdcAddress
);
+
+                taResponse.append( tfUserName.getText() + " being logged in ...\n\r" );
+
+                gssClient.login();
+
+                if ( gssClient.hasConfidentialContext() )
                 {
-					String message = new String("Sample secret message from client");
-					taResponse.append("You are successfully logged in ... \n\r");
-					taResponse.append("Sending [" + message + "] to server \n\r");
-					String response = gssClient.sendMessageReturnReply(message);
-					taResponse.append("Server response ... " + response + "\n\r");
-				}
+                    String message = new String( "Sample secret message from client" );
+                    taResponse.append( "You are successfully logged in ... \n\r" );
+                    taResponse.append( "Sending [" + message + "] to server \n\r" );
+                    String response = gssClient.sendMessageReturnReply( message );
+                    taResponse.append( "Server response ... " + response + "\n\r" );
+                }
                 else
                 {
-					taResponse.append("Confidential context failed. \n\r");
-				}
+                    taResponse.append( "Confidential context failed. \n\r" );
+                }
 
-				try
+                try
                 {
-					gssClient.logout();
-				}
-                catch (Exception e)
+                    gssClient.logout();
+                }
+                catch ( Exception e )
                 {
-					e.printStackTrace();
-				}
-			}
-		}
-        catch (Exception e)
+                    e.printStackTrace();
+                }
+            }
+        }
+        catch ( Exception e )
         {
-			taResponse.append("Exception ..." + e.getMessage() + "\n\r");
-		}
-	}
+            taResponse.append( "Exception ..." + e.getMessage() + "\n\r" );
+        }
+    }
 }
-

Modified: directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServer.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServer.java?view=diff&rev=537722&r1=537721&r2=537722
==============================================================================
--- directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServer.java
(original)
+++ directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServer.java
Sun May 13 23:12:14 2007
@@ -16,11 +16,11 @@
  */
 package org.apache.kerberos.examples.gssdemo;
 
+
 public class GSSServer
 {
-    public static void main(String[] args)
+    public static void main( String[] args )
     {
         new GSSServerThread().startServer();
     }
 }
-

Modified: directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServerThread.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServerThread.java?view=diff&rev=537722&r1=537721&r2=537722
==============================================================================
--- directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServerThread.java
(original)
+++ directory/clients/trunk/kerberos/examples/src/main/java/org/apache/kerberos/examples/gssdemo/GSSServerThread.java
Sun May 13 23:12:14 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.kerberos.examples.gssdemo;
 
+
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.net.ServerSocket;
@@ -26,7 +27,7 @@
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
 
-import org.apache.kerberos.jaas.CallbackHandlerBean;
+import org.apache.directory.server.kerberos.shared.jaas.CallbackHandlerBean;
 import org.ietf.jgss.GSSContext;
 import org.ietf.jgss.GSSCredential;
 import org.ietf.jgss.GSSManager;
@@ -34,142 +35,141 @@
 import org.ietf.jgss.MessageProp;
 import org.ietf.jgss.Oid;
 
+
 public class GSSServerThread implements PrivilegedAction
 {
+    //Handles callback from the JAAS framework.
+    CallbackHandlerBean beanCallbackHandler = null;
 
-	//Handles callback from the JAAS framework.
-	CallbackHandlerBean beanCallbackHandler = null;
+    //The main object that handles all JAAS login.
+    LoginContext serverLC = null;
 
-	//The main object that handles all JAAS login.
-	LoginContext serverLC = null;
+    //The context for secure communication with client.
+    GSSContext serverGSSContext = null;
 
-	//The context for secure communication with client.
-	GSSContext serverGSSContext = null;
+    //Socket and streams used for communication.
+    ServerSocket serverSocket = null;
+    DataInputStream inStream = null;
+    DataOutputStream outStream = null;
+
+    //Name and port of server.
+    private String _serverName;
+    private int _serverPort;
+    private String _password;
+    private String _realm;
+    private String _kdc;
+
+    //Configuration file and the name of the client configuration.
+    String _confFile = null;
+    String _confName = null;
 
-	//Socket and streams used for communication.
-	ServerSocket serverSocket = null;
-	DataInputStream inStream = null;
-	DataOutputStream outStream = null;
-
-	//Name and port of server.
-	private String _serverName;
-	private int    _serverPort;
-	private String _password;
-	private String _realm;
-	private String _kdc;
-
-	//Configuration file and the name of the client configuration.
-	String _confFile = null;
-	String _confName = null;
 
-	// GSSServerThread constructor
-	public GSSServerThread()
+    // GSSServerThread constructor
+    public GSSServerThread()
     {
+        _serverName = "ldap";
+        _password = "keyrand";
+        _serverPort = 1082;
+        _realm = "25OZ.COM";
+        _kdc = "enrique.25oz.com";
+
+        beanCallbackHandler = new CallbackHandlerBean( _serverName, _password );
+        System.setProperty( "java.security.krb5.realm", _realm );
+        System.setProperty( "java.security.krb5.kdc", _kdc );
+        System.setProperty( "sun.security.krb5.debug", "true" );
+        Security.setProperty( "login.configuration.provider", "org.apache.kerberos.kdc.jaas.Krb5LoginConfiguration"
);
+    }
 
-		_serverName = "ldap";
-		_password   = "keyrand";
-		_serverPort = 1082;
-		_realm      = "25OZ.COM";
-		_kdc        = "enrique.25oz.com";
-
-		beanCallbackHandler = new CallbackHandlerBean(_serverName, _password);
-		System.setProperty("java.security.krb5.realm", _realm);
-		System.setProperty("java.security.krb5.kdc", _kdc);
-		System.setProperty("sun.security.krb5.debug", "true");
-		Security.setProperty("login.configuration.provider",
-				"org.apache.kerberos.kdc.jaas.Krb5LoginConfiguration");
-	}
 
-	public boolean startServer()
+    public boolean startServer()
     {
-
-		try
+        try
         {
-			serverLC = new LoginContext(_serverName, beanCallbackHandler);
-			serverLC.login();
-			Subject.doAs(serverLC.getSubject(), this);
-			return true;
-		}
-        catch (Exception e)
+            serverLC = new LoginContext( _serverName, beanCallbackHandler );
+            serverLC.login();
+            Subject.doAs( serverLC.getSubject(), this );
+            return true;
+        }
+        catch ( Exception e )
         {
-			System.out.println(">>> GSSServerThread ... Secure Context not established..");
-			e.printStackTrace();
-			return false;
-		}
-	}
+            System.out.println( ">>> GSSServerThread ... Secure Context not established.."
);
+            e.printStackTrace();
+            return false;
+        }
+    }
 
-	public Object run()
+
+    public Object run()
     {
-		while (true)
+        while ( true )
         {
-			try
+            try
             {
-				serverSocket = new ServerSocket(_serverPort);
-				GSSManager manager = GSSManager.getInstance();
-				Oid kerberos = new Oid("1.2.840.113554.1.2.2");
+                serverSocket = new ServerSocket( _serverPort );
+                GSSManager manager = GSSManager.getInstance();
+                Oid kerberos = new Oid( "1.2.840.113554.1.2.2" );
 
-				System.out.println(">>> GSSServerThread started ... Waiting for incoming connection");
+                System.out.println( ">>> GSSServerThread started ... Waiting for
incoming connection" );
 
-				GSSName serverGSSName = manager.createName(_serverName, null);
-				GSSCredential serverGSSCreds = manager.createCredential(serverGSSName,
-						GSSCredential.INDEFINITE_LIFETIME, kerberos, GSSCredential.ACCEPT_ONLY);
+                GSSName serverGSSName = manager.createName( _serverName, null );
+                GSSCredential serverGSSCreds = manager.createCredential( serverGSSName,
+                    GSSCredential.INDEFINITE_LIFETIME, kerberos, GSSCredential.ACCEPT_ONLY
);
 
-				serverGSSContext = manager.createContext(serverGSSCreds);
+                serverGSSContext = manager.createContext( serverGSSCreds );
 
-				Socket clientSocket = serverSocket.accept();
-				inStream = new DataInputStream(clientSocket.getInputStream());
-				outStream = new DataOutputStream(clientSocket.getOutputStream());
+                Socket clientSocket = serverSocket.accept();
+                inStream = new DataInputStream( clientSocket.getInputStream() );
+                outStream = new DataOutputStream( clientSocket.getOutputStream() );
 
-				byte[] byteToken = null;
+                byte[] byteToken = null;
 
-				while (!serverGSSContext.isEstablished())
+                while ( !serverGSSContext.isEstablished() )
                 {
-					byteToken = new byte[inStream.readInt()];
-					inStream.readFully(byteToken);
-					byteToken = serverGSSContext.acceptSecContext(byteToken, 0, byteToken.length);
+                    byteToken = new byte[inStream.readInt()];
+                    inStream.readFully( byteToken );
+                    byteToken = serverGSSContext.acceptSecContext( byteToken, 0, byteToken.length
);
 
-					if (byteToken != null)
+                    if ( byteToken != null )
                     {
-						outStream.writeInt(byteToken.length);
-						outStream.write(byteToken);
-						outStream.flush();
-					}
-				}
-
-				String clientName = serverGSSContext.getTargName().toString();
-				String serverName = serverGSSContext.getSrcName().toString();
-				MessageProp msgProp = new MessageProp(0, false);
-
-				byteToken = new byte[inStream.readInt()];
-				inStream.readFully(byteToken);
-
-				// Unwrapping and verifying the received message.
-				byte[] message = serverGSSContext.unwrap(byteToken, 0, byteToken.length, msgProp);
-				System.out.print(">>> GSSServerThread Message [ ");
-				System.out.println(new String(message) + " ] received");
-
-				// Wrapping the response message.
-				message = new String(">>> GSSServerThread Secure Context established between
" + "["
-						+ clientName + "] and [" + serverName + "]").getBytes();
-
-				byte[] secureMessage = serverGSSContext.wrap(message, 0, message.length, msgProp);
-
-				outStream.writeInt(secureMessage.length);
-				outStream.write(secureMessage);
-				outStream.flush();
-				System.out.println(">>> GSSServerThread Message [" + new String(message) + "]
sent");
-
-				// Disposing and closing client and server sockets.
-				serverGSSContext.dispose();
-				clientSocket.close();
-				serverSocket.close();
-				System.out.println(">>> GSSServerThread waiting ... ");
-			}
-            catch (java.lang.Exception e)
+                        outStream.writeInt( byteToken.length );
+                        outStream.write( byteToken );
+                        outStream.flush();
+                    }
+                }
+
+                String clientName = serverGSSContext.getTargName().toString();
+                String serverName = serverGSSContext.getSrcName().toString();
+                MessageProp msgProp = new MessageProp( 0, false );
+
+                byteToken = new byte[inStream.readInt()];
+                inStream.readFully( byteToken );
+
+                // Unwrapping and verifying the received message.
+                byte[] message = serverGSSContext.unwrap( byteToken, 0, byteToken.length,
msgProp );
+                System.out.print( ">>> GSSServerThread Message [ " );
+                System.out.println( new String( message ) + " ] received" );
+
+                // Wrapping the response message.
+                message = new String( ">>> GSSServerThread Secure Context established
between " + "[" + clientName
+                    + "] and [" + serverName + "]" ).getBytes();
+
+                byte[] secureMessage = serverGSSContext.wrap( message, 0, message.length,
msgProp );
+
+                outStream.writeInt( secureMessage.length );
+                outStream.write( secureMessage );
+                outStream.flush();
+                System.out.println( ">>> GSSServerThread Message [" + new String(
message ) + "] sent" );
+
+                // Disposing and closing client and server sockets.
+                serverGSSContext.dispose();
+                clientSocket.close();
+                serverSocket.close();
+                System.out.println( ">>> GSSServerThread waiting ... " );
+            }
+            catch ( java.lang.Exception e )
             {
-				e.printStackTrace();
-			}
-		}
-	}
+                e.printStackTrace();
+            }
+        }
+    }
 }
-



Mime
View raw message