[jboss-cvs] JBossAS SVN: r110572 - in projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 9 13:42:22 EST 2011


Author: jesper.pedersen
Date: 2011-02-09 13:42:22 -0500 (Wed, 09 Feb 2011)
New Revision: 110572

Added:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Commands.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Unauth.java
Modified:
   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/Connect.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/unit/EISTestCase.java
Log:
[JBJCA-94] Reauthentication test eis server - Add UNAUTH command

Modified: 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	2011-02-09 18:41:08 UTC (rev 110571)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Auth.java	2011-02-09 18:42:22 UTC (rev 110572)
@@ -33,17 +33,19 @@
  */
 public class Auth implements Invoker
 {
-   /** The key */
-   public static final byte KEY = 3;
-
    /** The logger */
    private Logger log = Logger.getLogger(Auth.class);
 
+   /** The interaction */
+   private Interaction interaction;
+
    /**
     * Auth
+    * @param interaction The interaction
     */
-   public Auth()
+   public Auth(Interaction interaction)
    {
+      this.interaction = interaction;
    }
 
    /**
@@ -61,6 +63,8 @@
 
       log.infof("UserName=%s Password=%s", userName, password);
 
+      interaction.setUserName(userName);
+
       return userName;
    }
 }

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Commands.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Commands.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Commands.java	2011-02-09 18:42:22 UTC (rev 110572)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+/**
+ * Represents the available commands
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public interface Commands
+{
+   /** CONNECT */
+   public static final byte CONNECT = 0;
+
+   /** CLOSE */
+   public static final byte CLOSE = 1;
+
+   /** ECHO */
+   public static final byte ECHO = 2;
+
+   /** AUTH */
+   public static final byte AUTH = 3;
+
+   /** UNAUTH */
+   public static final byte UNAUTH = 4;
+}

Modified: 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	2011-02-09 18:41:08 UTC (rev 110571)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Connect.java	2011-02-09 18:42:22 UTC (rev 110572)
@@ -33,9 +33,6 @@
  */
 public class Connect implements Invoker
 {
-   /** The key */
-   public static final byte KEY = 0;
-
    /** The logger */
    private Logger log = Logger.getLogger(Connect.class);
 
@@ -58,7 +55,7 @@
 
       Serializable s = args[0];
 
-      log.infof("S=%s", s);
+      log.infof("Connected=%s", s);
 
       return s;
    }

Modified: 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	2011-02-09 18:41:08 UTC (rev 110571)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Echo.java	2011-02-09 18:42:22 UTC (rev 110572)
@@ -33,17 +33,19 @@
  */
 public class Echo implements Invoker
 {
-   /** The key */
-   public static final byte KEY = 2;
-
    /** The logger */
    private Logger log = Logger.getLogger(Echo.class);
 
+   /** The interaction */
+   private Interaction interaction;
+
    /**
-    * Auth
+    * Constructor
+    * @param interaction The interaction
     */
-   public Echo()
+   public Echo(Interaction interaction)
    {
+      this.interaction = interaction;
    }
 
    /**
@@ -58,7 +60,7 @@
 
       Serializable s = args[0];
 
-      log.infof("S=%s", s);
+      log.infof("%s sent %s", interaction.getUserName() != null ? interaction.getUserName() : "Anonymous", s);
 
       return s;
    }

Modified: 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	2011-02-09 18:41:08 UTC (rev 110571)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Interaction.java	2011-02-09 18:42:22 UTC (rev 110572)
@@ -57,6 +57,9 @@
    /** Output */
    private ObjectOutputStream oos;
 
+   /** The user name */
+   private String userName;
+
    /**
     * Constructor
     * @param socket The socket
@@ -70,6 +73,7 @@
       this.callback = callback;
       this.ois = null;
       this.oos = null;
+      this.userName = null;
    }
 
    /**
@@ -92,32 +96,36 @@
 
             log.debugf("Command: %d for %s", command, socket);
 
-            if (command == Connect.KEY)
+            if (command == Commands.CONNECT)
             {
                invoker = new Connect();
 
                arguments = new Serializable[1];
                arguments[0] = granted ? Boolean.TRUE : Boolean.FALSE;
             }
-            else if (command == Close.KEY)
+            else if (command == Commands.CLOSE)
             {
                close = true;
             }
-            else if (granted && command == Echo.KEY)
+            else if (granted && command == Commands.ECHO)
             {
-               invoker = new Echo();
+               invoker = new Echo(this);
 
                arguments = new Serializable[1];
                arguments[0] = (Serializable)ois.readObject();
             }
-            else if (granted && command == Auth.KEY)
+            else if (granted && command == Commands.AUTH)
             {
-               invoker = new Auth();
+               invoker = new Auth(this);
 
                arguments = new Serializable[2];
                arguments[0] = (Serializable)ois.readUTF();
                arguments[1] = (Serializable)ois.readUTF();
             }
+            else if (granted && command == Commands.UNAUTH)
+            {
+               invoker = new Unauth(this);
+            }
             else
             {
                log.warnf("Unknown command: %d for %s", command, socket);
@@ -160,6 +168,24 @@
    }
 
    /**
+    * Get the user name
+    * @return The value
+    */
+   String getUserName()
+   {
+      return userName;
+   }
+
+   /**
+    * Set the user name
+    * @param v The value
+    */
+   void setUserName(String v)
+   {
+      userName = v;
+   }
+
+   /**
     * Get input stream
     * @return The value
     * @exception IOException Thrown in case of an error

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Unauth.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Unauth.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Unauth.java	2011-02-09 18:42:22 UTC (rev 110572)
@@ -0,0 +1,71 @@
+/*
+ * 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 unauth command
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Unauth implements Invoker
+{
+   /** The logger */
+   private Logger log = Logger.getLogger(Unauth.class);
+
+   /** The interaction */
+   private Interaction interaction;
+
+   /**
+    * Constructor
+    * @param interaction The interaction
+    */
+   public Unauth(Interaction interaction)
+   {
+      this.interaction = interaction;
+   }
+
+   /**
+    * Invoke
+    * @param args The arguments
+    * @return The return value
+    */
+   public Serializable invoke(Serializable[] args)
+   {
+      if (args != null)
+         return new IllegalArgumentException("Unsupported argument list: " + Arrays.toString(args));
+
+      log.infof("Unauth: %s", interaction.getUserName() != null ? interaction.getUserName() : "Anonymous");
+
+      if (interaction.getUserName() != null)
+      {
+         interaction.setUserName(null);
+         return Boolean.TRUE;
+      }
+
+      return Boolean.FALSE;
+   }
+}

