Make enter identity dialog's smarter about matching a string with a set of favorite...
authorJustin Anderson <jander@mit.edu>
Thu, 2 Oct 2008 13:20:04 +0000 (13:20 +0000)
committerJustin Anderson <jander@mit.edu>
Thu, 2 Oct 2008 13:20:04 +0000 (13:20 +0000)
ticket:6055

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20808 dc483132-0cff-0310-8789-dd5450dbe970

src/kim/agent/mac/AuthenticationController.h
src/kim/agent/mac/AuthenticationController.m
src/kim/agent/mac/KIMUtilities.h
src/kim/agent/mac/KIMUtilities.m
src/kim/agent/mac/resources/English.lproj/Authentication.xib

index 4035668e2e61c1c7240bb59d910c390ae4251d25..c62611db7088f9ec8413267cf9eae7423db361c6 100644 (file)
@@ -97,4 +97,7 @@
           returnCode: (int) returnCode 
          contextInfo: (void *) contextInfo;
 
+- (IBAction) changePasswordGearAction: (id) sender;
+- (void) changePasswordThread: (NSString *) identityString;
+
 @end
index eaf4e6913e3e6351bdaa412a016e55c0b7ee08cd..34e7662d22af7792e715a10fa5a3816c4fcc08ee 100644 (file)
 - (IBAction) showTicketOptions: (id) sender
 {
     NSDictionary *options = nil;
+    NSString *expandedString = nil;
     // if this is a favorite, try to load its default options
     [identityField validateEditing];
 
-    options = [favoriteOptions valueForKey:[identityField stringValue]];
+    expandedString = [KIMUtilities expandedIdentity:[identityField stringValue]];
+
+    // edit the favorite options for this favorite identity
+    if (expandedString) {
+        options = [favoriteOptions objectForKey:expandedString];
+    }
     
+    // else fallback to options passed from client
+    // use a copy of the current options
     if (!options) {
         options = [[[glueController valueForKeyPath:options_keypath] mutableCopy] autorelease];
     }
     
-    // else fallback to options passed from client
-    // use a copy of the current options
     [ticketOptionsController setContent:options];
     
     [ticketOptionsController setValue:[NSNumber numberWithInteger:[KIMUtilities minValidLifetime]]
         // discard new options
         [ticketOptionsController setContent:nil];
     } else {
-        // replace existing options with new
-        // add to favorites if not already in list
-        
-        // replace options of existing if already in list
         kim_error err = KIM_NO_ERROR;
         kim_preferences prefs = NULL;
         kim_identity identity = NULL;
         kim_options options = NULL;
+        NSString *expandedString = [KIMUtilities expandedIdentity:[identityField stringValue]];;
 
-        [glueController setValue:[ticketOptionsController content] 
-                      forKeyPath:options_keypath];
-        
-        err = kim_preferences_create(&prefs);
-        
+        // replace options if favorite exists
+        // add to favorites if not already in list
+        if (!expandedString) {
+            err = KIM_BAD_PRINCIPAL_STRING_ERR;
+        }
+        if (!err) {
+            [favoriteOptions setObject:[ticketOptionsController content] 
+                                forKey:expandedString];
+        }
+        if (!err) {
+            err = kim_preferences_create(&prefs);
+        }
         if (!err) {
             err = kim_identity_create_from_string(&identity, [[identityField stringValue] UTF8String]);
         }
         if (!err) {
             options = [KIMUtilities kimOptionsForDictionary:[ticketOptionsController content]];
         }
+        
         if (!identity) { err = KIM_BAD_PRINCIPAL_STRING_ERR; }
         if (!options) { err = KIM_BAD_OPTIONS_ERR; }
         
         if (!err && identity && options) {
             err = kim_preferences_add_favorite_identity(prefs, identity, options);
         }
-                
         if (!err) {
             err = kim_preferences_synchronize(prefs);
         }
     [ticketOptionsSheet orderOut:nil];
 }
 
+- (IBAction) changePasswordGearAction: (id) sender
+{
+    NSString *expandedString = [KIMUtilities expandedIdentity:[identityField stringValue]];
+    NSLog(@"%s", __FUNCTION__);
+    if (expandedString && [expandedString length] > 0) {
+        [expandedString retain];
+        [NSThread detachNewThreadSelector:@selector(changePasswordThread:)
+                                 toTarget:self 
+                               withObject:expandedString];
+    }
+}
+
+- (void) changePasswordThread: (NSString *) identityString
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    kim_error err = KIM_NO_ERROR;
+    kim_identity identity = NULL;
+    
+    NSLog(@"%s %@", __FUNCTION__, identityString);
+    if (!err) {
+        err = kim_identity_create_from_string(&identity, [identityString UTF8String]);
+    }
+    if (!err) {
+        err = kim_identity_change_password(identity);
+    }
+
+    NSLog(@"%s %d", __FUNCTION__, err);
+
+    kim_identity_free(&identity);
+    
+    [identityString release];
+    [pool release];
+}
+
 - (IBAction) cancel: (id) sender
 {
     [associatedClient didCancel];
 
 - (IBAction) enterIdentity: (id) sender
 {
-    NSString *identityString = [glueController valueForKeyPath:identity_string_keypath];
-    NSDictionary *options = [glueController valueForKeyPath:options_keypath];
+    NSString *expandedString = [KIMUtilities expandedIdentity:[identityField stringValue]];
+    NSDictionary *options = [favoriteOptions objectForKey:expandedString];   
     
+    if (!options) {
+        options = [glueController valueForKeyPath:options_keypath];
+    }
     // the principal must already be valid to get this far
-    [associatedClient didEnterIdentity:identityString options:options];
+    [associatedClient didEnterIdentity:expandedString options:options];
 }
 
 - (IBAction) answerAuthPrompt: (id) sender
index 4e448b9d5616d72a44adc35a287a698e0d5db96a..516e8effebffba91f5601e81498843c9e717ba16 100644 (file)
@@ -82,6 +82,8 @@ NSLog(@"%s got error %@", __FUNCTION__, [KIMUtilities stringForLastKIMError:err]
 
 + (BOOL) validateIdentity: (NSString *) identityString;
 
++ (NSString *) expandedIdentity: (NSString *) identityString;
+
 + (NSDictionary *) dictionaryForKimOptions: (kim_options) options;
 + (kim_options) kimOptionsForDictionary: (NSDictionary *) aDict;
 
index f450cdf2ba3122f714ad02113fa0755954f98d23..34ff38e7f6bf1a12da7f162bb205e3b086ad59bf 100644 (file)
@@ -63,6 +63,7 @@
 {
     kim_error err = KIM_NO_ERROR;
     kim_identity identity = NULL;
+    
     if (!identityString || [identityString length] <= 1) {
         err = KIM_BAD_PRINCIPAL_STRING_ERR;
     }
     return (err == KIM_NO_ERROR);
 }
 
++ (NSString *) expandedIdentity: (NSString *) identityString
+{
+    NSString *result = nil;
+    kim_error err = KIM_NO_ERROR;
+    kim_identity identity = NULL;
+    kim_string validated_string = NULL;
+    
+    // convert to how it will actually be
+    // e.g. foo becomes foo@ATHENA.MIT.EDU
+    // for the purpose of matching to a favorite
+    if (!identityString) {
+        err = KIM_BAD_PRINCIPAL_STRING_ERR;
+    }
+    if (!err) {
+        err = kim_identity_create_from_string(&identity, [identityString UTF8String]);
+    }
+    if (!err && identity) {
+        err = kim_identity_get_display_string(identity, &validated_string);
+    }
+    if (!err && validated_string) {
+        result = [NSString stringWithUTF8String:validated_string];
+    }
+    kim_identity_free(&identity);
+    kim_string_free(&validated_string);
+    
+    return result;
+}
+
 + (NSDictionary *) dictionaryForKimOptions: (kim_options) options
 {
     kim_error err = KIM_NO_ERROR;
index e5273b70c6f18da0dc31a9b7effadf90e1f60427..d665e878dc89e1097fa90168d1de4c6a2c0379c9 100644 (file)
                                                                        </object>
                                                                        <object class="NSMenuItem" id="744766544">
                                                                                <reference key="NSMenu" ref="594991555"/>
+                                                                               <bool key="NSIsHidden">YES</bool>
                                                                                <string type="base64-UTF8" key="NSTitle">Q2hhbmdlIFBhc3N3b3Jk4oCmA</string>
                                                                                <string key="NSKeyEquiv"/>
                                                                                <int key="NSMnemonicLoc">2147483647</int>
                                                                        </object>
                                                                </object>
                                                        </object>
+                                                       <int key="NSSelectedIndex">2</int>
                                                        <bool key="NSPullDown">YES</bool>
                                                        <int key="NSPreferredEdge">1</int>
                                                        <bool key="NSUsesItemFromMenu">YES</bool>
                                <string key="NSClassName">NSView</string>
                        </object>
                        <object class="NSCustomView" id="866582848">
-                               <reference key="NSNextResponder"/>
+                               <nil key="NSNextResponder"/>
                                <int key="NSvFlags">274</int>
                                <object class="NSMutableArray" key="NSSubviews">
                                        <bool key="EncodedWithXMLCoder">YES</bool>
                                                <int key="NSvFlags">266</int>
                                                <string key="NSFrame">{{104, 82}, {376, 22}}</string>
                                                <reference key="NSSuperview" ref="866582848"/>
-                                               <reference key="NSWindow"/>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSTextFieldCell" key="NSCell" id="508869457">
                                                        <int key="NSCellFlags">-1804468671</int>
                                                <int key="NSvFlags">289</int>
                                                <string key="NSFrame">{{388, 12}, {98, 32}}</string>
                                                <reference key="NSSuperview" ref="866582848"/>
-                                               <reference key="NSWindow"/>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSButtonCell" key="NSCell" id="200893597">
                                                        <int key="NSCellFlags">67239424</int>
                                                <int key="NSvFlags">289</int>
                                                <string key="NSFrame">{{295, 12}, {93, 32}}</string>
                                                <reference key="NSSuperview" ref="866582848"/>
-                                               <reference key="NSWindow"/>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSButtonCell" key="NSCell" id="935364959">
                                                        <int key="NSCellFlags">67239424</int>
                                                <int key="NSvFlags">266</int>
                                                <string key="NSFrame">{{101, 126}, {382, 41}}</string>
                                                <reference key="NSSuperview" ref="866582848"/>
-                                               <reference key="NSWindow"/>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSTextFieldCell" key="NSCell" id="999660494">
                                                        <int key="NSCellFlags">67239424</int>
                                                <int key="NSvFlags">268</int>
                                                <string key="NSFrame">{{17, 84}, {80, 17}}</string>
                                                <reference key="NSSuperview" ref="866582848"/>
-                                               <reference key="NSWindow"/>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSTextFieldCell" key="NSCell" id="916263740">
                                                        <int key="NSCellFlags">68288064</int>
                                                <int key="NSvFlags">290</int>
                                                <string key="NSFrame">{{102, 58}, {380, 18}}</string>
                                                <reference key="NSSuperview" ref="866582848"/>
-                                               <reference key="NSWindow"/>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSButtonCell" key="NSCell" id="883697888">
                                                        <int key="NSCellFlags">-2080244224</int>
                                                <int key="NSvFlags">268</int>
                                                <string key="NSFrame">{{20, 126}, {64, 64}}</string>
                                                <reference key="NSSuperview" ref="866582848"/>
-                                               <reference key="NSWindow"/>
                                                <string key="NSClassName">BadgedImageView</string>
                                        </object>
                                </object>
                                <string key="NSFrameSize">{500, 210}</string>
-                               <reference key="NSSuperview"/>
-                               <reference key="NSWindow"/>
                                <string key="NSClassName">NSView</string>
                        </object>
                        <object class="NSCustomView" id="898191415">
                                                        <string key="NSKeyPath">selection.identity_string</string>
                                                        <object class="NSDictionary" key="NSOptions">
                                                                <string key="NS.key.0">NSContinuouslyUpdatesValue</string>
-                                                               <integer value="1" key="NS.object.0" id="5"/>
+                                                               <reference key="NS.object.0" ref="9"/>
                                                        </object>
                                                        <reference key="NSPreviousConnector" ref="407856422"/>
                                                        <int key="NSNibBindingConnectorVersion">2</int>
                                                        <string key="NSKeyPath">selection.valid_lifetime</string>
                                                        <object class="NSDictionary" key="NSOptions">
                                                                <string key="NS.key.0">NSContinuouslyUpdatesValue</string>
-                                                               <reference key="NS.object.0" ref="5"/>
+                                                               <reference key="NS.object.0" ref="9"/>
                                                        </object>
                                                        <int key="NSNibBindingConnectorVersion">2</int>
                                                </object>
                                                        <string key="NSKeyPath">selection.renewal_lifetime</string>
                                                        <object class="NSDictionary" key="NSOptions">
                                                                <string key="NS.key.0">NSContinuouslyUpdatesValue</string>
-                                                               <reference key="NS.object.0" ref="5"/>
+                                                               <reference key="NS.object.0" ref="9"/>
                                                        </object>
                                                        <int key="NSNibBindingConnectorVersion">2</int>
                                                </object>
                                        </object>
                                        <int key="connectionID">300520</int>
                                </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBActionConnection" key="connection">
+                                               <string key="label">changePasswordGearAction:</string>
+                                               <reference key="source" ref="262677138"/>
+                                               <reference key="destination" ref="744766544"/>
+                                       </object>
+                                       <int key="connectionID">300522</int>
+                               </object>
                        </object>
                        <object class="IBMutableOrderedSet" key="objectRecords">
                                <object class="NSArray" key="orderedObjects">
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
-                                       <string>{{611, 382}, {189, 93}}</string>
+                                       <string>{{611, 408}, {189, 93}}</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                </object>
                        </object>
                        <nil key="sourceID"/>
-                       <int key="maxID">300520</int>
+                       <int key="maxID">300522</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <object class="NSMutableArray" key="referencedPartialClassDescriptions">
                                                        <string>cancel:</string>
                                                        <string>cancelTicketOptions:</string>
                                                        <string>changePassword:</string>
+                                                       <string>changePasswordGearAction:</string>
                                                        <string>enterIdentity:</string>
                                                        <string>saveTicketOptions:</string>
                                                        <string>showTicketOptions:</string>
                                                        <string>id</string>
                                                        <string>id</string>
                                                        <string>id</string>
+                                                       <string>id</string>
                                                </object>
                                        </object>
                                        <object class="NSMutableDictionary" key="outlets">