Re: Vending a proxy problems
Re: Vending a proxy problems
- Subject: Re: Vending a proxy problems
- From: Philippe Mougin <email@hidden>
- Date: Thu, 25 Mar 2004 22:50:20 +0100
Jon,
The problem is quite general: a method that gives away to others a
reference to your protected object is called. You should instead ensure
that no references to your protected objects are returned (directly or
indirectly) to others except through your proxy.
At first glance, I would say that, in your situation, you should not
let forwardInvocation: route the replacementObjectForPortCoder: to your
protected object, because your protected object will then expose itself
to others through a distributed object proxy. Instead, you should
implement replacementObjectForPortCoder: in your proxy class in order
to return a distributed object proxy to your own proxy.
Something like this might work:
- (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
{
return [super replacementObjectForPortCoder:encoder];
}
Or you can try this:
- (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
{
return [NSDistantObject proxyWithLocal:self connection:[encoder
connection]];
}
Best,
Philippe Mougin
> I have a NSProxy subclass (semi inspired by NSProtocolChecker)
> that redirects all messages to a target object. In the proxy's
> forwardInvocation: method I perform some logic to test that the method
> call is safe to invoke (I'm using the authentication manager to
request
> rights). In my test tool this works fine, the proxy catches the
message's
> invocation, performs the test and if the test succeeds invokes the
> invocation.
>
> So now I'm trying to use Distributed Objects to vend the protected
> object over an NSConnection. Unfortunately there's a problem.
> The first message my proxy gets isn't one I sent it, rather it gets a
> "replacementObjectForPortCoder:" message. Once that message is
> received no other messages get routed through my proxy and further
> messages are sent directly to the target object!
>
> As far as I can tell I'm not doing anything dramatically from
> NSProtocolChecker so what gives? Anyone managed to do something
> like this before?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.