Modified: 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	2011-02-09 18:41:08 UTC (rev 110571)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/EISTestCase.java	2011-02-09 18:42:22 UTC (rev 110572)
@@ -22,10 +22,7 @@
 
 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.Commands;
 import org.jboss.jca.core.security.reauth.eis.ReauthServer;
 import org.jboss.jca.core.security.reauth.eis.SimpleCRI;
 
@@ -82,7 +79,7 @@
          ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
 
          // Connect
-         oos.writeByte(Connect.KEY);
+         oos.writeByte(Commands.CONNECT);
          oos.flush();
 
          ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
@@ -92,7 +89,7 @@
 
          // Write
          Integer payload = new Integer(0);
-         oos.writeByte(Echo.KEY);
+         oos.writeByte(Commands.ECHO);
          oos.writeObject(payload);
          oos.flush();
 
@@ -103,7 +100,7 @@
          assertEquals(payload, result);
 
          // Close
-         oos.writeByte(Close.KEY);
+         oos.writeByte(Commands.CLOSE);
          oos.flush();
       }
       finally
@@ -141,7 +138,7 @@
          ObjectOutputStream oos1 = new ObjectOutputStream(socket1.getOutputStream());
 
          // Connect
-         oos1.writeByte(Connect.KEY);
+         oos1.writeByte(Commands.CONNECT);
          oos1.flush();
 
          ObjectInputStream ois1 = new ObjectInputStream(socket1.getInputStream());
@@ -153,7 +150,7 @@
          Integer payload = new Integer(0);
 
          // Write
-         oos1.writeByte(Echo.KEY);
+         oos1.writeByte(Commands.ECHO);
          oos1.writeObject(payload);
          oos1.flush();
 
@@ -170,7 +167,7 @@
          ObjectOutputStream oos2 = new ObjectOutputStream(socket2.getOutputStream());
 
          // Connect
-         oos2.writeByte(Connect.KEY);
+         oos2.writeByte(Commands.CONNECT);
          oos2.flush();
 
          ObjectInputStream ois2 = new ObjectInputStream(socket2.getInputStream());
@@ -179,9 +176,9 @@
          assertTrue(!granted2.booleanValue());
 
          // Close
-         oos1.writeByte(Close.KEY);
+         oos1.writeByte(Commands.CLOSE);
          oos1.flush();
-         oos2.writeByte(Close.KEY);
+         oos2.writeByte(Commands.CLOSE);
          oos2.flush();
       }
       finally
@@ -232,7 +229,7 @@
 
          // Connect
          ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
-         oos.writeByte(Connect.KEY);
+         oos.writeByte(Commands.CONNECT);
          oos.flush();
 
          ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
@@ -244,7 +241,7 @@
          SimpleCRI payload = new SimpleCRI(userName, password);
 
          // Write
-         oos.writeByte(Auth.KEY);
+         oos.writeByte(Commands.AUTH);
          oos.writeUTF(payload.getUserName());
          oos.writeUTF(payload.getPassword());
          oos.flush();
@@ -256,7 +253,7 @@
          assertEquals(userName, result);
 
          // Close
-         oos.writeByte(Close.KEY);
+         oos.writeByte(Commands.CLOSE);
          oos.flush();
       }
       finally
@@ -297,7 +294,7 @@
 
          // Connect
          ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
-         oos.writeByte(Connect.KEY);
+         oos.writeByte(Commands.CONNECT);
          oos.flush();
 
          ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
@@ -309,7 +306,7 @@
          SimpleCRI payload1 = new SimpleCRI(userName1, password1);
 
          // Write
-         oos.writeByte(Auth.KEY);
+         oos.writeByte(Commands.AUTH);
          oos.writeUTF(payload1.getUserName());
          oos.writeUTF(payload1.getPassword());
          oos.flush();
@@ -324,7 +321,7 @@
          SimpleCRI payload2 = new SimpleCRI(userName2, password2);
 
          // Write
-         oos.writeByte(Auth.KEY);
+         oos.writeByte(Commands.AUTH);
          oos.writeUTF(payload2.getUserName());
          oos.writeUTF(payload2.getPassword());
          oos.flush();
@@ -336,7 +333,7 @@
          assertEquals(userName2, result);
 
          // Close
-         oos.writeByte(Close.KEY);
+         oos.writeByte(Commands.CLOSE);
          oos.flush();
       }
       finally



More information about the jboss-cvs-commits mailing list