You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ad...@apache.org on 2004/03/10 03:15:51 UTC

cvs commit: incubator-geronimo/modules/security/src/test/org/apache/geronimo/security/network/protocol SubjectCarryingProtocolTest.java TestProtocol.java

adc         2004/03/09 18:15:51

  Modified:    modules/security project.xml
               modules/security/src/test/org/apache/geronimo/security
                        AbstractTest.java
               modules/security/src/test/org/apache/geronimo/security/jaas
                        LoginSQLTest.java
  Added:       modules/security/src/java/org/apache/geronimo/security/network/protocol
                        PassthroughDownPacket.java PassthroughUpPacket.java
                        SubjectCarryingClientProtocol.java
                        SubjectCarryingPacketReader.java
                        SubjectCarryingPackets.java
                        SubjectCarryingServerProtocol.java
                        SubjectCarryingUpPacket.java
                        SubjectCaryingDownPacket.java
               modules/security/src/test/org/apache/geronimo/security/network/protocol
                        SubjectCarryingProtocolTest.java TestProtocol.java
  Log:
  Networking code that implements stacked protocols.  Checking in work
  before I loose it.
  
  Revision  Changes    Path
  1.10      +13 -1     incubator-geronimo/modules/security/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/security/project.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- project.xml	19 Feb 2004 09:00:28 -0000	1.9
  +++ project.xml	10 Mar 2004 02:15:50 -0000	1.10
  @@ -65,7 +65,19 @@
   
           <dependency>
               <groupId>geronimo</groupId>
  +            <artifactId>geronimo-network</artifactId>
  +            <version>${pom.currentVersion}</version>
  +        </dependency>
  +
  +        <dependency>
  +            <groupId>geronimo</groupId>
               <artifactId>geronimo-deployment</artifactId>
  +            <version>${pom.currentVersion}</version>
  +        </dependency>
  +
  +        <dependency>
  +            <groupId>geronimo</groupId>
  +            <artifactId>geronimo-system</artifactId>
               <version>${pom.currentVersion}</version>
           </dependency>
   
  
  
  
  1.1                  incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/network/protocol/PassthroughDownPacket.java
  
  Index: PassthroughDownPacket.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  import java.util.Collection;
  
  import org.apache.geronimo.network.protocol.util.ByteKeyDownPacket;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  public class PassthroughDownPacket extends ByteKeyDownPacket implements SubjectCarryingPackets {
  
      private Collection buffers;
  
      public PassthroughDownPacket() {
          super(PASSTHROUGH);
      }
  
      public void setBuffers(Collection buffers) {
          this.buffers = buffers;
      }
  
      protected Collection getChildBuffers() {
          return buffers;
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/network/protocol/PassthroughUpPacket.java
  
  Index: PassthroughUpPacket.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  import java.nio.ByteBuffer;
  
  import org.apache.geronimo.network.protocol.PacketFactory;
  import org.apache.geronimo.network.protocol.ProtocolException;
  import org.apache.geronimo.network.protocol.UpPacket;
  import org.apache.geronimo.network.protocol.util.ByteKeyUpPacket;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  public class PassthroughUpPacket extends ByteKeyUpPacket implements PacketFactory, SubjectCarryingPackets {
  
      public PassthroughUpPacket() {
          super(PASSTHROUGH);
      }
  
      public UpPacket create(ByteBuffer buffer) throws ProtocolException {
          return new PassthroughUpPacket();
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingClientProtocol.java
  
  Index: SubjectCarryingClientProtocol.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  import javax.security.auth.Subject;
  
  import java.security.AccessController;
  import java.util.Collection;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.geronimo.network.protocol.AbstractProtocol;
  import org.apache.geronimo.network.protocol.DownPacket;
  import org.apache.geronimo.network.protocol.ProtocolException;
  import org.apache.geronimo.network.protocol.UpPacket;
  import org.apache.geronimo.security.IdentificationPrincipal;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  public class SubjectCarryingClientProtocol extends AbstractProtocol {
  
      final static private Log log = LogFactory.getLog(SubjectCarryingClientProtocol.class);
  
      private Subject clientSubject;
  
      public void doStart() throws ProtocolException {
          log.trace("Starting");
      }
  
      public void doStop() throws ProtocolException {
          log.trace("Stopping");
      }
  
      public void sendUp(UpPacket packet) throws ProtocolException {
          getUp().sendUp(packet);
      }
  
      public void sendDown(DownPacket packet) throws ProtocolException {
          Subject subject = Subject.getSubject(AccessController.getContext());
          if (clientSubject == subject) {
              PassthroughDownPacket passthroughPacket = new PassthroughDownPacket();
              passthroughPacket.setBuffers(packet.getBuffers());
  
              getDown().sendDown(passthroughPacket);
          } else {
              clientSubject = subject;
              Collection principals = clientSubject.getPrincipals(IdentificationPrincipal.class);
  
              if (principals.isEmpty()) {
                  PassthroughDownPacket passthroughPacket = new PassthroughDownPacket();
                  passthroughPacket.setBuffers(packet.getBuffers());
  
                  getDown().sendDown(passthroughPacket);
              } else {
                  IdentificationPrincipal principal = (IdentificationPrincipal) principals.iterator().next();
  
                  SubjectCaryingDownPacket subjectPacket = new SubjectCaryingDownPacket();
                  subjectPacket.setSubjectId(principal.getId());
                  subjectPacket.setBuffers(packet.getBuffers());
  
                  getDown().sendDown(subjectPacket);
              }
          }
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingPacketReader.java
  
  Index: SubjectCarryingPacketReader.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  import org.apache.geronimo.network.protocol.util.ByteKeyUpPacketReader;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  class SubjectCarryingPacketReader extends ByteKeyUpPacketReader implements SubjectCarryingPackets {
  
      private static SubjectCarryingPacketReader ourInstance = new SubjectCarryingPacketReader();
  
      public static SubjectCarryingPacketReader getInstance() {
          return ourInstance;
      }
  
      private SubjectCarryingPacketReader() {
          register(PASSTHROUGH, new PassthroughUpPacket());
          register(SUBJECT, new SubjectCarryingUpPacket());
      }
  }
  
  
  1.1                  incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingPackets.java
  
  Index: SubjectCarryingPackets.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  interface SubjectCarryingPackets {
  
      final byte PASSTHROUGH = (byte)0x00;
      final byte SUBJECT = (byte)0x01;
  }
  
  
  
  1.1                  incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingServerProtocol.java
  
  Index: SubjectCarryingServerProtocol.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  import javax.security.auth.Subject;
  
  import java.util.ArrayList;
  import java.util.Collection;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.geronimo.network.protocol.AbstractProtocol;
  import org.apache.geronimo.network.protocol.DownPacket;
  import org.apache.geronimo.network.protocol.ProtocolException;
  import org.apache.geronimo.network.protocol.UpPacket;
  import org.apache.geronimo.network.protocol.MetadataSupport;
  import org.apache.geronimo.network.protocol.control.BootstrapCook;
  import org.apache.geronimo.network.protocol.control.ControlContext;
  import org.apache.geronimo.network.protocol.control.commands.CreateInstanceMenuItem;
  import org.apache.geronimo.security.SubjectId;
  import org.apache.geronimo.security.ContextManager;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  public class SubjectCarryingServerProtocol extends AbstractProtocol implements BootstrapCook {
  
      final static private Log log = LogFactory.getLog(SubjectCarryingServerProtocol.class);
  
      private Subject clientSubject;
  
      public void doStart() throws ProtocolException {
          log.trace("Starting");
      }
  
      public void doStop() throws ProtocolException {
          log.trace("Stopping");
      }
  
      public void sendUp(UpPacket packet) throws ProtocolException {
          log.trace("sendUp");
          UpPacket p = SubjectCarryingPacketReader.getInstance().read(packet.getBuffer());
          if (p instanceof PassthroughUpPacket) {
              MetadataSupport.setSubject(packet, clientSubject);
              getUp().sendUp(packet);
          } else if (p instanceof SubjectCarryingUpPacket) {
              SubjectCarryingUpPacket subjectPacket = (SubjectCarryingUpPacket)p;
              clientSubject = ContextManager.getRegisteredSubject(subjectPacket.getSubjectId());
  
              MetadataSupport.setSubject(packet, clientSubject);
              getUp().sendUp(packet);
          }
      }
  
      public void sendDown(DownPacket packet) throws ProtocolException {
          log.trace("sendDown");
          getDown().sendDown(packet);
      }
  
      public Collection cook(ControlContext context) {
          ArrayList list = new ArrayList(1);
  
          CreateInstanceMenuItem create = new CreateInstanceMenuItem();
          create.setClassName("org.apache.geronimo.security.network.protocol.SubjectCarryingClientProtocol");
          create.setInstanceId(context.assignId(this));
          list.add(create);
  
          return list;
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingUpPacket.java
  
  Index: SubjectCarryingUpPacket.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  import java.nio.ByteBuffer;
  
  import org.apache.geronimo.network.protocol.PacketFactory;
  import org.apache.geronimo.network.protocol.ProtocolException;
  import org.apache.geronimo.network.protocol.UpPacket;
  import org.apache.geronimo.network.protocol.util.ByteKeyUpPacket;
  import org.apache.geronimo.network.protocol.util.PacketUtil;
  import org.apache.geronimo.security.SubjectId;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  class SubjectCarryingUpPacket extends ByteKeyUpPacket implements PacketFactory, SubjectCarryingPackets {
  
      private SubjectId subjectId;
  
      public SubjectCarryingUpPacket() {
          super(SUBJECT);
      }
  
      public SubjectId getSubjectId() {
          return subjectId;
      }
  
      public UpPacket create(ByteBuffer buffer) throws ProtocolException {
          Long id = PacketUtil.getLong(buffer);
          byte[] hash = PacketUtil.getByteArray(buffer);
  
          SubjectCarryingUpPacket packet = new SubjectCarryingUpPacket();
          packet.setBuffer(buffer);
          packet.subjectId = new SubjectId(id, hash);
  
          return packet;
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCaryingDownPacket.java
  
  Index: SubjectCaryingDownPacket.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  import java.util.ArrayList;
  import java.util.Collection;
  
  import org.apache.geronimo.network.protocol.util.ByteKeyDownPacket;
  import org.apache.geronimo.network.protocol.util.PacketUtil;
  import org.apache.geronimo.security.SubjectId;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  class SubjectCaryingDownPacket extends ByteKeyDownPacket implements SubjectCarryingPackets {
  
      private SubjectId subjectId;
      private Collection buffers;
  
      public SubjectCaryingDownPacket() {
          super(SUBJECT);
      }
  
      public SubjectId getSubjectId() {
          return subjectId;
      }
  
      public void setSubjectId(SubjectId subjectId) {
          this.subjectId = subjectId;
      }
  
      protected Collection getChildBuffers() {
          ArrayList list = new ArrayList(2 + buffers.size());
  
          list.add(PacketUtil.putLong(subjectId.getSubjectId()).flip());
          list.add(PacketUtil.putByteArray(subjectId.getHash()).flip());
  
          list.addAll(buffers);
  
          return list;
      }
  
      public void setBuffers(Collection buffers) {
          this.buffers = buffers;
      }
  
  }
  
  
  
  1.3       +2 -2      incubator-geronimo/modules/security/src/test/org/apache/geronimo/security/AbstractTest.java
  
  Index: AbstractTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/security/src/test/org/apache/geronimo/security/AbstractTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractTest.java	25 Feb 2004 09:58:10 -0000	1.2
  +++ AbstractTest.java	10 Mar 2004 02:15:50 -0000	1.3
  @@ -59,7 +59,7 @@
           loginService = new ObjectName("geronimo.security:type=LoginService");
           gbean.setReferencePatterns("Realms", Collections.singleton(new ObjectName("geronimo.security:type=SecurityRealm,*")));
           gbean.setAttribute("Kernel", kernel);
  -        gbean.setAttribute("ReclaimPeriod", new Long(100));
  +        gbean.setAttribute("ReclaimPeriod", new Long(10 * 1000));  // todo check other tests to see if ok
           gbean.setAttribute("Algorithm", "HmacSHA1");
           gbean.setAttribute("Password", "secret");
           kernel.loadGBean(loginService, gbean);
  
  
  
  1.4       +2 -2      incubator-geronimo/modules/security/src/test/org/apache/geronimo/security/jaas/LoginSQLTest.java
  
  Index: LoginSQLTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/security/src/test/org/apache/geronimo/security/jaas/LoginSQLTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LoginSQLTest.java	25 Feb 2004 09:58:10 -0000	1.3
  +++ LoginSQLTest.java	10 Mar 2004 02:15:50 -0000	1.4
  @@ -137,7 +137,7 @@
           IdentificationPrincipal principal = (IdentificationPrincipal) subject.getPrincipals(IdentificationPrincipal.class).iterator().next();
           assertTrue("id of principal should be non-zero", principal.getId().getSubjectId().longValue() != 0);
   
  -        Thread.sleep(2 * 1000);
  +        Thread.sleep(20 * 1000);
   
           try {
               context.logout();
  
  
  
  1.1                  incubator-geronimo/modules/security/src/test/org/apache/geronimo/security/network/protocol/SubjectCarryingProtocolTest.java
  
  Index: SubjectCarryingProtocolTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  import javax.management.ObjectName;
  import javax.security.auth.Subject;
  import javax.security.auth.login.AppConfigurationEntry;
  import javax.security.auth.login.Configuration;
  import javax.security.auth.login.LoginContext;
  
  import java.io.File;
  import java.net.InetSocketAddress;
  import java.net.URI;
  import java.nio.ByteBuffer;
  import java.security.PrivilegedActionException;
  import java.security.PrivilegedExceptionAction;
  import java.util.ArrayList;
  import java.util.HashMap;
  
  import EDU.oswego.cs.dl.util.concurrent.Mutex;
  import com.sun.security.auth.login.ConfigFile;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.geronimo.gbean.jmx.GBeanMBean;
  import org.apache.geronimo.network.SelectorManager;
  import org.apache.geronimo.network.protocol.CountingProtocol;
  import org.apache.geronimo.network.protocol.PlainDownPacket;
  import org.apache.geronimo.network.protocol.ProtocolFactory;
  import org.apache.geronimo.network.protocol.ServerSocketAcceptor;
  import org.apache.geronimo.network.protocol.SocketProtocol;
  import org.apache.geronimo.network.protocol.control.ControlClientProtocol;
  import org.apache.geronimo.network.protocol.control.ControlClientProtocolStack;
  import org.apache.geronimo.network.protocol.control.ControlServerListener;
  import org.apache.geronimo.network.protocol.control.ControlServerProtocol;
  import org.apache.geronimo.network.protocol.control.ControlServerProtocolStack;
  import org.apache.geronimo.network.protocol.control.ControlServerProtocolWaiter;
  import org.apache.geronimo.security.AbstractTest;
  import org.apache.geronimo.security.jaas.GeronimoLoginConfiguration;
  import org.apache.geronimo.system.ClockPool;
  import org.apache.geronimo.system.ThreadPool;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  public class SubjectCarryingProtocolTest extends AbstractTest {
  
      final static private Log log = LogFactory.getLog(SubjectCarryingProtocolTest.class);
  
      protected ObjectName propertiesRealm;
      protected ObjectName propertiesCE;
  
      private Subject clientSubject;
      private Subject serverSubject;
      private Mutex startMutex = new Mutex();
      private Mutex shutdownMutex = new Mutex();
      private ThreadGroup threadGroup;
  
      public void testDummy() throws Exception {
      }
  
      public void test() throws Exception {
  
          shutdownMutex.acquire();
  
          new Thread(threadGroup, new ServerThread(serverSubject), "Geronimo server").start();
  
          startMutex.acquire();
          startMutex.release();
  
          PrivilegedExceptionAction clientAction = new ClientAction();
          Subject.doAs(clientSubject, clientAction);
      }
  
      class ClientAction implements PrivilegedExceptionAction {
  
          public Object run() throws Exception {
              ThreadPool tp = new ThreadPool();
              tp.setKeepAliveTime(1 * 1000);
              tp.setMinimumPoolSize(1);
              tp.setMaximumPoolSize(5);
              tp.setPoolName("Client TP");
              tp.doStart();
  
              ClockPool cp = new ClockPool();
              cp.setPoolName("Client CP");
              cp.doStart();
  
              SelectorManager sm = new SelectorManager();
              sm.setThreadPool(tp);
              sm.setThreadName("Client Selector Manager");
              sm.doStart();
  
              ControlClientProtocolStack clientStack = new ControlClientProtocolStack();
              clientStack.setClassLoader(Thread.currentThread().getContextClassLoader());
              clientStack.setThreadPool(tp);
              clientStack.setClockPool(cp);
              clientStack.setSelectorManager(sm);
  
              SocketProtocol sp = new SocketProtocol();
              sp.setTimeout(1000 * 1000); //todo reset to 10s
              sp.setInterface(new InetSocketAddress("localhost", 0));
              sp.setAddress(new InetSocketAddress("localhost", 8081));
              sp.setSelectorManager(sm);
  
              clientStack.push(sp);
  
              ControlClientProtocol ccp = new ControlClientProtocol();
              ccp.setTimeout(1000 * 1000); //todo set to 10s
  
              clientStack.push(ccp);
  
              clientStack.doStart();
  
              clientStack.sendDown(getPlainPacket());
              clientStack.sendDown(getPlainPacket());
              clientStack.sendDown(getPlainPacket());
  
              Thread.sleep(5 * 1000);
  
              clientStack.doStop();
  
              shutdownMutex.release();
  
              sm.doStop();
  
              cp.doStop();
  
              tp.doStop();
  
              return null;
          }
      }
  
      class ServerThread implements Runnable {
  
          private Subject subject;
  
          ServerThread(Subject subject) {
              this.subject = subject;
          }
  
          public void run() {
              try {
                  PrivilegedExceptionAction serverAction = new ServerAction();
                  Subject.doAs(subject, serverAction);
              } catch (PrivilegedActionException e) {
                  e.printStackTrace();
              }
          }
      }
  
      class ServerAction implements PrivilegedExceptionAction {
  
          public Object run() throws Exception {
              ThreadPool tp = new ThreadPool();
              tp.setKeepAliveTime(1 * 1000);
              tp.setMinimumPoolSize(1);
              tp.setMaximumPoolSize(5);
              tp.setPoolName("Server TP");
              tp.doStart();
  
              ClockPool cp = new ClockPool();
              cp.setPoolName("Server CP");
              cp.doStart();
  
              SelectorManager sm = new SelectorManager();
              sm.setThreadPool(tp);
              sm.setThreadName("Server Selector Manager");
              sm.doStart();
  
              ControlServerProtocolStack templateStack = new ControlServerProtocolStack();
  
              SocketProtocol spt = new SocketProtocol();
              spt.setTimeout(10 * 1000);
              spt.setSelectorManager(sm);
  
              templateStack.push(spt);
  
              ControlServerProtocol csp = new ControlServerProtocol();
              csp.setTimeout(1 * 1000);
              csp.setThreadPool(tp);
              csp.setClockPool(cp);
              csp.setSelectorManager(sm);
              csp.setControlServerListener(new ControlServerListener() {
                  public void shutdown() {
                      log.trace("SERVER SIDE SHUTDOWN");
                  }
              });
  
              templateStack.push(csp);
  
              ControlServerProtocolWaiter waiter = new ControlServerProtocolWaiter();
  
              SubjectCarryingServerProtocol scp = new SubjectCarryingServerProtocol();
  
              waiter.push(scp);
  
              waiter.push(new CountingProtocol());
  
              TestProtocol test = new TestProtocol();
              test.setValue("SimpleTest");
              test.setThreadPool(tp);
              test.setClockPool(cp);
              test.setSelectorManager(sm);
  
              waiter.push(test);
  
              templateStack.push(waiter);
  
              ProtocolFactory pf = new ProtocolFactory();
              pf.setClockPool(cp);
              pf.setMaxAge(Long.MAX_VALUE);
              pf.setMaxInactivity(1 * 60 * 60 * 1000);
              pf.setReclaimPeriod(10 * 1000);
              pf.setTemplate(templateStack);
  
              ServerSocketAcceptor ssa = new ServerSocketAcceptor();
              ssa.setSelectorManager(sm);
              ssa.setTimeOut(5 * 1000);
              ssa.setUri(new URI("async://localhost:8081/?tcp.nodelay=true&tcp.backlog=5#"));
              ssa.setAcceptorListener(pf);
              ssa.doStart();
  
              startMutex.release();
  
              shutdownMutex.acquire();
  
              ssa.doStop();
  
              pf.doStop();
  
              sm.doStop();
  
              cp.doStop();
  
              tp.doStop();
  
              shutdownMutex.release();
  
              return null;
          }
      }
  
      public void setUp() throws Exception {
          Configuration.setConfiguration(new GeronimoLoginConfiguration());
  
          super.setUp();
  
          GBeanMBean gbean = new GBeanMBean("org.apache.geronimo.security.realm.providers.PropertiesFileSecurityRealm");
          propertiesRealm = new ObjectName("geronimo.security:type=SecurityRealm,realm=properties-realm");
          gbean.setAttribute("RealmName", "properties-realm");
          gbean.setAttribute("MaxLoginModuleAge", new Long(1 * 1000));
          gbean.setAttribute("UsersURI", (new File(new File("."), "src/test-data/data/users.properties")).toURI());
          gbean.setAttribute("GroupsURI", (new File(new File("."), "src/test-data/data/groups.properties")).toURI());
          kernel.loadGBean(propertiesRealm, gbean);
  
          gbean = new GBeanMBean("org.apache.geronimo.security.jaas.ConfigurationEntryRealmLocal");
          propertiesCE = new ObjectName("geronimo.security:type=ConfigurationEntry,jaasId=properties");
          gbean.setAttribute("JAASId", "properties");
          gbean.setAttribute("RealmName", "properties-realm");
          gbean.setAttribute("ControlFlag", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED);
          gbean.setAttribute("Options", new HashMap());
          kernel.loadGBean(propertiesCE, gbean);
  
          kernel.startGBean(propertiesRealm);
          kernel.startGBean(propertiesCE);
  
          LoginContext context = new LoginContext("properties", new AbstractTest.UsernamePasswordCallback("alan", "starcraft"));
          context.login();
          clientSubject = context.getSubject();
  
          context = new LoginContext("properties", new AbstractTest.UsernamePasswordCallback("izumi", "violin"));
          context.login();
          serverSubject = context.getSubject();
  
          threadGroup = new ThreadGroup("Geronimo GSSAPI Server");
      }
  
      public void tearDown() throws Exception {
          kernel.stopGBean(propertiesCE);
          kernel.stopGBean(propertiesRealm);
          kernel.unloadGBean(propertiesRealm);
          kernel.unloadGBean(propertiesCE);
  
          super.tearDown();
  
          Configuration.setConfiguration(new ConfigFile());
      }
  
      static volatile long id = 0;
  
      protected PlainDownPacket getPlainPacket() {
          PlainDownPacket packet = new PlainDownPacket();
          ArrayList list = new ArrayList();
  
          final int COUNT = 1024;
          ByteBuffer buffer = ByteBuffer.allocate(COUNT);
          for (int i = 0; i < COUNT; i++) {
              buffer.put((byte) 0x0b);
          }
          buffer.flip();
  
          list.add(buffer);
          packet.setBuffers(list);
  
          return packet;
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/security/src/test/org/apache/geronimo/security/network/protocol/TestProtocol.java
  
  Index: TestProtocol.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.security.network.protocol;
  
  import javax.security.auth.Subject;
  
  import java.nio.ByteBuffer;
  import java.util.ArrayList;
  import java.util.Collection;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.geronimo.network.SelectorManager;
  import org.apache.geronimo.network.protocol.AbstractProtocol;
  import org.apache.geronimo.network.protocol.DownPacket;
  import org.apache.geronimo.network.protocol.MetadataSupport;
  import org.apache.geronimo.network.protocol.ProtocolException;
  import org.apache.geronimo.network.protocol.UpPacket;
  import org.apache.geronimo.network.protocol.control.BootstrapCook;
  import org.apache.geronimo.network.protocol.control.ControlContext;
  import org.apache.geronimo.network.protocol.control.commands.CreateInstanceMenuItem;
  import org.apache.geronimo.network.protocol.control.commands.SetAttributeMenuItem;
  import org.apache.geronimo.network.protocol.control.commands.SetReferenceMenuItem;
  import org.apache.geronimo.system.ClockPool;
  import org.apache.geronimo.system.ThreadPool;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/10 02:15:50 $
   */
  public class TestProtocol extends AbstractProtocol implements BootstrapCook {
  
      final static private Log log = LogFactory.getLog(TestProtocol.class);
  
      private String value;
      private ThreadPool threadPool;
      private ClockPool clockPool;
      private SelectorManager selectorManager;
  
      public TestProtocol() {
      }
  
      public String getValue() {
          return value;
      }
  
      public void setValue(String value) {
          this.value = value;
      }
  
      public ThreadPool getThreadPool() {
          return threadPool;
      }
  
      public void setThreadPool(ThreadPool threadPool) {
          this.threadPool = threadPool;
      }
  
      public ClockPool getClockPool() {
          return clockPool;
      }
  
      public void setClockPool(ClockPool clockPool) {
          this.clockPool = clockPool;
      }
  
      public SelectorManager getSelectorManager() {
          return selectorManager;
      }
  
      public void setSelectorManager(SelectorManager selectorManager) {
          this.selectorManager = selectorManager;
      }
  
      public void doStart() throws ProtocolException {
      }
  
      public void doStop() throws ProtocolException {
      }
  
      public void sendUp(UpPacket packet) throws ProtocolException {
          log.trace("sendUp");
  
          ByteBuffer buffer = packet.getBuffer();
          byte[] b = new byte[buffer.remaining()];
          buffer.get(b);
          for (int i = buffer.position(); i < buffer.limit(); i++) {
              if (b[i] != (byte) 0x0b) throw new ProtocolException("bb");
          }
          Subject subject = MetadataSupport.getSubject(packet);
          if (subject != null) log.trace("Subject passed: " + subject);
  
          if (getUp() != null) getUp().sendUp(packet);
      }
  
      public void sendDown(DownPacket packet) throws ProtocolException {
          log.trace("sendDown");
          getDown().sendDown(packet);
      }
  
      public Collection cook(ControlContext context) {
          ArrayList items = new ArrayList(2);
  
          CreateInstanceMenuItem create = new CreateInstanceMenuItem();
          create.setClassName(TestProtocol.class.getName());
          create.setInstanceId(context.assignId(this));
          items.add(create);
  
          SetAttributeMenuItem set = new SetAttributeMenuItem();
          set.setInstanceId(context.assignId(this));
          set.setAttributeName("Value");
          set.setAttributeValue(value);
          items.add(set);
  
          SetReferenceMenuItem ref = new SetReferenceMenuItem();
          ref.setInstanceId(context.assignId(this));
          ref.setReferenceName("ThreadPool");
          ref.setReferenceId(context.assignId(threadPool));
          items.add(ref);
  
          ref = new SetReferenceMenuItem();
          ref.setInstanceId(context.assignId(this));
          ref.setReferenceName("ClockPool");
          ref.setReferenceId(context.assignId(clockPool));
          items.add(ref);
  
          ref = new SetReferenceMenuItem();
          ref.setInstanceId(context.assignId(this));
          ref.setReferenceName("SelectorManager");
          ref.setReferenceId(context.assignId(selectorManager));
          items.add(ref);
  
  
          return items;
      }
  
  }