Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ignoring credentials in shared NSURLCredentialStorage



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:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden
References: 
 >Ignoring credentials in shared NSURLCredentialStorage (From: Dave Dribin <email@hidden>)
 >Re: Ignoring credentials in shared NSURLCredentialStorage (From: Jerry Krinock <email@hidden>)
 >Re: Ignoring credentials in shared NSURLCredentialStorage (From: Dave Dribin <email@hidden>)
 >Re: Ignoring credentials in shared NSURLCredentialStorage (From: Jerry Krinock <email@hidden>)
 >Re: Ignoring credentials in shared NSURLCredentialStorage (From: Dave Dribin <email@hidden>)
 >Re: Ignoring credentials in shared NSURLCredentialStorage (From: Jerry Krinock <email@hidden>)
 >Re: Ignoring credentials in shared NSURLCredentialStorage (From: Dave Dribin <email@hidden>)
 >Re: Ignoring credentials in shared NSURLCredentialStorage (From: Jerry Krinock <email@hidden>)
 >Re: Ignoring credentials in shared NSURLCredentialStorage (From: Dave Dribin <email@hidden>)
 >Re: Ignoring credentials in shared NSURLCredentialStorage (From: Becky Willrich <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.