[jboss-cvs] JBossAS SVN: r110567 - in projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core: security and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 9 11:52:09 EST 2011


Author: jesper.pedersen
Date: 2011-02-09 11:52:09 -0500 (Wed, 09 Feb 2011)
New Revision: 110567

Added:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Auth.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Close.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Connect.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/EISServer.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Echo.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Interaction.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Invoker.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/ReauthServer.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SecurityActions.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SimpleCRI.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/package.html
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/EISTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/package.html
Log:
[JBJCA-94] Reauthentication test eis server

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Auth.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Auth.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Auth.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents an auth command
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Auth implements Invoker
+{
+   /** The key */
+   public static final byte KEY = 3;
+
+   /** The logger */
+   private Logger log = Logger.getLogger(Auth.class);
+
+   /**
+    * Auth
+    */
+   public Auth()
+   {
+   }
+
+   /**
+    * Invoke
+    * @param args The arguments
+    * @return The return value
+    */
+   public Serializable invoke(Serializable[] args)
+   {
+      if (args == null || args.length != 2)
+         return new IllegalArgumentException("Unsupported argument list: " + Arrays.toString(args));
+
+      String userName = (String)args[0];
+      String password = (String)args[1];
+
+      log.infof("UserName=%s Password=%s", userName, password);
+
+      return userName;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Close.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Close.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Close.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import java.io.Serializable;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a close command
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Close implements Invoker
+{
+   /** The key */
+   public static final byte KEY = 1;
+
+   /** The logger */
+   private Logger log = Logger.getLogger(Close.class);
+
+   /**
+    * Constructor
+    */
+   public Close()
+   {
+   }
+
+   /**
+    * Invoke
+    * @param args The arguments
+    * @return The return value
+    */
+   public Serializable invoke(Serializable[] args)
+   {
+      return new UnsupportedOperationException("Unsupported operation: close");
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Connect.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Connect.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Connect.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a connect command
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Connect implements Invoker
+{
+   /** The key */
+   public static final byte KEY = 0;
+
+   /** The logger */
+   private Logger log = Logger.getLogger(Connect.class);
+
+   /**
+    * Constructor
+    */
+   public Connect()
+   {
+   }
+
+   /**
+    * Invoke
+    * @param args The arguments
+    * @return The return value
+    */
+   public Serializable invoke(Serializable[] args)
+   {
+      if (args == null || args.length != 1)
+         return new IllegalArgumentException("Unsupported argument list: " + Arrays.toString(args));
+
+      Serializable s = args[0];
+
+      log.infof("S=%s", s);
+
+      return s;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/EISServer.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/EISServer.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/EISServer.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,206 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jboss.logging.Logger;
+
+/**
+ * The reauthentication EIS server
+ * @author <a href="mailto:jesper.pedersen at comcast.net">Jesper Pedersen</a>
+ */
+public class EISServer implements Runnable
+{
+   /** The logger */
+   private Logger log = Logger.getLogger(EISServer.class);
+
+   /** The bind address */
+   private String bindAddress;
+
+   /** The bind port */
+   private int bindPort;
+
+   /** Maximum number of connections */
+   private int maxConnections;
+
+   /** Is the server running ? */
+   private AtomicBoolean running;
+
+   /** Shutdown */
+   private CountDownLatch shutdown;
+
+   /** Current number of valid connections */
+   private AtomicInteger validConnections;
+
+   /** The server socket */
+   private ServerSocket ss;
+
+   /** The thread pool */
+   private ThreadPoolExecutor tpe;
+
+   /**
+    * Constructor
+    * @param bindAddress The bind address
+    * @param bindPort The bind port
+    * @param maxConnections The maximum number of connections
+    * @exception IOException Thrown if a server socket can not be created
+    */
+   public EISServer(String bindAddress, int bindPort, int maxConnections) throws IOException
+   {
+      if (bindAddress == null)
+         bindAddress = "localhost";
+
+      this.bindAddress = bindAddress;
+      this.bindPort = bindPort;
+      this.maxConnections = maxConnections;
+      this.running = new AtomicBoolean(false);
+      this.shutdown = null;
+      this.validConnections = new AtomicInteger(0);
+      this.ss = null;
+      this.tpe = null;
+   }
+
+   /**
+    * Start
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void start() throws Throwable
+   {
+      if (!running.get())
+      {
+         shutdown = new CountDownLatch(1);
+
+         InetSocketAddress address = new InetSocketAddress(bindAddress, bindPort); 
+
+         ss = new ServerSocket();
+         ss.bind(address, maxConnections);
+
+         BlockingQueue<Runnable> threadPoolQueue = new SynchronousQueue<Runnable>(true);
+         
+         tpe = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Integer.MAX_VALUE,
+                                      60, TimeUnit.SECONDS,
+                                      threadPoolQueue);
+         
+         tpe.allowCoreThreadTimeOut(true);
+         tpe.prestartAllCoreThreads();
+
+         running.set(true);
+
+         log.infof("EISServer started");
+      }
+   }
+
+   /**
+    * Stop
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void stop() throws Throwable
+   {
+      running.set(false);
+
+      if (tpe != null)
+         tpe.shutdown();
+
+      if (ss != null)
+      {
+         try
+         {
+            ss.close();
+         }
+         catch (IOException ioe)
+         {
+            log.debugf(ioe.getMessage(), ioe);
+         }
+      }
+
+      shutdown.await();
+
+      log.infof("EISServer stopped");
+   }
+
+   /**
+    * Run
+    */
+   public void run()
+   {
+      while (running.get())
+      {
+         Socket socket = null;
+         try
+         {
+            log.debugf("Waiting for connection");
+
+            socket = ss.accept();
+            socket.setSoTimeout(300000);
+
+            log.debugf("Accepted connection: %s", socket);
+
+            boolean granted = validConnections.incrementAndGet() <= maxConnections;
+
+            log.debugf("Granted: %s", granted);
+
+            Runnable r = new Interaction(socket, granted, validConnections);
+            tpe.submit(r);
+         }
+         catch (IOException ioe)
+         {
+            log.debugf(ioe.getMessage(), ioe);
+         }
+         catch (RejectedExecutionException ree)
+         {
+            log.debugf("Rejecting connection: %s", socket);
+
+            validConnections.decrementAndGet();
+
+            if (socket != null)
+            {
+               try
+               {
+                  socket.shutdownInput();
+                  socket.shutdownOutput();
+
+                  socket.close();
+               }
+               catch (IOException ioe)
+               {
+                  log.debugf(ioe.getMessage(), ioe);
+               }
+            }
+         }
+      }
+      
+      shutdown.countDown();
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Echo.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Echo.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Echo.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents an echo command
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Echo implements Invoker
+{
+   /** The key */
+   public static final byte KEY = 2;
+
+   /** The logger */
+   private Logger log = Logger.getLogger(Echo.class);
+
+   /**
+    * Auth
+    */
+   public Echo()
+   {
+   }
+
+   /**
+    * Invoke
+    * @param args The arguments
+    * @return The return value
+    */
+   public Serializable invoke(Serializable[] args)
+   {
+      if (args == null || args.length != 1)
+         return new IllegalArgumentException("Unsupported argument list: " + Arrays.toString(args));
+
+      Serializable s = args[0];
+
+      log.infof("S=%s", s);
+
+      return s;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Interaction.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Interaction.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Interaction.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.net.Socket;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jboss.logging.Logger;
+
+/**
+ * An interaction between client and server
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Interaction implements Runnable
+{
+   /** The logger */
+   private Logger log = Logger.getLogger(Interaction.class);
+
+   /** The socket */
+   private Socket socket;
+
+   /** Granted */
+   private boolean granted;
+
+   /** Callback */
+   private AtomicInteger callback;
+
+   /** Input */
+   private ObjectInputStream ois;
+
+   /** Output */
+   private ObjectOutputStream oos;
+
+   /**
+    * Constructor
+    * @param socket The socket
+    * @param granted Was full access granted
+    * @param callback The close callback
+    */
+   public Interaction(Socket socket, boolean granted, AtomicInteger callback)
+   {
+      this.socket = socket;
+      this.granted = granted;
+      this.callback = callback;
+      this.ois = null;
+      this.oos = null;
+   }
+
+   /**
+    * Run
+    */
+   public void run()
+   {
+      log.debugf("Interaction started for: %s", socket);
+
+      try
+      {
+         boolean close = false;
+               
+         while (!close)
+         {
+            byte command = getInput().readByte();
+            Serializable[] arguments = null;
+
+            Invoker invoker = null;
+
+            log.debugf("Command: %d for %s", command, socket);
+
+            if (command == Connect.KEY)
+            {
+               invoker = new Connect();
+
+               arguments = new Serializable[1];
+               arguments[0] = granted ? Boolean.TRUE : Boolean.FALSE;
+            }
+            else if (command == Close.KEY)
+            {
+               close = true;
+            }
+            else if (granted && command == Echo.KEY)
+            {
+               invoker = new Echo();
+
+               arguments = new Serializable[1];
+               arguments[0] = (Serializable)ois.readObject();
+            }
+            else if (granted && command == Auth.KEY)
+            {
+               invoker = new Auth();
+
+               arguments = new Serializable[2];
+               arguments[0] = (Serializable)ois.readUTF();
+               arguments[1] = (Serializable)ois.readUTF();
+            }
+            else
+            {
+               log.warnf("Unknown command: %d for %s", command, socket);
+            }
+
+            if (!close)
+            {
+               if (invoker != null)
+               {
+                  Serializable result = invoker.invoke(arguments);
+
+                  log.infof("Sending reply: %s to: %s", result, socket);
+
+                  getOutput().writeObject(result);
+                  getOutput().flush();
+               }
+            }
+         }
+      }
+      catch (Throwable t)
+      {
+         log.debug(t.getMessage(), t);
+      }
+      finally
+      {
+         log.debugf("Interaction ended for: %s", socket);
+
+         try
+         {
+            if (socket != null)
+               socket.close();
+         }
+         catch (IOException ioe)
+         {
+            log.debug(ioe.getMessage(), ioe);
+         }
+
+         callback.decrementAndGet();
+      }
+   }
+
+   /**
+    * Get input stream
+    * @return The value
+    * @exception IOException Thrown in case of an error
+    */
+   private ObjectInputStream getInput() throws IOException
+   {
+      if (ois == null)
+         ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream(), 8192));
+      
+      return ois;
+   }
+
+   /**
+    * Get output stream
+    * @return The value
+    * @exception IOException Thrown in case of an error
+    */
+   private ObjectOutputStream getOutput() throws IOException
+   {
+      if (oos == null)
+         oos = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream(), 8192));
+      
+      return oos;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Invoker.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Invoker.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Invoker.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import java.io.Serializable;
+
+/**
+ * Represents an invoker
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public interface Invoker
+{
+   /**
+    * Invoke
+    * @param args The arguments
+    * @return The return value
+    */
+   public Serializable invoke(Serializable[] args);
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/ReauthServer.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/ReauthServer.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/ReauthServer.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,144 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import org.jboss.logging.Logger;
+
+/**
+ * The reauthentication EIS server
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class ReauthServer
+{
+   /** Default host name */
+   private static final String DEFAULT_HOST_NAME = "localhost";
+
+   /** The logger */
+   private static Logger log = Logger.getLogger(ReauthServer.class);
+
+   /** The host name */
+   private String hostName;
+
+   /** The port */
+   private int port;
+
+   /** Maximum number of connections */
+   private int maxConnections;
+
+   /** EIS server */
+   private EISServer eis;
+
+   /**
+    * Constructor
+    */
+   public ReauthServer()
+   {
+      this.hostName = DEFAULT_HOST_NAME;
+      this.port = 19000;
+      this.maxConnections = 1;
+      this.eis = null;
+   }
+
+   /**
+    * Get the host name
+    * @return The value
+    */
+   public String getHostName()
+   {
+      return hostName;
+   }
+
+   /**
+    * Set the host name
+    * @param v The value
+    */
+   public void setHostName(String v)
+   {
+      if (v != null)
+         hostName = v;
+   }
+
+   /**
+    * Get the port
+    * @return The value
+    */
+   public int getPort()
+   {
+      return port;
+   }
+
+   /**
+    * Set the port
+    * @param v The value
+    */
+   public void setPort(int v)
+   {
+      port = v;
+   }
+
+   /**
+    * Get the maximum number of connections
+    * @return The value
+    */
+   public int getMaxConnections()
+   {
+      return maxConnections;
+   }
+
+   /**
+    * Set the maximum number of connections
+    * @param v The value
+    */
+   public void setMaxConnections(int v)
+   {
+      maxConnections = v;
+   }
+
+   /**
+    * Start
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void start() throws Throwable
+   {
+      if (eis != null)
+         eis.stop();
+
+      eis = new EISServer(hostName, port, maxConnections);
+      eis.start();
+
+      Thread t = new Thread(eis);
+      t.start();
+   }
+
+   /**
+    * Stop
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void stop() throws Throwable
+   {
+      if (eis != null)
+         eis.stop();
+
+      eis = null;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SecurityActions.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SecurityActions.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+class SecurityActions
+{ 
+   /**
+    * Constructor
+    */
+   private SecurityActions()
+   {
+   }
+
+   /**
+    * Get the thread context class loader
+    * @return The class loader
+    */
+   static ClassLoader getThreadContextClassLoader()
+   {
+      if (System.getSecurityManager() == null)
+         return Thread.currentThread().getContextClassLoader();
+
+      return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() 
+      {
+         public ClassLoader run()
+         {
+            return Thread.currentThread().getContextClassLoader();
+         }
+      });
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SimpleCRI.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SimpleCRI.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SimpleCRI.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis;
+
+import java.io.Serializable;
+
+import javax.resource.spi.ConnectionRequestInfo;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A simple connection request info object
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class SimpleCRI implements ConnectionRequestInfo, Serializable
+{
+   private static final long serialVersionUID = 1L;
+   
+   private static Logger log = Logger.getLogger(SimpleCRI.class);
+
+   private final String userName;
+   private final String password;
+
+   /**
+    * Constructor
+    * @param userName The user name
+    * @param password The password
+    */
+   public SimpleCRI(final String userName, final String password)
+   {
+      if (userName == null)
+         throw new IllegalArgumentException("UserName is null");
+
+      if (password == null)
+         throw new IllegalArgumentException("UserName is null");
+
+      this.userName = userName;
+      this.password = password;
+   }
+
+   /**
+    * Get the user name
+    * @return The value
+    */
+   public String getUserName()
+   {
+      return userName;
+   }
+
+   /**
+    * Get the password
+    * @return The value
+    */
+   public String getPassword()
+   {
+      return password;
+   }
+
+   /**
+    * Hash code
+    * @return The value
+    */
+   public int hashCode()
+   {
+      int hashCode = 7;
+
+      hashCode += 7 * userName.hashCode();
+      hashCode += 7 * password.hashCode();
+
+      return hashCode;
+   }
+
+   /**
+    * Equals
+    * @param obj The other object
+    * @return True if equal; otherwise false
+    */
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+
+      if (obj == null || !(obj instanceof SimpleCRI))
+         return false;
+
+      SimpleCRI s = (SimpleCRI)obj;
+
+      return userName.equals(s.getUserName()) &&
+         password.equals(s.getPassword());
+   }
+
+   /**
+    * String representation
+    * @return The value
+    */
+   public String toString()
+   {
+      StringBuilder sb = new StringBuilder();
+
+      sb.append("SimpleCRI@").append(Integer.toHexString(System.identityHashCode(this)));
+      sb.append("[userName=").append(userName);
+      sb.append(" password=").append(password);
+      sb.append("]");
+
+      return sb.toString();
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/package.html	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,3 @@
+<body>
+This package contains the EIS for the reauthentication test suite.
+</body>

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/EISTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/EISTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/EISTestCase.java	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,389 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth.eis.unit;
+
+import org.jboss.jca.core.security.reauth.eis.Auth;
+import org.jboss.jca.core.security.reauth.eis.Close;
+import org.jboss.jca.core.security.reauth.eis.Connect;
+import org.jboss.jca.core.security.reauth.eis.Echo;
+import org.jboss.jca.core.security.reauth.eis.ReauthServer;
+import org.jboss.jca.core.security.reauth.eis.SimpleCRI;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.Socket;
+
+import org.jboss.logging.Logger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Tests for the reauthencation EIS server.
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class EISTestCase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static Logger log = Logger.getLogger(EISTestCase.class);
+
+   private static ReauthServer reauthServer;
+
+   private static String host = "localhost";
+   private static int port = 19000;
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Connect
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testConnect() throws Throwable
+   {
+      Socket socket = null;
+      try
+      {
+         socket = new Socket(host, port);
+
+         log.infof("Socket: %s", socket);
+
+         ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+
+         // Connect
+         oos.writeByte(Connect.KEY);
+         oos.flush();
+
+         ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+         Boolean granted = (Boolean)ois.readObject();
+         assertTrue(granted.booleanValue());
+
+         // Write
+         Integer payload = new Integer(0);
+         oos.writeByte(Echo.KEY);
+         oos.writeObject(payload);
+         oos.flush();
+
+         // Read
+         Object result = ois.readObject();
+
+         // Assert
+         assertEquals(payload, result);
+
+         // Close
+         oos.writeByte(Close.KEY);
+         oos.flush();
+      }
+      finally
+      {
+         if (socket != null)
+         {
+            try
+            {
+               socket.close();
+            }
+            catch (IOException ioe)
+            {
+               log.debugf(ioe.getMessage(), ioe);
+            }
+         }
+      }
+   }
+
+   /**
+    * Connect
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testDoubleConnect() throws Throwable
+   {
+      Socket socket1 = null;
+      Socket socket2 = null;
+
+      try
+      {
+         socket1 = new Socket(host, port);
+
+         log.infof("Socket1: %s", socket1);
+
+         ObjectOutputStream oos1 = new ObjectOutputStream(socket1.getOutputStream());
+
+         // Connect
+         oos1.writeByte(Connect.KEY);
+         oos1.flush();
+
+         ObjectInputStream ois1 = new ObjectInputStream(socket1.getInputStream());
+
+         Boolean granted1 = (Boolean)ois1.readObject();
+         assertTrue(granted1.booleanValue());
+
+         // Payload
+         Integer payload = new Integer(0);
+
+         // Write
+         oos1.writeByte(Echo.KEY);
+         oos1.writeObject(payload);
+         oos1.flush();
+
+         // Read
+         Object result = ois1.readObject();
+
+         // Assert
+         assertEquals(payload, result);
+
+         socket2 = new Socket(host, port);
+
+         log.infof("Socket2: %s", socket2);
+
+         ObjectOutputStream oos2 = new ObjectOutputStream(socket2.getOutputStream());
+
+         // Connect
+         oos2.writeByte(Connect.KEY);
+         oos2.flush();
+
+         ObjectInputStream ois2 = new ObjectInputStream(socket2.getInputStream());
+
+         Boolean granted2 = (Boolean)ois2.readObject();
+         assertTrue(!granted2.booleanValue());
+
+         // Close
+         oos1.writeByte(Close.KEY);
+         oos1.flush();
+         oos2.writeByte(Close.KEY);
+         oos2.flush();
+      }
+      finally
+      {
+         if (socket1 != null)
+         {
+            try
+            {
+               socket1.close();
+            }
+            catch (IOException ioe)
+            {
+               // Ignore
+            }
+         }
+
+         if (socket2 != null)
+         {
+            try
+            {
+               socket2.close();
+            }
+            catch (IOException ioe)
+            {
+               // Ignore
+            }
+         }
+      }
+   }
+
+   /**
+    * Auth CRI test
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testAuthCri() throws Throwable
+   {
+      Socket socket = null;
+      try
+      {
+         socket = new Socket(host, port);
+
+         log.infof("Socket: %s", socket);
+
+         // User
+         String userName = "user";
+         String password = "password";
+
+         // Connect
+         ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+         oos.writeByte(Connect.KEY);
+         oos.flush();
+
+         ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+         Boolean granted = (Boolean)ois.readObject();
+         assertTrue(granted.booleanValue());
+
+         // Payload
+         SimpleCRI payload = new SimpleCRI(userName, password);
+
+         // Write
+         oos.writeByte(Auth.KEY);
+         oos.writeUTF(payload.getUserName());
+         oos.writeUTF(payload.getPassword());
+         oos.flush();
+
+         // Read
+         Object result = ois.readObject();
+
+         // Assert
+         assertEquals(userName, result);
+
+         // Close
+         oos.writeByte(Close.KEY);
+         oos.flush();
+      }
+      finally
+      {
+         if (socket != null)
+         {
+            try
+            {
+               socket.close();
+            }
+            catch (IOException ioe)
+            {
+               // Ignore
+            }
+         }
+      }
+   }
+
+   /**
+    * Auth CRI test - change user name
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testAuthCriChangeUserName() throws Throwable
+   {
+      Socket socket = null;
+      try
+      {
+         socket = new Socket(host, port);
+
+         log.infof("Socket: %s", socket);
+
+         // User
+         String userName1 = "user1";
+         String password1 = "password1";
+         String userName2 = "user2";
+         String password2 = "password2";
+
+         // Connect
+         ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+         oos.writeByte(Connect.KEY);
+         oos.flush();
+
+         ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+         Boolean granted = (Boolean)ois.readObject();
+         assertTrue(granted.booleanValue());
+
+         // Payload
+         SimpleCRI payload1 = new SimpleCRI(userName1, password1);
+
+         // Write
+         oos.writeByte(Auth.KEY);
+         oos.writeUTF(payload1.getUserName());
+         oos.writeUTF(payload1.getPassword());
+         oos.flush();
+
+         // Read
+         Object result = ois.readObject();
+
+         // Assert
+         assertEquals(userName1, result);
+
+         // Payload
+         SimpleCRI payload2 = new SimpleCRI(userName2, password2);
+
+         // Write
+         oos.writeByte(Auth.KEY);
+         oos.writeUTF(payload2.getUserName());
+         oos.writeUTF(payload2.getPassword());
+         oos.flush();
+
+         // Read
+         result = ois.readObject();
+
+         // Assert
+         assertEquals(userName2, result);
+
+         // Close
+         oos.writeByte(Close.KEY);
+         oos.flush();
+      }
+      finally
+      {
+         if (socket != null)
+         {
+            try
+            {
+               socket.close();
+            }
+            catch (IOException ioe)
+            {
+               // Ignore
+            }
+         }
+      }
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Lifecycle start, before each test is executed
+    * @throws Throwable throwable exception 
+    */
+   @Before
+   public void before() throws Throwable
+   {
+      reauthServer = new ReauthServer();
+      reauthServer.setHostName(host);
+      reauthServer.setPort(port);
+      reauthServer.setMaxConnections(1);
+      
+      assertNotNull(reauthServer);
+
+      reauthServer.start();
+   }
+
+   /**
+    * Lifecycle stop, after each test is executed
+    * @throws Throwable throwable exception 
+    */
+   @After
+   public void after() throws Throwable
+   {
+      reauthServer.stop();
+      reauthServer = null;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/package.html	2011-02-09 16:52:09 UTC (rev 110567)
@@ -0,0 +1,3 @@
+<body>
+This package contains unit tests for the reauthentication EIS server.
+</body>



More information about the jboss-cvs-commits mailing list