SFAuthorizationView - again...
SFAuthorizationView - again...
- Subject: SFAuthorizationView - again...
- From: Eric Long <email@hidden>
- Date: Thu, 04 Mar 2004 12:02:21 -0800
Hi,
I posted recently about SFAuthorizationView. I managed to get code working
to a point, but I still have a couple of issues that I'm not sure what to do
about. Maybe someone here can clear up the fog.
My intended use of the SFAuthorizationView is to have it come up authorized
by default, and if the user chooses I will allow him or her to deauthorize
and require password authentication before settings may be modified. I
maintain the state of the user's choice persistently across runs of the
application.
In my windowDidLoad() method of my window controller class I set up the
initial state for the view like this:
-------
if (requireAuthentication == NO)
{
// init to display lock unlocked
OSStatus myStatus;
AuthorizationRef myAuthorizationRef;
myStatus = AuthorizationCreate (NULL, kAuthorizationEmptyEnvironment,
kAuthorizationFlagDefaults, &myAuthorizationRef);
if (myStatus == errAuthorizationSuccess)
{
AuthorizationItem item = {"com.myCompany.myApp.editSettings", 0,
NULL, 0};
AuthorizationRights rightsRequested = {1, &item}, *authorizedRights =
NULL;
AuthorizationFlags flags = kAuthorizationFlagDefaults |
kAuthorizationFlagPreAuthorize |
kAuthorizationFlagExtendRights |
kAuthorizationFlagPartialRights;
myStatus = AuthorizationCopyRights(myAuthorizationRef,
&rightsRequested, kAuthorizationEmptyEnvironment, flags, &authorizedRights);
if (myStatus == errAuthorizationSuccess)
{
[authenticationView setAuthorizationRights: authorizedRights];
AuthorizationFreeItemSet(authorizedRights);
}
AuthorizationFree(myAuthorizationRef,
kAuthorizationFlagDestroyRights);
}
}
else
{
// init to display lock locked
[authenticationView
setString:(NSString*)"com.myCompany.myApp.editSettings"];
}
[authenticationView updateStatus:self];
--------
This appeared to work well, but two problems have appeared.
#1 - I noticed that if the user deauthorizes, then reauthorizes, then quits
the app, the next time the app is brought up the same code above that
normally works for authorizing the user wasn't working as expected. The
view came up with the lock locked-- for one time only. The next time the
code was called it works as expected. I tested by adding a loop around the
code that executes if requireAuthentication == NO, so it would execute
twice. That made the problem go away, but it's an obvious hack. I don't
know what I'm doing wrong, but it's clear I'm missing the boat somehow.
#2 - There seems to be a connection between what my App does and whether or
not my System Preferences panels appear authorized or deauthorized. If I
deauthorize in my app, pref panels like Startup Disk appear deauthorized. I
don't want this connection and I don't know why there is a connection.
I'm just trying to use SFAuthorizationView so the appearance is consistent
with the OS. I'm not looking for the OS to actually provide real rights to
my user, like an installer or other processes might need to support.
Can anyone clear up the mystery here for me?
Thanks for your help,
Eric
_______________________________________________
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.