Re: Ignoring credentials in shared NSURLCredentialStorage
Re: Ignoring credentials in shared NSURLCredentialStorage
- Subject: Re: Ignoring credentials in shared NSURLCredentialStorage
- From: Dave Dribin <email@hidden>
- Date: Mon, 14 May 2007 09:54:37 -0500
On May 11, 2007, at 11:36 AM, Becky Willrich wrote:
- You can try using poseAs: to insert your own
NSURLCredentialStorage class in place of the default one; it could
always fail to find credentials, or maybe call through to the real
NSURLCredentialStorage in all cases except the ones you want to
intercept. If you do this, you are tinkering with the runtime, so
be careful - you'll want to make sure and implement forward:: to
send any unrecognized messages through to a "real"
NSURLCredentialStorage. I'm not a runtime expert, so I don't know
what all the gotchas are, just that there are more than a few.
I figured out how to do it with a category (see below). You just
need to call initializeDefaultCredentials() early on, in main() or an
+initialize method. The only downside is a category can only
override a method and cannot call the original NSURLCredentialStorage
methods. You'd have to do class posing or method swizzling to do
that. Also, I didn't have to override credentialsForProtectionSpace:
and setCredential:forProtectionSpace:, as I didn't see them being
called in my app.
-Dave
-----
static NSMutableDictionary * sDefaultCredentials;
void initializeDefaultCredentials()
{
sDefaultCredentials = [[NSMutableDictionary alloc] init];;
}
@implementation NSURLCredentialStorage (SharedOverride)
- (NSURLCredential *) defaultCredentialForProtectionSpace:
(NSURLProtectionSpace *) protectionSpace;
{
return [sDefaultCredentials objectForKey: protectionSpace];
}
- (void) setDefaultCredential: (NSURLCredential *) credential
forProtectionSpace: (NSURLProtectionSpace *)
protectionSpace;
{
[sDefaultCredentials setObject: credential forKey:
protectionSpace];
}
@end
-----
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden