diff options
| author | slewis | 2005-05-04 05:28:16 +0000 |
|---|---|---|
| committer | slewis | 2005-05-04 05:28:16 +0000 |
| commit | 9e128d5304cac2bbe9aefa098d982f2ac8de5af3 (patch) | |
| tree | db9353c43fbc97ff724977be1db3efe333c1e154 | |
| parent | 437b45b9270d6742db349dda25410957346adbea (diff) | |
| download | org.eclipse.ecf-9e128d5304cac2bbe9aefa098d982f2ac8de5af3.tar.gz org.eclipse.ecf-9e128d5304cac2bbe9aefa098d982f2ac8de5af3.tar.xz org.eclipse.ecf-9e128d5304cac2bbe9aefa098d982f2ac8de5af3.zip | |
Changed IJoinAuthorizationContext interface to IJoinContext. Removed API ISharedObjectContainer.joinGroup(ID,Object) from interface and all implementations and replaced with ISharedObjectContainer.joinGroup(ID,IJoinContext). Added code in example collab Client to use callback mechanism to communicate password information in ObjectCallback
14 files changed, 372 insertions, 407 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/Client.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/Client.java index 6593fc7ac..8be44deda 100644 --- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/Client.java +++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/Client.java @@ -11,6 +11,7 @@ package org.eclipse.ecf.example.collab; +import java.io.IOException; import java.net.ConnectException; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -21,6 +22,11 @@ import java.util.Iterator; import java.util.List; import java.util.Vector; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.UnsupportedCallbackException; + import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; @@ -35,6 +41,8 @@ import org.eclipse.ecf.core.events.IContainerEvent; import org.eclipse.ecf.core.events.ISharedObjectContainerDepartedEvent; import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.IDFactory; +import org.eclipse.ecf.core.security.IJoinContext; +import org.eclipse.ecf.core.security.ObjectCallback; import org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject; import org.eclipse.ecf.example.collab.share.SharedObjectEventListener; import org.eclipse.ecf.example.collab.share.TreeItem; @@ -264,6 +272,26 @@ public class Client { if (name.equals(type)) return true; else return false; } + protected IJoinContext getJoinContext(final String username, final Object password) { + return new IJoinContext() { + public CallbackHandler getCallbackHandler() { + return new CallbackHandler() { + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + if (callbacks == null) return; + for (int i=0; i < callbacks.length; i++) { + if (callbacks[i] instanceof NameCallback) { + NameCallback ncb = (NameCallback) callbacks[i]; + ncb.setName(username); + } else if (callbacks[i] instanceof ObjectCallback) { + ObjectCallback ocb = (ObjectCallback) callbacks[i]; + ocb.setObject(password); + } + } + } + }; + } + }; + } public synchronized void createAndConnectClient(String type, final ID gID, String username, Object data, final IResource proj) throws Exception { @@ -303,7 +331,7 @@ public class Client { if (pc != null) setupPresenceContainer(client,pc,groupID,username); try { - client.joinGroup(groupID, data); + client.joinGroup(groupID, getJoinContext(username,data)); } catch (SharedObjectContainerJoinException e) { try { EclipseCollabSharedObject so = newClient.getObject(); diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java index 5e72f9d4d..0e652a537 100644 --- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java +++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java @@ -23,6 +23,7 @@ import org.eclipse.ecf.core.ISharedObjectContext; import org.eclipse.ecf.core.SharedObjectContainerJoinException; import org.eclipse.ecf.core.SharedObjectDescription; import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.security.IJoinContext; import org.eclipse.ecf.example.collab.ClientPlugin; import org.eclipse.ecf.example.collab.share.io.EclipseFileTransfer; import org.eclipse.ecf.example.collab.share.io.FileTransferParams; @@ -441,7 +442,7 @@ public class EclipseCollabSharedObject extends GenericSharedObject implements return super.isHost(); } - public void joinGroup(ID remote, Object data) + public void joinGroup(ID remote, IJoinContext data) throws SharedObjectContainerJoinException { ISharedObjectContext crs = getContext(); if (crs == null) { diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatHandler.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatHandler.java index 8c25d5c9d..729e124a7 100644 --- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatHandler.java +++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatHandler.java @@ -15,6 +15,7 @@ import java.util.Map; import org.eclipse.ecf.core.SharedObjectContainerJoinException; import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.security.IJoinContext; import org.eclipse.ecf.example.collab.share.User; @@ -36,7 +37,7 @@ public interface LineChatHandler { public Object getObject(ID target); - public void joinGroup(ID remote, Object data) + public void joinGroup(ID remote, IJoinContext joinContext) throws SharedObjectContainerJoinException; public void leaveGroup(); diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ClientSOContainer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ClientSOContainer.java index 7a3f5120d..526259cdd 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ClientSOContainer.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ClientSOContainer.java @@ -33,12 +33,13 @@ import org.eclipse.ecf.core.events.SharedObjectContainerJoinGroupEvent; import org.eclipse.ecf.core.events.SharedObjectContainerJoinedEvent; import org.eclipse.ecf.core.events.SharedObjectContainerLeaveGroupEvent; import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.security.IJoinAuthorizationContext; +import org.eclipse.ecf.core.security.IJoinContext; import org.eclipse.ecf.provider.generic.gmm.Member; public abstract class ClientSOContainer extends SOContainer { - - protected ISynchAsynchConnection connection; + + protected ISynchAsynchConnection connection; + protected ID remoteServerID; protected byte connectionState; @@ -54,12 +55,14 @@ public abstract class ClientSOContainer extends SOContainer { protected Lock connectLock; - protected Lock getConnectLock() { - return connectLock; - } - protected ISynchAsynchConnection getConnection() { - return connection; - } + protected Lock getConnectLock() { + return connectLock; + } + + protected ISynchAsynchConnection getConnection() { + return connection; + } + public ClientSOContainer(ISharedObjectContainerConfig config) { super(config); connection = null; @@ -89,14 +92,17 @@ public abstract class ClientSOContainer extends SOContainer { } public ID getGroupID() { - synchronized (getConnectLock()) { - return remoteServerID; - } + synchronized (getConnectLock()) { + return remoteServerID; + } } - protected Callback[] makeJoinCallbacks(Object connectData) { + + protected Callback[] makeAuthorizationCallbacks() { return null; } - public void joinGroup(ID remote, IJoinAuthorizationContext joinContext) throws SharedObjectContainerJoinException { + + public void joinGroup(ID remote, IJoinContext joinContext) + throws SharedObjectContainerJoinException { // first notify synchonously fireContainerEvent(new SharedObjectContainerJoinGroupEvent( this.getID(), remote, joinContext)); @@ -104,137 +110,48 @@ public abstract class ClientSOContainer extends SOContainer { if (isClosing) throw new IllegalStateException("container is closing"); debug("joingroup:" + remote + ":" + joinContext); - ISynchAsynchConnection aConnection = getClientConnection(remote, + ISynchAsynchConnection aConnection = makeConnection(remote, joinContext); - if (aConnection == null) { - ConnectException c = new ConnectException("join failed to" - + ":" + remote.getName()); - throw c; - } - Object response; + if (aConnection == null) + throw new ConnectException("join failed to" + ":" + + remote.getName() + + " because makeConnection returned null"); + Object response = null; synchronized (connectLock) { + // Throw if already connected if (isConnected()) { killConnection(aConnection); aConnection = null; - ConnectException c = new ConnectException( - "already connected to " + getGroupID()); - throw c; + throw new ConnectException("already connected to " + + getGroupID()); } + // Throw if connecting if (isConnecting()) { killConnection(aConnection); aConnection = null; - ConnectException c = new ConnectException( - "currently connecting"); - throw c; + throw new ConnectException("currently connecting"); } + // else we're entering connecting state connectionState = CONNECTING; connection = aConnection; } - synchronized (aConnection) { - try { - Object connectData = getConnectData(remote, joinContext); - // Get handler from joinContext and get appropriate data - if (joinContext != null) { - CallbackHandler handler = joinContext.getCallbackHandler(); - if (handler != null) { - handler.handle(makeJoinCallbacks(connectData)); - } - } - // Make connect call - response = aConnection.connect(remote, connectData, - getConnectTimeout()); - - } catch (IOException e) { - synchronized (connectLock) { - killConnection(aConnection); - if (connection != aConnection) { - aConnection = null; - throw e; - } - connectionState = UNCONNECTED; - connection = null; - remoteServerID = null; - } - throw e; - } - synchronized (connectLock) { - // If not in correct state, disconnect and return - if (connection != aConnection) { - killConnection(aConnection); - aConnection = null; - ConnectException c = new ConnectException( - "join failed because not in correct state"); - throw c; - } - ID serverID = null; - try { - serverID = acceptNewServer(remote, response); - } catch (Exception e) { - killConnection(aConnection); - aConnection = null; - connection = null; - remoteServerID = null; - connectionState = UNCONNECTED; - ConnectException c = new ConnectException( - "join refused locally via acceptNewServer"); - throw c; - } - aConnection.start(); - remoteServerID = serverID; - connectionState = CONNECTED; + // Now call join callback handler, if it exists + Callback[] callbacks = makeAuthorizationCallbacks(); + if (joinContext != null) { + CallbackHandler handler = joinContext.getCallbackHandler(); + if (handler != null) { + handler.handle(callbacks); } } - } catch (Exception e) { - dumpStack("Exception in joinGroup", e); - SharedObjectContainerJoinException except = new SharedObjectContainerJoinException( - "joinGroup exception in container " + getID() + " joining " - + remote + ": " + e.getClass().getName() + ": " - + e.getMessage()); - except.setStackTrace(e.getStackTrace()); - throw except; - } - } - public void joinGroup(ID remote, Object data) - throws SharedObjectContainerJoinException { - // first notify synchonously - fireContainerEvent(new SharedObjectContainerJoinGroupEvent( - this.getID(), remote, data)); - try { - if (isClosing) - throw new IllegalStateException("container is closing"); - debug("joingroup:" + remote + ":" + data); - ISynchAsynchConnection aConnection = getClientConnection(remote, - data); - if (aConnection == null) { - ConnectException c = new ConnectException("join failed to" - + ":" + remote.getName()); - throw c; - } - Object response; - synchronized (connectLock) { - if (isConnected()) { - killConnection(aConnection); - aConnection = null; - ConnectException c = new ConnectException( - "already connected to " + getGroupID()); - throw c; - } - if (isConnecting()) { - killConnection(aConnection); - aConnection = null; - ConnectException c = new ConnectException( - "currently connecting"); - throw c; - } - connectionState = CONNECTING; - connection = aConnection; - } synchronized (aConnection) { try { - Object connectData = getConnectData(remote, data); + Object connectData = makeConnectData(remote, callbacks, + null); + // Make connect call response = aConnection.connect(remote, connectData, getConnectTimeout()); + } catch (IOException e) { synchronized (connectLock) { killConnection(aConnection); @@ -253,22 +170,20 @@ public abstract class ClientSOContainer extends SOContainer { if (connection != aConnection) { killConnection(aConnection); aConnection = null; - ConnectException c = new ConnectException( + throw new ConnectException( "join failed because not in correct state"); - throw c; } ID serverID = null; try { - serverID = acceptNewServer(remote, response); + serverID = handleConnectResponse(remote, response); } catch (Exception e) { killConnection(aConnection); aConnection = null; connection = null; remoteServerID = null; connectionState = UNCONNECTED; - ConnectException c = new ConnectException( + throw new ConnectException( "join refused locally via acceptNewServer"); - throw c; } aConnection.start(); remoteServerID = serverID; @@ -357,7 +272,7 @@ public abstract class ClientSOContainer extends SOContainer { // NOP } - protected Serializable getConnectData(ID target, Object data) { + protected Object makeConnectData(ID target, Callback[] cbs, Object data) { return ContainerMessage.makeJoinGroupMessage(getID(), target, getNextSequenceNumber(), (Serializable) data); } @@ -368,7 +283,7 @@ public abstract class ClientSOContainer extends SOContainer { public void leaveGroup() { ID groupID = getGroupID(); - debug("leaveGroup:"+groupID); + debug("leaveGroup:" + groupID); fireContainerEvent(new SharedObjectContainerLeaveGroupEvent(this .getID(), groupID)); synchronized (connectLock) { @@ -383,7 +298,7 @@ public abstract class ClientSOContainer extends SOContainer { getNextSequenceNumber(), getLeaveData(groupID)))); } catch (Exception e) { - dumpStack("Exception in leaveGroup.sendSynch()",e); + dumpStack("Exception in leaveGroup.sendSynch()", e); } synchronized (getGroupMembershipLock()) { memberLeave(groupID, connection); @@ -399,9 +314,8 @@ public abstract class ClientSOContainer extends SOContainer { groupID)); } - protected abstract ISynchAsynchConnection getClientConnection( - ID remoteSpace, Object data) - throws ConnectionInstantiationException; + protected abstract ISynchAsynchConnection makeConnection(ID remoteSpace, + Object data) throws ConnectionInstantiationException; protected void queueContainerMessage(ContainerMessage message) throws IOException { @@ -492,19 +406,20 @@ public abstract class ClientSOContainer extends SOContainer { throw new ConnectException("not connected"); } - protected ID acceptNewServer(ID orginalTarget, Object serverData) + protected ID handleConnectResponse(ID orginalTarget, Object serverData) throws Exception { ContainerMessage aPacket = (ContainerMessage) serverData; ID fromID = aPacket.getFromContainerID(); if (fromID == null) throw new InvalidObjectException("server id is null"); - ID[] ids = ((ContainerMessage.ViewChangeMessage) aPacket.getData()).getChangeIDs(); + ID[] ids = ((ContainerMessage.ViewChangeMessage) aPacket.getData()) + .getChangeIDs(); if (ids == null) throw new java.io.InvalidObjectException("id array null"); for (int i = 0; i < ids.length; i++) { ID id = ids[i]; if (id != null && !id.equals(getID())) { - addNewRemoteMember(id, null); + addNewRemoteMember(id, null); // notify listeners fireContainerEvent(new SharedObjectContainerJoinedEvent(this .getID(), id)); diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainer.java index 43f4c877e..e24f2e6b6 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainer.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainer.java @@ -44,6 +44,7 @@ import org.eclipse.ecf.core.events.IContainerEvent; import org.eclipse.ecf.core.events.SharedObjectContainerDepartedEvent; import org.eclipse.ecf.core.events.SharedObjectContainerDisposeEvent; import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.security.IJoinContext; import org.eclipse.ecf.core.util.Event; import org.eclipse.ecf.core.util.IClassLoaderMapper; import org.eclipse.ecf.core.util.IQueueEnqueue; @@ -795,9 +796,9 @@ public abstract class SOContainer implements ISharedObjectContainer { * (non-Javadoc) * * @see org.eclipse.ecf.core.ISharedObjectContainer#joinGroup(org.eclipse.ecf.core.identity.ID, - * java.lang.Object) + * org.eclipse.ecf.core.security.IJoinContext) */ - public abstract void joinGroup(ID groupID, Object loginData) + public abstract void joinGroup(ID groupID, IJoinContext joinContext) throws SharedObjectContainerJoinException; protected void killConnection(IConnection conn) { diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContext.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContext.java index 994ed7855..322314791 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContext.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContext.java @@ -23,6 +23,7 @@ import org.eclipse.ecf.core.ISharedObjectManager; import org.eclipse.ecf.core.SharedObjectContainerJoinException; import org.eclipse.ecf.core.SharedObjectDescription; import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.security.IJoinContext; import org.eclipse.ecf.core.util.IQueueEnqueue; import org.eclipse.ecf.provider.Trace; @@ -108,18 +109,18 @@ public class SOContext implements ISharedObjectContext { * (non-Javadoc) * * @see org.eclipse.ecf.core.ISharedObjectContext#joinGroup(org.eclipse.ecf.core.identity.ID, - * java.lang.Object) + * org.eclipse.ecf.core.security.IJoinContext) */ - public synchronized void joinGroup(ID groupID, Object loginData) - throws SharedObjectContainerJoinException { + public synchronized void joinGroup(ID groupID, IJoinContext joinContext) + throws SharedObjectContainerJoinException { if (isInactive()) { trace("joinGroup("+groupID+") CONTEXT INACTIVE"); return; } else { trace("joinGroup("+groupID+")"); - container.joinGroup(groupID, loginData); + container.joinGroup(groupID, joinContext); } - } + } /* * (non-Javadoc) diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ServerSOContainer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ServerSOContainer.java index b9dd75e1c..8331bb3c2 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ServerSOContainer.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ServerSOContainer.java @@ -26,7 +26,7 @@ import org.eclipse.ecf.core.events.SharedObjectContainerDepartedEvent; import org.eclipse.ecf.core.events.SharedObjectContainerEjectedEvent; import org.eclipse.ecf.core.events.SharedObjectContainerJoinedEvent; import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.security.IJoinAuthorizationContext; +import org.eclipse.ecf.core.security.IJoinContext; import org.eclipse.ecf.provider.generic.gmm.Member; public class ServerSOContainer extends SOContainer implements ISharedObjectContainerGroupManager { @@ -261,7 +261,7 @@ public class ServerSOContainer extends SOContainer implements ISharedObjectConta super.dispose(timeout); } - public void joinGroup(ID groupID, IJoinAuthorizationContext joinContext) throws SharedObjectContainerJoinException { + public void joinGroup(ID groupID, IJoinContext joinContext) throws SharedObjectContainerJoinException { SharedObjectContainerJoinException e = new SharedObjectContainerJoinException( "ServerApplication cannot join group " + groupID.getName()); throw e; diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPClientSOContainer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPClientSOContainer.java index 95cb3361e..3e8612ec5 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPClientSOContainer.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPClientSOContainer.java @@ -32,7 +32,7 @@ public class TCPClientSOContainer extends ClientSOContainer { keepAlive = ka; } - protected ISynchAsynchConnection getClientConnection(ID remoteSpace, + protected ISynchAsynchConnection makeConnection(ID remoteSpace, Object data) throws ConnectionInstantiationException { debug("getClientConnection:" + remoteSpace + ":" + data); Object[] args = { new Integer(keepAlive) }; diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContainer.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContainer.java index 229e09be9..616cccc9a 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContainer.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContainer.java @@ -10,135 +10,122 @@ package org.eclipse.ecf.core; import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.security.IJoinAuthorizationContext; +import org.eclipse.ecf.core.security.IJoinContext; /** * Core interface that must be implemented by all ECF container instances. - * Instances are typically - * created via {@link SharedObjectContainerFactory} + * Instances are typically created via {@link SharedObjectContainerFactory} */ public interface ISharedObjectContainer { - /** - * Return the ISharedObjectContainerConfig for this ISharedObjectContainer. - * The returned value must always be non-null. - * - * @return ISharedObjectContainerConfig for the given ISharedObjectContainer - * instance - */ - public ISharedObjectContainerConfig getConfig(); - /** - * Add listener to ISharedObjectContainer. Listener will be notified when - * container events occur - * - * @param l - * the ISharedObjectContainerListener to add - * @param filter - * the filter to define types of container events to receive - */ - public void addListener(ISharedObjectContainerListener l, String filter); - /** - * Remove listener from ISharedObjectContainer. - * - * @param l - * the ISharedObjectContainerListener to remove - */ - public void removeListener(ISharedObjectContainerListener l); - /** - * Dispose this ISharedObjectContainer instance. The container instance - * will be made inactive after the completion of this method and will be - * unavailable for subsequent usage - * - * @param waittime - */ - public void dispose(long waittime); - /** - * Join a container group. The group to join is identified by the first - * parameter (groupID) using any required authentication provided via the - * second parameter (loginData). This method provides an implementation - * independent way for container implementations to connect, authenticate, - * and communicate with a remote service or group of services. Providers are - * responsible for implementing this operation in a way appropriate to the - * given remote service and expected protocol. - * - * @param groupID - * the ID of the remote service to join - * @param loginData - * any required login/authentication data to allow this container - * to authenticate - * @exception SharedObjectContainerJoinException - * thrown if communication cannot be established with remote - * service - */ - public void joinGroup(ID groupID, Object loginData) - throws SharedObjectContainerJoinException; - - /** - * Join a container group. The group to join is identified by the first - * parameter (groupID) using any required authentication provided via the - * second parameter (joinContext). This method provides an implementation - * independent way for container implementations to connect, authenticate, - * and communicate with a remote service or group of services. Providers are - * responsible for implementing this operation in a way appropriate to the - * given remote service and expected protocol. - * - * @param groupID - * the ID of the remote service to join - * @param joinContext - * any required authentication context to allow this container - * to authenticate on join with remote containers - * @exception SharedObjectContainerJoinException - * thrown if communication cannot be established with remote - * service - */ - public void joinGroup(ID groupID, IJoinAuthorizationContext joinContext) throws SharedObjectContainerJoinException; - - /** - * Leave a container group. This operation will disconnect the local - * container instance from any previously joined group. - */ - public void leaveGroup(); - /** - * Get the group id that this container has joined. Return null if no group has - * previously been joined. - * - * @return ID of the group previously joined - */ - public ID getGroupID(); - /** - * Get the current membership of the joined group. This method will - * accurately report the current group membership of the connected group. - * - * @return ID[] the IDs of the current group membership - */ - public ID[] getGroupMemberIDs(); - /** - * @return true if this ISharedObjectContainer instance is in the - * 'manager' role for the group, false otherwise - */ - public boolean isGroupManager(); - /** - * @return true if this ISharedObjectContainer instance is in a server - * role for the group, false otherwise - */ - public boolean isGroupServer(); - - /** - * Get SharedObjectManager for this container - * - * @return ISharedObjectManager for this container instance - */ - public ISharedObjectManager getSharedObjectManager(); - - /** - * Returns an object which is an instance of the given class associated with - * this object. - * - * @param adapter - * the adapter class to lookup - * @return Object a object castable to the given class, or null if this - * object does not have an adapter for the given class - */ - public Object getAdapter(Class adapter); + /** + * Return the ISharedObjectContainerConfig for this ISharedObjectContainer. + * The returned value must always be non-null. + * + * @return ISharedObjectContainerConfig for the given ISharedObjectContainer + * instance + */ + public ISharedObjectContainerConfig getConfig(); + + /** + * Add listener to ISharedObjectContainer. Listener will be notified when + * container events occur + * + * @param l + * the ISharedObjectContainerListener to add + * @param filter + * the filter to define types of container events to receive + */ + public void addListener(ISharedObjectContainerListener l, String filter); + + /** + * Remove listener from ISharedObjectContainer. + * + * @param l + * the ISharedObjectContainerListener to remove + */ + public void removeListener(ISharedObjectContainerListener l); + + /** + * Dispose this ISharedObjectContainer instance. The container instance will + * be made inactive after the completion of this method and will be + * unavailable for subsequent usage + * + * @param waittime + */ + public void dispose(long waittime); + + /** + * Join a container group. The group to join is identified by the first + * parameter (groupID) using any required authentication provided via the + * second parameter (joinContext). This method provides an implementation + * independent way for container implementations to connect, authenticate, + * and communicate with a remote service or group of services. Providers are + * responsible for implementing this operation in a way appropriate to the + * given remote service and expected protocol. + * + * @param groupID + * the ID of the remote service to join + * @param joinContext + * any required context to allow this container to authenticate + * on join with remote containers + * @exception SharedObjectContainerJoinException + * thrown if communication cannot be established with remote + * service + */ + public void joinGroup(ID groupID, IJoinContext joinContext) + throws SharedObjectContainerJoinException; + + /** + * Leave a container group. This operation will disconnect the local + * container instance from any previously joined group. + */ + public void leaveGroup(); + + /** + * Get the group id that this container has joined. Return null if no group + * has previously been joined. + * + * @return ID of the group previously joined + */ + public ID getGroupID(); + + /** + * Get the current membership of the joined group. This method will + * accurately report the current group membership of the connected group. + * + * @return ID[] the IDs of the current group membership + */ + public ID[] getGroupMemberIDs(); + + /** + * @return true if this ISharedObjectContainer instance is in the 'manager' + * role for the group, false otherwise + */ + public boolean isGroupManager(); + + /** + * @return true if this ISharedObjectContainer instance is in a server role + * for the group, false otherwise + */ + public boolean isGroupServer(); + + /** + * Get SharedObjectManager for this container + * + * @return ISharedObjectManager for this container instance + */ + public ISharedObjectManager getSharedObjectManager(); + + /** + * Returns an object which is an instance of the given class associated with + * this object. + * + * @param adapter + * the adapter class to lookup + * @return Object a object castable to the given class, or null if this + * object does not have an adapter for the given class + */ + public Object getAdapter(Class adapter); }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContext.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContext.java index a5bcf9020..4c3676fdb 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContext.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContext.java @@ -12,86 +12,94 @@ package org.eclipse.ecf.core; import java.io.IOException; import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.security.IJoinContext; import org.eclipse.ecf.core.util.IQueueEnqueue; /** - * Context reference provided to all ISharedObjects upon initialization. Implementers of - * this interface provide a runtime context for ISharedObject instances. Upon initialization - * within a container (see {@link ISharedObject#init(ISharedObjectConfig)}, ISharedObject instances - * can access an instance of this context by calling {@link ISharedObjectConfig#getContext()}. They - * then can have access to the functions provided by this context object for use in implementing - * their behavior. - * + * Context reference provided to all ISharedObjects upon initialization. + * Implementers of this interface provide a runtime context for ISharedObject + * instances. Upon initialization within a container (see + * {@link ISharedObject#init(ISharedObjectConfig)}, ISharedObject instances can + * access an instance of this context by calling + * {@link ISharedObjectConfig#getContext()}. They then can have access to the + * functions provided by this context object for use in implementing their + * behavior. + * * @see ISharedObject#init * @see ISharedObjectConfig#getContext() */ public interface ISharedObjectContext { - /** - * Get the local container instance's ID - * - * @return the ID of the enclosing container - */ - public ID getLocalContainerID(); - /** - * Get the ISharedObjectManager for this context - * @return ISharedObjectManager the shared object manager instance for this - * container. Null if none available. - */ - public ISharedObjectManager getSharedObjectManager(); - /** - * Get the IQueueEnqueue instance associated with this ISharedObject. If the - * given container provides a queue for this ISharedObject, this method will - * return a IQueueEnqueue reference to the appropriate queue. - * - * @return IQueueEnqueue instance if an active queue is associated with this - * ISharedObject. If no active queue is associated with the - * ISharedObject, returns null. - * - */ - public IQueueEnqueue getQueue(); - - /** - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#joinGroup(org.eclipse.ecf.core.identity.ID, - * java.lang.Object) - */ - public void joinGroup(ID groupID, Object loginData) - throws SharedObjectContainerJoinException; - /** - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#leaveGroup() - */ - public void leaveGroup(); - - /** - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupID() - */ - public ID getGroupID(); - /** - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupManager() - */ - public boolean isGroupManager(); - /** - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupServer() - */ - public boolean isGroupServer(); - /** - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupMemberIDs() - */ - public ID[] getGroupMemberIDs(); - - /** + /** + * Get the local container instance's ID + * + * @return the ID of the enclosing container + */ + public ID getLocalContainerID(); + + /** + * Get the ISharedObjectManager for this context + * + * @return ISharedObjectManager the shared object manager instance for this + * container. Null if none available. + */ + public ISharedObjectManager getSharedObjectManager(); + + /** + * Get the IQueueEnqueue instance associated with this ISharedObject. If the + * given container provides a queue for this ISharedObject, this method will + * return a IQueueEnqueue reference to the appropriate queue. + * + * @return IQueueEnqueue instance if an active queue is associated with this + * ISharedObject. If no active queue is associated with the + * ISharedObject, returns null. + */ + public IQueueEnqueue getQueue(); + + /** + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#joinGroup() + */ + public void joinGroup(ID groupID, IJoinContext joinContext) + throws SharedObjectContainerJoinException; + + /** + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#leaveGroup() + */ + public void leaveGroup(); + + /** + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupID() + */ + public ID getGroupID(); + + /** + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupManager() + */ + public boolean isGroupManager(); + + /** + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupServer() + */ + public boolean isGroupServer(); + + /** + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupMemberIDs() + */ + public ID[] getGroupMemberIDs(); + + /** * Send message to create a remote instance of an ISharedObject with the * same ID as this instance. This method allows ISharedObject instances * (with a reference to a valid ISharedObjectContext) to send messages to @@ -104,49 +112,52 @@ public interface ISharedObjectContext { * of the create request. If this parameter is null, the request * is assumed to be made of <b>all </b> remote containers * currently in the given group (excepting the local container). - * * @param sd * the SharedObjectDescription describing the class, constructor * and other properties to be associated with the new instance - * * @throws IOException * thrown if message cannot be sent by container */ - public void sendCreate(ID toContainerID, SharedObjectDescription sd) - throws IOException; - - /** - * Send create response back to an ISharedObject with the - * same ID as this instance. This method allows ISharedObject instances - * (with a reference to a valid ISharedObjectContext) to send messages to - * remote containers asking them to deliver the create response status back to the - * ISharedObject. + public void sendCreate(ID toContainerID, SharedObjectDescription sd) + throws IOException; + + /** + * Send create response back to an ISharedObject with the same ID as this + * instance. This method allows ISharedObject instances (with a reference to + * a valid ISharedObjectContext) to send messages to remote containers + * asking them to deliver the create response status back to the + * ISharedObject. * - * @param toContainerID the ID of the container that is to receive this response - * @param throwable a throwable associated with the creation. Null means that - * no exception occured - * @param identifier the identifier used in the original create message (in the shared - * object description) - * @exception IOException thrown if the create response cannot be sent + * @param toContainerID + * the ID of the container that is to receive this response + * @param throwable + * a throwable associated with the creation. Null means that no + * exception occured + * @param identifier + * the identifier used in the original create message (in the + * shared object description) + * @exception IOException + * thrown if the create response cannot be sent */ - public void sendCreateResponse(ID toContainerID, Throwable throwable, long identifier) - throws IOException; - /** - * Send message to dispose of a remote instance of the ISharedObject with - * same ID as this instance. This method allows ISharedObject instances to control the - * destruction of remote replicas. - * - * @param toContainerID - * the ID of the remote ISharedObjectContainer that is the target - * of the dispose request. If this parameter is null, the request - * is assumed to be made of <b>all </b> remote containers - * currently in the given group (excepting the local container). - * - * @throws IOException - * thrown if message cannot be sent by container - */ - public void sendDispose(ID toContainerID) throws IOException; - /** + public void sendCreateResponse(ID toContainerID, Throwable throwable, + long identifier) throws IOException; + + /** + * Send message to dispose of a remote instance of the ISharedObject with + * same ID as this instance. This method allows ISharedObject instances to + * control the destruction of remote replicas. + * + * @param toContainerID + * the ID of the remote ISharedObjectContainer that is the target + * of the dispose request. If this parameter is null, the request + * is assumed to be made of <b>all </b> remote containers + * currently in the given group (excepting the local container). + * @throws IOException + * thrown if message cannot be sent by container + */ + public void sendDispose(ID toContainerID) throws IOException; + + /** * Send arbitrary message to remote instance of the ISharedObject with same * ID as this instance. This method allows ISharedObject instances to send * arbitrary data to one or more remote replicas of this ISharedObject. @@ -165,7 +176,7 @@ public interface ISharedObjectContext { */ public void sendMessage(ID toContainerID, Object data) throws IOException; - /** + /** * Returns an object which is an instance of the given class associated with * this object. * @@ -174,16 +185,16 @@ public interface ISharedObjectContext { * @return Object a object castable to the given class, or null if this * object does not have an adapter for the given class */ - public Object getAdapter(Class clazz); - - /** - * Get a reference to a proxy instance that allows the registration and - * access to local OSGI-platform-provided services. If this method returns - * null, then such services are not available. - * - * @return null if OSGI platform services cannot be accessed, a valid - * instance of the given interface if the context allows access to - * such services - */ - public IOSGIService getServiceAccess(); + public Object getAdapter(Class clazz); + + /** + * Get a reference to a proxy instance that allows the registration and + * access to local OSGI-platform-provided services. If this method returns + * null, then such services are not available. + * + * @return null if OSGI platform services cannot be accessed, a valid + * instance of the given interface if the context allows access to + * such services + */ + public IOSGIService getServiceAccess(); }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/IJoinAuthorizationContext.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/IJoinContext.java index 96459513b..94a39489b 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/IJoinAuthorizationContext.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/IJoinContext.java @@ -11,7 +11,7 @@ package org.eclipse.ecf.core.security; import javax.security.auth.callback.CallbackHandler; -public interface IJoinAuthorizationContext { +public interface IJoinContext { /** * Get the callbackhandler instance used by the provider to * callback into application code. The provider will typically use the diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/ObjectCallback.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/ObjectCallback.java index 87e07c3ee..18a1375db 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/ObjectCallback.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/security/ObjectCallback.java @@ -5,14 +5,17 @@ import javax.security.auth.callback.Callback; public class ObjectCallback implements Callback { Object data; + public ObjectCallback() { + data = null; + } public ObjectCallback(Object val) { this.data = val; } - public void setData(Object val) { + public void setObject(Object val) { this.data = val; } - public Object getData() { + public Object getObject() { return this.data; } } diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPClientSOContainer.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPClientSOContainer.java index 74b08d705..f4098e7e4 100644 --- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPClientSOContainer.java +++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPClientSOContainer.java @@ -9,10 +9,11 @@ package org.eclipse.ecf.provider.xmpp.container; import java.io.IOException; -import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import javax.security.auth.callback.Callback; + import org.eclipse.ecf.core.ISharedObjectContainer; import org.eclipse.ecf.core.SharedObjectAddException; import org.eclipse.ecf.core.SharedObjectContainerInstantiationException; @@ -25,6 +26,8 @@ import org.eclipse.ecf.core.events.SharedObjectContainerJoinedEvent; import org.eclipse.ecf.core.events.SharedObjectContainerLeaveGroupEvent; import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.IDFactory; +import org.eclipse.ecf.core.security.IJoinContext; +import org.eclipse.ecf.core.security.ObjectCallback; import org.eclipse.ecf.core.util.ECFException; import org.eclipse.ecf.core.util.IQueueEnqueue; import org.eclipse.ecf.presence.IAccountManager; @@ -82,7 +85,7 @@ public class XMPPClientSOContainer extends ClientSOContainer { initializeSharedObject(); } - protected ID acceptNewServer(ID originalTarget, Object serverData) + protected ID handleConnectResponse(ID originalTarget, Object serverData) throws Exception { if (originalTarget != null && !originalTarget.equals(getID())) { addNewRemoteMember(originalTarget, null); @@ -125,7 +128,7 @@ public class XMPPClientSOContainer extends ClientSOContainer { messageSender = null; } - protected ISynchAsynchConnection getClientConnection(ID remoteSpace, + protected ISynchAsynchConnection makeConnection(ID remoteSpace, Object data) throws ConnectionInstantiationException { Object[] args = { new Integer(keepAlive) }; ISynchAsynchConnection conn = null; @@ -138,10 +141,24 @@ public class XMPPClientSOContainer extends ClientSOContainer { return conn; } - protected Serializable getConnectData(ID target, Object data) { - return (Serializable) data; + protected Object makeConnectData(ID target, Callback [] cbs, Object data) { + // first one is password callback + if (cbs.length > 0) { + if (cbs[0] instanceof ObjectCallback) { + ObjectCallback cb = (ObjectCallback) cbs[0]; + return cb.getObject(); + } + } + return data; + } + + protected Callback[] makeAuthorizationCallbacks() { + Callback [] cbs = new Callback[1]; + cbs[0] = new ObjectCallback(); + return cbs; } + protected int getConnectTimeout() { return keepAlive; } @@ -212,11 +229,11 @@ public class XMPPClientSOContainer extends ClientSOContainer { sharedObject = new XMPPPresenceSharedObject(); } - public void joinGroup(ID remote, Object data) + public void joinGroup(ID remote, IJoinContext joinContext) throws SharedObjectContainerJoinException { try { addSharedObjectToContainer(remote); - super.joinGroup(remote, data); + super.joinGroup(remote, joinContext); } catch (SharedObjectContainerJoinException e) { cleanUpConnectFail(); throw e; diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSOContainer.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSOContainer.java index 0c9a24fe7..cb553aa85 100644 --- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSOContainer.java +++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSOContainer.java @@ -232,7 +232,7 @@ public class XMPPGroupChatSOContainer extends ClientSOContainer { * @see org.eclipse.ecf.provider.generic.ClientSOContainer#getClientConnection(org.eclipse.ecf.core.identity.ID, * java.lang.Object) */ - protected ISynchAsynchConnection getClientConnection(ID remoteSpace, + protected ISynchAsynchConnection makeConnection(ID remoteSpace, Object data) throws ConnectionInstantiationException { return null; } |
