Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 49430 invoked from network); 6 Sep 2005 17:52:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Sep 2005 17:52:29 -0000 Received: (qmail 36176 invoked by uid 500); 6 Sep 2005 17:52:29 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 36143 invoked by uid 500); 6 Sep 2005 17:52:28 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 36127 invoked by uid 99); 6 Sep 2005 17:52:28 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Sep 2005 10:52:28 -0700 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 06 Sep 2005 10:52:42 -0700 Received: (qmail 49420 invoked by uid 65534); 6 Sep 2005 17:52:27 -0000 Message-ID: <20050906175227.49419.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r279045 - /geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingChannel.java Date: Tue, 06 Sep 2005 17:52:27 -0000 To: scm@geronimo.apache.org From: dblevins@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: dblevins Date: Tue Sep 6 10:52:24 2005 New Revision: 279045 URL: http://svn.apache.org/viewcvs?rev=279045&view=rev Log: Updated for activeio 2 Modified: geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingChannel.java Modified: geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingChannel.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingChannel.java?rev=279045&r1=279044&r2=279045&view=diff ============================================================================== --- geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingChannel.java (original) +++ geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/network/protocol/SubjectCarryingChannel.java Tue Sep 6 10:52:24 2005 @@ -16,78 +16,77 @@ */ package org.apache.geronimo.security.network.protocol; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.security.AccessController; -import java.util.Collection; -import javax.security.auth.Subject; - -import org.activeio.AsynchChannel; -import org.activeio.FilterAsynchChannel; +import org.activeio.AsyncChannel; +import org.activeio.FilterAsyncChannel; import org.activeio.Packet; -import org.activeio.adapter.PacketInputStream; import org.activeio.adapter.PacketOutputStream; +import org.activeio.adapter.PacketToInputStream; import org.activeio.packet.AppendedPacket; import org.activeio.packet.ByteArrayPacket; import org.activeio.packet.FilterPacket; - import org.apache.geronimo.security.ContextManager; import org.apache.geronimo.security.IdentificationPrincipal; import org.apache.geronimo.security.SubjectId; +import javax.security.auth.Subject; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.security.AccessController; +import java.util.Collection; + /** - * SubjectCarryingChannel is a FilterAsynchChannel that allows you to send + * SubjectCarryingChannel is a FilterAsynchChannel that allows you to send * the subject associated with the current write operation down to the remote * end of the channel. - * + * * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $ */ -public class SubjectCarryingChannel extends FilterAsynchChannel { +public class SubjectCarryingChannel extends FilterAsyncChannel { - static final byte PASSTHROUGH = (byte)0x00; - static final byte SET_SUBJECT = (byte)0x01; - static final byte CLEAR_SUBJECT = (byte)0x2; + static final byte PASSTHROUGH = (byte) 0x00; + static final byte SET_SUBJECT = (byte) 0x01; + static final byte CLEAR_SUBJECT = (byte) 0x2; - final private ByteArrayPacket header = new ByteArrayPacket(new byte[1+8+4]); + final private ByteArrayPacket header = new ByteArrayPacket(new byte[1 + 8 + 4]); private Subject remoteSubject; private Subject localSubject; - + private final boolean enableLocalSubjectPublishing; private final boolean enableRemoteSubjectConsumption; - public SubjectCarryingChannel(AsynchChannel next) { + public SubjectCarryingChannel(AsyncChannel next) { this(next, true, true); } - - public SubjectCarryingChannel(AsynchChannel next, boolean enableLocalSubjectPublishing, boolean enableRemoteSubjectConsumption) { + + public SubjectCarryingChannel(AsyncChannel next, boolean enableLocalSubjectPublishing, boolean enableRemoteSubjectConsumption) { super(next); this.enableLocalSubjectPublishing = enableLocalSubjectPublishing; this.enableRemoteSubjectConsumption = enableRemoteSubjectConsumption; } - + public void write(Packet packet) throws IOException { - + // Don't add anything to the packet stream if subject writing is not enabled. - if( !enableLocalSubjectPublishing ) { + if (!enableLocalSubjectPublishing) { super.write(packet); return; } - + Subject subject = Subject.getSubject(AccessController.getContext()); if (remoteSubject != subject) { remoteSubject = subject; Collection principals = remoteSubject.getPrincipals(IdentificationPrincipal.class); - + if (principals.isEmpty()) { super.write(createClearSubjectPackt()); - } else { + } else { IdentificationPrincipal principal = (IdentificationPrincipal) principals.iterator().next(); - SubjectId subjectId = principal.getId(); + SubjectId subjectId = principal.getId(); super.write(createSubjectPacket(subjectId.getSubjectId(), subjectId.getHash())); } - + } super.write(createPassthroughPacket(packet)); } @@ -99,7 +98,7 @@ } public Object narrow(Class target) { - if( target == SubjectContext.class ) { + if (target == SubjectContext.class) { return new SubjectContext() { public Subject getSubject() { return remoteSubject; @@ -116,24 +115,24 @@ } public void onPacket(Packet packet) { - + // Don't take anything to the packet stream if subject reading is not enabled. - if( !enableRemoteSubjectConsumption ) { + if (!enableRemoteSubjectConsumption) { super.onPacket(packet); return; } - + try { - switch( packet.read() ) { + switch (packet.read()) { case CLEAR_SUBJECT: localSubject = null; return; - case SET_SUBJECT: + case SET_SUBJECT: SubjectId subjectId = extractSubjectId(packet); localSubject = ContextManager.getRegisteredSubject(subjectId); return; case PASSTHROUGH: - super.onPacket( new SubjectPacketFilter(packet) ); + super.onPacket(new SubjectPacketFilter(packet)); } } catch (IOException e) { super.onPacketError(e); @@ -145,9 +144,9 @@ /** */ private SubjectId extractSubjectId(Packet packet) throws IOException { - DataInputStream is = new DataInputStream(new PacketInputStream(packet)); + DataInputStream is = new DataInputStream(new PacketToInputStream(packet)); Long id = new Long(is.readLong()); - byte hash[]= new byte[ is.readInt() ]; + byte hash[] = new byte[is.readInt()]; return new SubjectId(id, hash); } @@ -173,7 +172,7 @@ header.clear(); header.write(PASSTHROUGH); header.flip(); - return AppendedPacket.join(header,packet); + return AppendedPacket.join(header, packet); } public Subject getLocalSubject() { @@ -183,5 +182,5 @@ public Subject getRemoteSubject() { return remoteSubject; } - + }