[jboss-cvs] JBossAS SVN: r110688 - in projects/jboss-jca/trunk/core/src/test: java/org/jboss/jca/core/security/reauth/eis and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 16 10:40:03 EST 2011
Author: jesper.pedersen
Date: 2011-02-16 10:40:03 -0500 (Wed, 16 Feb 2011)
New Revision: 110688
Added:
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/MaxConnections.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnection.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionFactory.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionFactoryImpl.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionImpl.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthCri.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnection.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionFactory.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionMetaData.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthResourceAdapter.java
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/package.html
projects/jboss-jca/trunk/core/src/test/resources/rars/
projects/jboss-jca/trunk/core/src/test/resources/rars/security/
projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/
projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/
projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/META-INF/
projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/META-INF/ironjacamar.xml
projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/META-INF/ra.xml
Removed:
projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SimpleCRI.java
Modified:
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/EISServer.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 - CRI based resource adapter
Modified: 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 2011-02-16 14:29:35 UTC (rev 110687)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Commands.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -45,4 +45,7 @@
/** GETAUTH */
public static final byte GETAUTH = 5;
+
+ /** MAXCONNECTIONS */
+ public static final byte MAXCONNECTIONS = 6;
}
Modified: 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 2011-02-16 14:29:35 UTC (rev 110687)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/EISServer.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -171,7 +171,7 @@
log.debugf("Granted: %s", granted);
- Runnable r = new Interaction(socket, granted, validConnections);
+ Runnable r = new Interaction(socket, granted, validConnections, maxConnections);
tpe.submit(r);
}
catch (IOException ioe)
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-16 14:29:35 UTC (rev 110687)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/Interaction.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -51,6 +51,9 @@
/** Callback */
private AtomicInteger callback;
+ /** Max connections */
+ private int maxConnections;
+
/** Input */
private ObjectInputStream ois;
@@ -65,12 +68,14 @@
* @param socket The socket
* @param granted Was full access granted
* @param callback The close callback
+ * @param maxConnections The maximum number of connections
*/
- public Interaction(Socket socket, boolean granted, AtomicInteger callback)
+ public Interaction(Socket socket, boolean granted, AtomicInteger callback, int maxConnections)
{
this.socket = socket;
this.granted = granted;
this.callback = callback;
+ this.maxConnections = maxConnections;
this.ois = null;
this.oos = null;
this.userName = null;
@@ -130,6 +135,10 @@
{
invoker = new GetAuth(this);
}
+ else if (granted && command == Commands.MAXCONNECTIONS)
+ {
+ invoker = new MaxConnections(this, Integer.valueOf(maxConnections));
+ }
else
{
log.warnf("Unknown command: %d for %s", command, socket);
Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/MaxConnections.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/MaxConnections.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/MaxConnections.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,70 @@
+/*
+ * 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 max connections command
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class MaxConnections implements Invoker
+{
+ /** The logger */
+ private Logger log = Logger.getLogger(MaxConnections.class);
+
+ /** The interaction */
+ private Interaction interaction;
+
+ /** Max connections */
+ private Integer maxConnections;
+
+ /**
+ * Constructor
+ * @param interaction The interaction
+ * @param maxConnections The max connections
+ */
+ public MaxConnections(Interaction interaction, Integer maxConnections)
+ {
+ this.interaction = interaction;
+ this.maxConnections = maxConnections;
+ }
+
+ /**
+ * 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("MaxConnections: %s", maxConnections);
+
+ return maxConnections;
+ }
+}
Deleted: 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 2011-02-16 14:29:35 UTC (rev 110687)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/SimpleCRI.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -1,129 +0,0 @@
-/*
- * 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();
- }
-}
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-16 14:29:35 UTC (rev 110687)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/eis/unit/EISTestCase.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -24,7 +24,6 @@
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;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -257,13 +256,10 @@
Boolean granted = (Boolean)ois.readObject();
assertTrue(granted.booleanValue());
- // Payload
- SimpleCRI payload = new SimpleCRI(userName, password);
-
// Write
oos.writeByte(Commands.AUTH);
- oos.writeUTF(payload.getUserName());
- oos.writeUTF(payload.getPassword());
+ oos.writeUTF(userName);
+ oos.writeUTF(password);
oos.flush();
// Read
@@ -342,13 +338,10 @@
Boolean granted = (Boolean)ois.readObject();
assertTrue(granted.booleanValue());
- // Payload
- SimpleCRI payload1 = new SimpleCRI(userName1, password1);
-
// Write
oos.writeByte(Commands.AUTH);
- oos.writeUTF(payload1.getUserName());
- oos.writeUTF(payload1.getPassword());
+ oos.writeUTF(userName1);
+ oos.writeUTF(password1);
oos.flush();
// Read
@@ -357,13 +350,10 @@
// Assert
assertEquals(userName1, result);
- // Payload
- SimpleCRI payload2 = new SimpleCRI(userName2, password2);
-
// Write
oos.writeByte(Commands.AUTH);
- oos.writeUTF(payload2.getUserName());
- oos.writeUTF(payload2.getPassword());
+ oos.writeUTF(userName2);
+ oos.writeUTF(password2);
oos.flush();
// Read
Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnection.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnection.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnection.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,55 @@
+/*
+ * 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.ra.cri;
+
+import javax.resource.ResourceException;
+
+/**
+ * ReauthConnection
+ *
+ * @version $Revision: $
+ */
+public interface ReauthConnection
+{
+ /**
+ * login
+ * @param username username
+ * @param password password
+ * @return String
+ * @throws ResourceException Thrown if an error occurs
+ */
+ public String login(String username, String password) throws ResourceException;
+
+ /**
+ * logout
+ * @return boolean
+ * @throws ResourceException Thrown if an error occurs
+ */
+ public boolean logout() throws ResourceException;
+
+ /**
+ * get auth
+ * @return String
+ * @throws ResourceException Thrown if an error occurs
+ */
+ public String getAuth() throws ResourceException;
+}
Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionFactory.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionFactory.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.ra.cri;
+
+import java.io.Serializable;
+
+import javax.resource.Referenceable;
+import javax.resource.ResourceException;
+
+/**
+ * ReauthConnectionFactory
+ *
+ * @version $Revision: $
+ */
+public interface ReauthConnectionFactory extends Serializable, Referenceable
+{
+ /**
+ * Get connection from factory
+ *
+ * @param userName The user name
+ * @param password The password
+ * @return ReauthConnection instance
+ * @exception ResourceException Thrown if a connection can't be obtained
+ */
+ public ReauthConnection getConnection(String userName, String password) throws ResourceException;
+}
Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionFactoryImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionFactoryImpl.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionFactoryImpl.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.ra.cri;
+
+import javax.naming.NamingException;
+import javax.naming.Reference;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ManagedConnectionFactory;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ReauthConnectionFactoryImpl
+ *
+ * @version $Revision: $
+ */
+public class ReauthConnectionFactoryImpl implements ReauthConnectionFactory
+{
+ /** The serial version UID */
+ private static final long serialVersionUID = 1L;
+
+ /** The logger */
+ private static Logger log = Logger.getLogger(ReauthConnectionFactoryImpl.class);
+
+ /** The managed connection factory */
+ private ManagedConnectionFactory mcf;
+
+ /** The connection manager */
+ private ConnectionManager connectionManager;
+
+ /** Reference */
+ private Reference reference;
+
+ /**
+ * Constructor
+ * @param mcf The managed connection factory
+ * @param cxManager The connection manager
+ */
+ public ReauthConnectionFactoryImpl(ManagedConnectionFactory mcf,
+ ConnectionManager cxManager)
+ {
+ this.mcf = mcf;
+ this.connectionManager = cxManager;
+ this.reference = null;
+ }
+
+ /**
+ * Get connection from factory
+ *
+ * @param userName The user name
+ * @param password The password
+ * @return ReauthConnection instance
+ * @exception ResourceException Thrown if a connection can't be obtained
+ */
+ @Override
+ public ReauthConnection getConnection(String userName, String password) throws ResourceException
+ {
+ log.tracef("getConnection()");
+
+ ReauthCri cri = new ReauthCri(userName, password);
+ return (ReauthConnection)connectionManager.allocateConnection(mcf, cri);
+ }
+
+ /**
+ * Get the Reference instance.
+ *
+ * @return Reference instance
+ * @exception NamingException Thrown if a reference can't be obtained
+ */
+ @Override
+ public Reference getReference() throws NamingException
+ {
+ log.tracef("getReference()");
+
+ return reference;
+ }
+
+ /**
+ * Set the Reference instance.
+ *
+ * @param reference A Reference instance
+ */
+ @Override
+ public void setReference(Reference reference)
+ {
+ log.tracef("setReference(%s)", reference);
+
+ this.reference = reference;
+ }
+}
Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionImpl.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionImpl.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,177 @@
+/*
+ * 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.ra.cri;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.Socket;
+
+import javax.resource.ResourceException;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ReauthConnectionImpl
+ *
+ * @version $Revision: $
+ */
+public class ReauthConnectionImpl implements ReauthConnection
+{
+ /** The logger */
+ private static Logger log = Logger.getLogger(ReauthConnectionImpl.class);
+
+ /** The socket */
+ private Socket socket;
+
+ /** Input */
+ private ObjectInputStream ois;
+
+ /** Output */
+ private ObjectOutputStream oos;
+
+ /** The CRI */
+ private ReauthCri cri;
+
+ /**
+ * Constructor
+ * @param socket The socket
+ * @param cri ConnectionRequestInfo instance
+ * @exception ResourceException Thrown if an error occurs
+ */
+ public ReauthConnectionImpl(Socket socket, ReauthCri cri) throws ResourceException
+ {
+ log.tracef("constructor(%s, %s)", socket, cri);
+
+ this.socket = socket;
+ this.cri = cri;
+ }
+
+ /**
+ * Call login
+ * @param username String
+ * @param password String
+ * @return String
+ * @exception ResourceException Thrown if an error occurs
+ */
+ public String login(String username, String password) throws ResourceException
+ {
+ log.tracef("login(%s, %s)", username, password);
+
+ try
+ {
+ getOutput().writeByte(3);
+ getOutput().writeUTF(username);
+ getOutput().writeUTF(password);
+ getOutput().flush();
+
+ return (String)getInput().readObject();
+ }
+ catch (Throwable t)
+ {
+ throw new ResourceException("Error during login", t);
+ }
+ }
+
+ /**
+ * Call logout
+ * @return boolean
+ * @exception ResourceException Thrown if an error occurs
+ */
+ public boolean logout() throws ResourceException
+ {
+ log.tracef("logout()");
+
+ try
+ {
+ getOutput().writeByte(4);
+ getOutput().flush();
+
+ Boolean result = (Boolean)getInput().readObject();
+
+ return result.booleanValue();
+ }
+ catch (Throwable t)
+ {
+ throw new ResourceException("Error during logout", t);
+ }
+ }
+
+ /**
+ * get auth
+ * @return String
+ * @throws ResourceException Thrown if an error occurs
+ */
+ public String getAuth() throws ResourceException
+ {
+ log.tracef("getAuth()");
+
+ try
+ {
+ getOutput().writeByte(5);
+ getOutput().flush();
+
+ return (String)getInput().readObject();
+ }
+ catch (Throwable t)
+ {
+ throw new ResourceException("Error during getAuth", t);
+ }
+ }
+
+ /**
+ * Get the CRI
+ * @return The value
+ */
+ ReauthCri getCri()
+ {
+ return cri;
+ }
+
+ /**
+ * 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;
+ }
+}
Copied: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthCri.java (from rev 110678, 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/ra/cri/ReauthCri.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthCri.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,156 @@
+/*
+ * 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.ra.cri;
+
+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 ReauthCri implements ConnectionRequestInfo, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private static Logger log = Logger.getLogger(ReauthCri.class);
+
+ private final String userName;
+ private final String password;
+
+ /**
+ * Constructor
+ * @param userName The user name
+ * @param password The password
+ */
+ public ReauthCri(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;
+
+ if (userName != null)
+ hashCode += 7 * userName.hashCode();
+
+ if (password != null)
+ 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 ReauthCri))
+ return false;
+
+ ReauthCri rCri = (ReauthCri)obj;
+
+ boolean result = true;
+ if (result)
+ {
+ if (userName == null)
+ {
+ result = rCri.getUserName() == null;
+ }
+ else
+ {
+ result = userName.equals(rCri.getUserName());
+ }
+ }
+
+ if (result)
+ {
+ if (password == null)
+ {
+ result = rCri.getPassword() == null;
+ }
+ else
+ {
+ result = password.equals(rCri.getPassword());
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * String representation
+ * @return The value
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("ReauthCri@").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/ra/cri/ReauthManagedConnection.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnection.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnection.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,329 @@
+/*
+ * 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.ra.cri;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.PrintWriter;
+import java.net.Socket;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.resource.NotSupportedException;
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionEventListener;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.LocalTransaction;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionMetaData;
+import javax.security.auth.Subject;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ReauthManagedConnection
+ *
+ * @version $Revision: $
+ */
+public class ReauthManagedConnection implements ManagedConnection
+{
+ /** The logger */
+ private static Logger log = Logger.getLogger(ReauthManagedConnection.class);
+
+ /** The managed connection factory */
+ private ReauthManagedConnectionFactory mcf;
+
+ /** The connection listeners */
+ private Set<ConnectionEventListener> listeners;
+
+ /** The logwriter */
+ private PrintWriter logwriter;
+
+ /** Current connection */
+ private ReauthConnectionImpl connection;
+
+ /** The socket */
+ private Socket socket;
+
+ /** Input */
+ private ObjectInputStream ois;
+
+ /** Output */
+ private ObjectOutputStream oos;
+
+ /**
+ * Constructor
+ * @param mcf The managed connection factory
+ * @exception ResourceException Thrown if an error occurs
+ */
+ public ReauthManagedConnection(ReauthManagedConnectionFactory mcf) throws ResourceException
+ {
+ try
+ {
+ this.mcf = mcf;
+ this.listeners = new HashSet<ConnectionEventListener>(1);
+ this.logwriter = null;
+
+ ReauthResourceAdapter rra = (ReauthResourceAdapter)mcf.getResourceAdapter();
+
+ // Note, that this socket instance *should really* be guarded against concurrent access
+ this.socket = new Socket(rra.getServer(), rra.getPort());
+ this.ois = null;
+ this.oos = null;
+
+ // Connect
+ getOutput().writeByte(0);
+ getOutput().flush();
+
+ Boolean granted = (Boolean)getInput().readObject();
+
+ if (!granted.booleanValue())
+ throw new ResourceException("Connection not granted");
+ }
+ catch (Throwable t)
+ {
+ throw new ResourceException("Unable to establish a connection", t);
+ }
+ }
+
+ /**
+ * Creates a new connection handle for the underlying physical connection
+ * represented by the ManagedConnection instance.
+ *
+ * @param subject Security context as JAAS subject
+ * @param cxRequestInfo ConnectionRequestInfo instance
+ * @return generic Object instance representing the connection handle.
+ * @throws ResourceException generic exception if operation fails
+ */
+ public Object getConnection(Subject subject,
+ ConnectionRequestInfo cxRequestInfo)
+ throws ResourceException
+ {
+ log.tracef("getConnection(%s, %s)", subject, cxRequestInfo);
+
+ if (cxRequestInfo == null)
+ throw new ResourceException("ReauthCri is null");
+
+ if (!(cxRequestInfo instanceof ReauthCri))
+ throw new ResourceException("Not a ReauthCri instance: " + cxRequestInfo.getClass().getName());
+
+ ReauthCri cri = (ReauthCri)cxRequestInfo;
+ boolean auth = true;
+
+ if (connection == null)
+ {
+ connection = new ReauthConnectionImpl(socket, cri);
+ }
+ else
+ {
+ if (connection.getCri().getUserName().equals(cri.getUserName()))
+ auth = false;
+ }
+
+ if (auth)
+ {
+ connection.login(cri.getUserName(), cri.getPassword());
+ }
+
+ return connection;
+ }
+
+ /**
+ * Used by the container to change the association of an
+ * application-level connection handle with a ManagedConneciton instance.
+ *
+ * @param connection Application-level connection handle
+ * @throws ResourceException generic exception if operation fails
+ */
+ public void associateConnection(Object connection) throws ResourceException
+ {
+ log.tracef("associateConnection(%s)", connection);
+
+ if (!(connection instanceof ReauthConnectionImpl))
+ throw new ResourceException("Unable to associate connection: " + connection.getClass().getName());
+
+ this.connection = (ReauthConnectionImpl)connection;
+ }
+
+ /**
+ * Application server calls this method to force any cleanup on the ManagedConnection instance.
+ *
+ * @throws ResourceException generic exception if operation fails
+ */
+ public void cleanup() throws ResourceException
+ {
+ log.tracef("cleanup");
+
+ // TODO - connection listeners
+
+ try
+ {
+ // Unauth the interaction
+ getOutput().writeByte(4);
+ getOutput().flush();
+
+ socket.close();
+ }
+ catch (Throwable t)
+ {
+ throw new ResourceException("Error during cleanup", t);
+ }
+ }
+
+ /**
+ * Destroys the physical connection to the underlying resource manager.
+ *
+ * @throws ResourceException generic exception if operation fails
+ */
+ public void destroy() throws ResourceException
+ {
+ log.tracef("destroy");
+
+ try
+ {
+ // Close the interaction
+ getOutput().writeByte(1);
+ getOutput().flush();
+
+ socket.close();
+ }
+ catch (Throwable t)
+ {
+ throw new ResourceException("Error during destroy", t);
+ }
+ }
+
+ /**
+ * Adds a connection event listener to the ManagedConnection instance.
+ *
+ * @param listener A new ConnectionEventListener to be registered
+ */
+ public void addConnectionEventListener(ConnectionEventListener listener)
+ {
+ log.tracef("addConnectionEventListener");
+ listeners.add(listener);
+ }
+
+ /**
+ * Removes an already registered connection event listener from the ManagedConnection instance.
+ *
+ * @param listener already registered connection event listener to be removed
+ */
+ public void removeConnectionEventListener(ConnectionEventListener listener)
+ {
+ log.tracef("removeConnectionEventListener");
+ listeners.remove(listener);
+ }
+
+ /**
+ * Gets the log writer for this ManagedConnection instance.
+ *
+ * @return Character ourput stream associated with this Managed-Connection instance
+ * @throws ResourceException generic exception if operation fails
+ */
+ public PrintWriter getLogWriter() throws ResourceException
+ {
+ log.tracef("getLogWriter");
+ return logwriter;
+ }
+
+ /**
+ * Sets the log writer for this ManagedConnection instance.
+ *
+ * @param out Character Output stream to be associated
+ * @throws ResourceException generic exception if operation fails
+ */
+ public void setLogWriter(PrintWriter out) throws ResourceException
+ {
+ log.tracef("setLogWriter(%s)", out);
+ this.logwriter = out;
+ }
+
+ /**
+ * Returns an <code>javax.resource.spi.LocalTransaction</code> instance.
+ *
+ * @return LocalTransaction instance
+ * @throws ResourceException generic exception if operation fails
+ */
+ public LocalTransaction getLocalTransaction() throws ResourceException
+ {
+ log.tracef("getLocalTransaction()");
+
+ throw new NotSupportedException();
+ }
+
+ /**
+ * Returns an <code>javax.transaction.xa.XAresource</code> instance.
+ *
+ * @return XAResource instance
+ * @throws ResourceException generic exception if operation fails
+ */
+ public XAResource getXAResource() throws ResourceException
+ {
+ log.tracef("getXAResource()");
+
+ throw new NotSupportedException();
+ }
+
+ /**
+ * Gets the metadata information for this connection's underlying EIS resource manager instance.
+ *
+ * @return ManagedConnectionMetaData instance
+ * @throws ResourceException generic exception if operation fails
+ */
+ public ManagedConnectionMetaData getMetaData() throws ResourceException
+ {
+ log.tracef("getMetaData()");
+
+ return new ReauthManagedConnectionMetaData(socket);
+ }
+
+ /**
+ * 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/ra/cri/ReauthManagedConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionFactory.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionFactory.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,227 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.ra.cri;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterAssociation;
+import javax.security.auth.Subject;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ReauthManagedConnectionFactory
+ *
+ * @version $Revision: $
+ */
+public class ReauthManagedConnectionFactory implements ManagedConnectionFactory, ResourceAdapterAssociation
+{
+ /** The serial version UID */
+ private static final long serialVersionUID = 1L;
+
+ /** The logger */
+ private static Logger log = Logger.getLogger(ReauthManagedConnectionFactory.class);
+
+ /** The resource adapter */
+ private ResourceAdapter ra;
+
+ /** The logwriter */
+ private PrintWriter logwriter;
+
+ /**
+ * Default constructor
+ */
+ public ReauthManagedConnectionFactory()
+ {
+ this.ra = null;
+ this.logwriter = null;
+ }
+
+ /**
+ * Creates a Connection Factory instance.
+ *
+ * @param cxManager ConnectionManager to be associated with created EIS connection factory instance
+ * @return EIS-specific Connection Factory instance or javax.resource.cci.ConnectionFactory instance
+ * @throws ResourceException Generic exception
+ */
+ public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException
+ {
+ if (ra == null)
+ throw new IllegalStateException("RA is null");
+
+ log.tracef("createConnectionFactory(%s)", cxManager);
+
+ return new ReauthConnectionFactoryImpl(this, cxManager);
+ }
+
+ /**
+ * Creates a Connection Factory instance.
+ *
+ * @return EIS-specific Connection Factory instance or javax.resource.cci.ConnectionFactory instance
+ * @throws ResourceException Generic exception
+ */
+ public Object createConnectionFactory() throws ResourceException
+ {
+ throw new ResourceException("Non-managed environment not supported");
+ }
+
+ /**
+ * Creates a new physical connection to the underlying EIS resource manager.
+ *
+ * @param subject Caller's security information
+ * @param cxRequestInfo Additional resource adapter specific connection request information
+ * @return ManagedConnection instance
+ * @throws ResourceException generic exception
+ */
+ public ManagedConnection createManagedConnection(Subject subject,
+ ConnectionRequestInfo cxRequestInfo)
+ throws ResourceException
+ {
+ if (ra == null)
+ throw new IllegalStateException("RA is null");
+
+ log.tracef("createManagedConnection(%s, %s)", subject, cxRequestInfo);
+
+ return new ReauthManagedConnection(this);
+ }
+
+ /**
+ * Returns a matched connection from the candidate set of connections.
+ *
+ * @param connectionSet Candidate connection set
+ * @param subject Caller's security information
+ * @param cxRequestInfo Additional resource adapter specific connection request information
+ * @return ManagedConnection if resource adapter finds an acceptable match otherwise null
+ * @throws ResourceException generic exception
+ */
+ public ManagedConnection matchManagedConnections(Set connectionSet,
+ Subject subject,
+ ConnectionRequestInfo cxRequestInfo)
+ throws ResourceException
+ {
+ if (ra == null)
+ throw new IllegalStateException("RA is null");
+
+ log.tracef("matchManagedConnections(%s, %s, %s)", connectionSet, subject, cxRequestInfo);
+
+ ManagedConnection result = null;
+
+ Iterator it = connectionSet.iterator();
+ while (result == null && it.hasNext())
+ {
+ ManagedConnection mc = (ManagedConnection)it.next();
+
+ if (mc instanceof ReauthManagedConnection)
+ {
+ result = mc;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Get the log writer for this ManagedConnectionFactory instance.
+ *
+ * @return PrintWriter
+ * @throws ResourceException generic exception
+ */
+ public PrintWriter getLogWriter() throws ResourceException
+ {
+ log.tracef("getLogWriter()");
+ return logwriter;
+ }
+
+ /**
+ * Set the log writer for this ManagedConnectionFactory instance.
+ *
+ * @param out PrintWriter - an out stream for error logging and tracing
+ * @throws ResourceException generic exception
+ */
+ public void setLogWriter(PrintWriter out) throws ResourceException
+ {
+ log.tracef("setLogWriter(%s)", out);
+ logwriter = out;
+ }
+
+ /**
+ * Get the resource adapter
+ *
+ * @return The handle
+ */
+ public ResourceAdapter getResourceAdapter()
+ {
+ log.tracef("getResourceAdapter()");
+ return ra;
+ }
+
+ /**
+ * Set the resource adapter
+ *
+ * @param ra The handle
+ */
+ public void setResourceAdapter(ResourceAdapter ra)
+ {
+ log.tracef("setResourceAdapter(%s)", ra);
+ this.ra = ra;
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ * @return A hash code value for this object.
+ */
+ @Override
+ public int hashCode()
+ {
+ return 17;
+ }
+
+ /**
+ * Indicates whether some other object is equal to this one.
+ * @param other The reference object with which to compare.
+ * @return true if this object is the same as the obj argument, false otherwise.
+ */
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other == null)
+ return false;
+
+ if (other == this)
+ return true;
+
+ if (!(other instanceof ReauthManagedConnectionFactory))
+ return false;
+
+ ReauthManagedConnectionFactory obj = (ReauthManagedConnectionFactory)other;
+
+ return true;
+ }
+}
Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionMetaData.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionMetaData.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionMetaData.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,169 @@
+/*
+ * 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.ra.cri;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.Socket;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ManagedConnectionMetaData;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ReauthManagedConnectionMetaData
+ *
+ * @version $Revision: $
+ */
+public class ReauthManagedConnectionMetaData implements ManagedConnectionMetaData
+{
+ /** The logger */
+ private static Logger log = Logger.getLogger(ReauthManagedConnectionMetaData.class);
+
+ /** The socket */
+ private Socket socket;
+
+ /** Input */
+ private ObjectInputStream ois;
+
+ /** Output */
+ private ObjectOutputStream oos;
+
+ /**
+ * Constructor
+ * @param socket The socket
+ */
+ public ReauthManagedConnectionMetaData(Socket socket)
+ {
+ this.socket = socket;
+ this.ois = null;
+ this.oos = null;
+ }
+
+ /**
+ * Returns Product name of the underlying EIS instance connected through the ManagedConnection.
+ *
+ * @return Product name of the EIS instance
+ * @throws ResourceException Thrown if an error occurs
+ */
+ @Override
+ public String getEISProductName() throws ResourceException
+ {
+ log.tracef("getEISProductName()");
+
+ return "Reauth resource adapter (CRI)";
+ }
+
+ /**
+ * Returns Product version of the underlying EIS instance connected through the ManagedConnection.
+ *
+ * @return Product version of the EIS instance
+ * @throws ResourceException Thrown if an error occurs
+ */
+ @Override
+ public String getEISProductVersion() throws ResourceException
+ {
+ log.tracef("getEISProductVersion()");
+
+ return "1.0";
+ }
+
+ /**
+ * Returns maximum limit on number of active concurrent connections
+ *
+ * @return Maximum limit for number of active concurrent connections
+ * @throws ResourceException Thrown if an error occurs
+ */
+ @Override
+ public int getMaxConnections() throws ResourceException
+ {
+ log.tracef("getMaxConnections()");
+
+ try
+ {
+ getOutput().writeByte(6);
+ getOutput().flush();
+
+ Integer result = (Integer)getInput().readObject();
+
+ return result.intValue();
+ }
+ catch (Throwable t)
+ {
+ throw new ResourceException("Error during getUserName()", t);
+ }
+ }
+
+ /**
+ * Returns name of the user associated with the ManagedConnection instance
+ *
+ * @return Name of the user
+ * @throws ResourceException Thrown if an error occurs
+ */
+ @Override
+ public String getUserName() throws ResourceException
+ {
+ log.tracef("getUserName()");
+
+ try
+ {
+ getOutput().writeByte(5);
+ getOutput().flush();
+
+ return (String)getInput().readObject();
+ }
+ catch (Throwable t)
+ {
+ throw new ResourceException("Error during getUserName()", t);
+ }
+ }
+
+ /**
+ * 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/ra/cri/ReauthResourceAdapter.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthResourceAdapter.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthResourceAdapter.java 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,216 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.ra.cri;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+
+import javax.transaction.xa.XAResource;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ReauthResourceAdapter
+ *
+ * @version $Revision: $
+ */
+public class ReauthResourceAdapter implements ResourceAdapter
+{
+ /** The logger */
+ private static Logger log = Logger.getLogger(ReauthResourceAdapter.class);
+
+ /** Server */
+ private String server;
+
+ /** Port */
+ private Integer port;
+
+ /**
+ * Default constructor
+ */
+ public ReauthResourceAdapter()
+ {
+ this.server = null;
+ this.port = null;
+ }
+
+ /**
+ * Set server
+ * @param server The value
+ */
+ public void setServer(String server)
+ {
+ this.server = server;
+ }
+
+ /**
+ * Get server
+ * @return The value
+ */
+ public String getServer()
+ {
+ return server;
+ }
+
+ /**
+ * Set port
+ * @param port The value
+ */
+ public void setPort(Integer port)
+ {
+ this.port = port;
+ }
+
+ /**
+ * Get Port
+ * @return The value
+ */
+ public Integer getPort()
+ {
+ return port;
+ }
+
+ /**
+ * This is called during the activation of a message endpoint.
+ *
+ * @param endpointFactory A message endpoint factory instance.
+ * @param spec An activation spec JavaBean instance.
+ * @throws ResourceException generic exception
+ */
+ public void endpointActivation(MessageEndpointFactory endpointFactory,
+ ActivationSpec spec)
+ throws ResourceException
+ {
+ log.tracef("endpointActivation");
+ }
+
+ /**
+ * This is called when a message endpoint is deactivated.
+ *
+ * @param endpointFactory A message endpoint factory instance.
+ * @param spec An activation spec JavaBean instance.
+ */
+ public void endpointDeactivation(MessageEndpointFactory endpointFactory,
+ ActivationSpec spec)
+ {
+ log.tracef("endpointDeactivation");
+ }
+
+ /**
+ * This is called when a resource adapter instance is bootstrapped.
+ *
+ * @param ctx A bootstrap context containing references
+ * @throws ResourceAdapterInternalException indicates bootstrap failure.
+ */
+ public void start(BootstrapContext ctx) throws ResourceAdapterInternalException
+ {
+ log.tracef("start");
+ }
+
+ /**
+ * This is called when a resource adapter instance is undeployed or
+ * during application server shutdown.
+ */
+ public void stop()
+ {
+ log.tracef("stop");
+ }
+
+ /**
+ * This method is called by the application server during crash recovery.
+ *
+ * @param specs An array of ActivationSpec JavaBeans
+ * @throws ResourceException generic exception
+ * @return An array of XAResource objects
+ */
+ public XAResource[] getXAResources(ActivationSpec[] specs)
+ throws ResourceException
+ {
+ log.tracef("getXAResources");
+ return null;
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ * @return A hash code value for this object.
+ */
+ @Override
+ public int hashCode()
+ {
+ int result = 17;
+
+ if (server != null)
+ result += 31 * result + 7 * server.hashCode();
+ else
+ result += 31 * result + 7;
+
+ if (port != null)
+ result += 31 * result + 7 * port.hashCode();
+ else
+ result += 31 * result + 7;
+
+ return result;
+ }
+
+ /**
+ * Indicates whether some other object is equal to this one.
+ * @param other The reference object with which to compare.
+ * @return true if this object is the same as the obj argument, false otherwise.
+ */
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other == null)
+ return false;
+
+ if (other == this)
+ return true;
+
+ if (!(other instanceof ReauthResourceAdapter))
+ return false;
+
+ ReauthResourceAdapter obj = (ReauthResourceAdapter)other;
+ boolean result = true;
+
+ if (result)
+ {
+ if (server == null)
+ result = obj.getServer() == null;
+ else
+ result = server.equals(obj.getServer());
+ }
+
+ if (result)
+ {
+ if (port == null)
+ result = obj.getPort() == null;
+ else
+ result = port.equals(obj.getPort());
+ }
+
+ return result;
+ }
+}
Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/package.html 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,3 @@
+<body>
+This package contains the reauth resource adapter using CRI.
+</body>
Added: projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/META-INF/ironjacamar.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/META-INF/ironjacamar.xml (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/META-INF/ironjacamar.xml 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+/*
+ * 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.
+ */
+-->
+
+<ironjacamar xmlns="http://www.jboss.org/ironjacamar/schema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema
+ http://www.jboss.org/ironjacamar/schema/ironjacamar_1_0.xsd">
+ <config-property name="Server">localhost</config-property>
+ <config-property name="Port">19000</config-property>
+
+ <transaction-support>NoTransaction</transaction-support>
+
+ <connection-definitions>
+ <connection-definition class-name="org.jboss.jca.core.security.reauth.ra.cri.ReauthManagedConnectionFactory"
+ enabled="true" jndi-name="java:/eis/Reauth"
+ use-java-context="true" pool-name="Reauth">
+ <pool>
+ <min-pool-size>0</min-pool-size>
+ <max-pool-size>1</max-pool-size>
+ </pool>
+ </connection-definition>
+ </connection-definitions>
+
+</ironjacamar>
Added: projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/META-INF/ra.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/META-INF/ra.xml (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/resources/rars/security/reauth/cri/META-INF/ra.xml 2011-02-16 15:40:03 UTC (rev 110688)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+/*
+ * 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.
+ */
+-->
+
+<connector xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
+ version="1.5">
+
+ <vendor-name>JBoss, Red Hat</vendor-name>
+ <eis-type>Reauth resource adapter (CRI)</eis-type>
+ <resourceadapter-version>1.0</resourceadapter-version>
+ <resourceadapter>
+ <resourceadapter-class>org.jboss.jca.core.security.reauth.ra.cri.ReauthResourceAdapter</resourceadapter-class>
+ <config-property>
+ <config-property-name>Server</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ <config-property-value>localhost</config-property-value>
+ </config-property>
+
+ <config-property>
+ <config-property-name>Port</config-property-name>
+ <config-property-type>java.lang.Integer</config-property-type>
+ <config-property-value>19000</config-property-value>
+ </config-property>
+
+ <outbound-resourceadapter>
+ <connection-definition>
+ <managedconnectionfactory-class>org.jboss.jca.core.security.reauth.ra.cri.ReauthManagedConnectionFactory</managedconnectionfactory-class>
+ <connectionfactory-interface>org.jboss.jca.core.security.reauth.ra.cri.ReauthConnectionFactory</connectionfactory-interface>
+ <connectionfactory-impl-class>org.jboss.jca.core.security.reauth.ra.cri.ReauthConnectionFactoryImpl</connectionfactory-impl-class>
+ <connection-interface>org.jboss.jca.core.security.reauth.ra.cri.ReauthConnection</connection-interface>
+ <connection-impl-class>org.jboss.jca.core.security.reauth.ra.cri.ReauthConnectionImpl</connection-impl-class>
+ </connection-definition>
+ <transaction-support>NoTransaction</transaction-support>
+ <reauthentication-support>true</reauthentication-support>
+ </outbound-resourceadapter>
+ </resourceadapter>
+</connector>
More information about the jboss-cvs-commits
mailing list