4

iOSプログラミングでの認証に問題があります。Windows 2003のIIS6に対して完全に機能するコードがありますが、IIS7を搭載したWindowsServer2008では機能しません。セキュリティオプションは両方のサーバーで同じです(匿名アクセスなしと「統合Windows認証」)。

「didReceiveAuthenticationChallenge」デリゲートのコードは次のとおりです。

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge 
{
//USE STORED CREDENTIALS
Credentials* cred = [[Credentials alloc] init];
NSString* userName = cred.userName;
NSString* pass = cred.pass;

NSString* authMethod = [[challenge protectionSpace] authenticationMethod];

//Kerberos (Negotiate) needs "user@realm" as username
//NTLM Needs domain\\username
if ([authMethod isEqualToString:NSURLAuthenticationMethodNTLM]) {
    userName = [NSString stringWithFormat:@"%@%@", @"es\\" , userName];
}
if ([authMethod isEqualToString:NSURLAuthenticationMethodNegotiate]) {
    userName = [NSString stringWithFormat:@"%@%@", userName, @"@subdomain.domain.com"];
}

NSLog(@"Auth method in use: %@" , authMethod);
NSLog(@"User: %@" , userName);
NSLog(@"Pass: %@" , pass);

if ([challenge previousFailureCount] <= 1) {
    NSLog(@"received authentication challenge");
    NSURLCredential *credential;
    credential = [NSURLCredential 
                     credentialWithUser:userName 
                     password:pass
                     persistence:NSURLCredentialPersistenceForSession];        

    [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];

}
else {
    NSLog(@"Authentication error");
    NSLog(@"Failed login with status code: %d", [(NSHTTPURLResponse*)[challenge failureResponse]statusCode]);
    [[challenge sender] cancelAuthenticationChallenge:challenge];   
}   

}

4

1 に答える 1

2

最後に、バグを発見しました... 問題は、Windows 2008 IIS7 サーバーの認証方法に関連しています。

「統合 Windows 認証」を使用すると、サーバーは NTLM または Kerberos を使用できます。私の 2008 サーバーは、これらのマシンで Kerberos が構成されていない場合でも、常に kerberos を使用します。

解決策は、IIS メタベースを編集して NTML 認証を強制することでした。

于 2012-08-17T13:02:01.837 に答える