| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/SecurityInterface.framework |
| Availability | Available in Mac OS X v10.3 and later |
| Companion guide | |
| Declared in | SFAuthorizationView.h |
The SFAuthorizationView class displays a lock icon that can be used as a visual indication that a user interface has restricted access.
The lock appears locked when the user must be authorized and appears open when the user has been authorized. The closed and open lock icons of the authorization view are shown in the following figure.
When you add an authorization view as a custom view to a window or dialog box, you must initialize it before it displays correctly. To initialize the view, use the setString: method to create a default rights structure (containing a prompt string) or the setAuthorizationRights: method to specify a rights structure. You must also either specify automatic updates (setAutoupdate: or setAutoupdate:interval:) or perform a manual update (updateStatus:) to set the lock icon to its initial state.
You can implement delegate methods that are invoked when the authorization view changes state. You can optionally implement the delegate methods to obtain the state of the authorization object when you are using an authorization view.
When the user clicks a locked authorization view icon, the Security Server displays an authentication dialog (to request a user name and password, for example). When the user provides the requested credentials, the lock icon unlocks and the user is considered preauthorized to perform the functions specified by the authorization rights structure. You can call the updateStatus: method to determine whether the user has been preauthorized: this method returns YES if the view is in the unlocked state, NO otherwise. Before committing changes or performing actions that require authorization, you should check the user’s authorization again, even if they are preauthorized.
The default behavior of this view is to preauthorize rights; if this is not possible it unlocks and waits for authorization to be checked when explicitly required.
– setString:
– setAuthorizationRights:
– setAutoupdate:
– setAutoupdate:interval:
– setFlags:
– setEnabled:
– authorizationViewCreatedAuthorization: delegate method
– authorizationViewDidAuthorize: delegate method
– authorizationViewDidDeauthorize: delegate method
– authorizationViewReleasedAuthorization: delegate method
– authorizationViewShouldDeauthorize: delegate method
Returns the authorization object associated with this view.
- (SFAuthorization *)authorization
The authorization object is defined in Security Foundation Framework Reference.
SFAuthorizationView.hReturns the authorization rights for this view.
- (AuthorizationRights *)authorizationRights
SFAuthorizationView.hReturns the current state of the authorization view.
- (SFAuthorizationViewState)authorizationState
SFAuthorizationView.hAttempts to unlock the lock icon in the view.
- (BOOL)authorize:(id)inSender
The authorization view to unlock.
This method has the same behavior as if the user clicked on the lock icon; if the user is authorized, the lock icon unlocks. If this method succeeds, it returns YES; if it fails, the lock icon remains locked and the method returns NO.
SFAuthorizationView.hSets the authorization state to unauthorized and locks the lock icon in the view.
- (BOOL)deauthorize:(id)inSender
The authorization view to lock.
If this method succeeds, it returns YES; if it fails, the lock icon remains unlocked and the method returns NO.
SFAuthorizationView.hReturns the delegate for this view.
- (id)delegate
SFAuthorizationView.hIndicates whether the authorization view is enabled (YES) or disabled (NO).
- (BOOL)isEnabled
SFAuthorizationView.hSets the authorization rights for this view.
- (void)setAuthorizationRights:(const AuthorizationRights *)authorizationRights
An authorization rights structure specifying the authorization rights represented by the authorization view.
Either this method or the setString: method must be called before the view displays correctly.
The authorization rights structures are defined in AuthorizationRights in Authorization Services C Reference.
SFAuthorizationView.hSets the authorization view to update itself automatically.
- (void)setAutoupdate:(BOOL)autoupdate
Specifies whether the authorization view should update itself automatically. Set to YES to enable autoupdates.
If autoupdates are enabled and the authorization times out (for example), the authorization view automatically relocks. If autoupdates are disabled, you have to call the updateStatus: method to manually update the view if the status changes when the user has not clicked on the lock icon. Autoupdates are disabled by default. Because autoupdates poll, they can affect system performance.
SFAuthorizationView.hSets the authorization view to update itself at a specific interval.
- (void)setAutoupdate:(BOOL)autoupdate interval:(NSTimeInterval)interval
Specifies whether the authorization view should update itself automatically. Set to YES to enable autoupdates.
If autoupdate is YES, sets the interval at which updates take place, in seconds.
If autoupdates are enabled and the authorization times out (for example), the authorization view automatically relocks. If autoupdates are disabled, you have to call the updateStatus: method to manually update the view if the status changes when the user has not clicked on the lock icon. Autoupdates are disabled by default. Because autoupdates poll, they can affect system performance. For that reason, you might want to set a time interval so that the polling does not take place as often.
SFAuthorizationView.hSets the delegate for this authorization view.
- (void)setDelegate:(id)delegate
The object to which messages about the state of the authorization object should be sent.
If you want to be notified of state changes (for example, when the user clicks the button), set a delegate and implement the delegate methods described in the delegate methods section.
SFAuthorizationView.hSets the current state of the authorization view.
- (void)setEnabled:(BOOL)enabled
Specifies whether the authorization view should be enabled (YES) or disabled (NO).
A disabled view is visible but dimmed.
SFAuthorizationView.hSets the current authorization flags for the view.
- (void)setFlags:(AuthorizationFlags)flags
The authorization flags to set for this view.
You can use this method to change the authorization flag settings made with the setAuthorizationRights: method or to specify flags other than the default (kAuthorizationFlagDefaults) used by the setString: method.
The authorization flags are described in Authorization Options in Authorization Services C Reference.
SFAuthorizationView.hSets the requested-right string to use with the default authorization rights set.
- (void)setString:(AuthorizationString)authorizationString
The string to be displayed.
This is a convenience method that creates an authorization rights set when you specify only the name of the requested right. The requested-right string is displayed in the Details pane of the user authentication dialog box. Either this method or the setAuthorizationRights: method must be called before the view displays correctly.
SFAuthorizationView.hManually updates the authorization view.
- (BOOL)updateStatus:(id)inSender
The authorization view to update.
Calls to updateStatus: return YES if in the unlocked state, NO otherwise.
If autoupdates have not been set, you must call updateStatus for the authorization view’s initial state to display correctly. The Security Framework calls this method for you when you change the state of the lock (by calling deauthorize:, for example.
SFAuthorizationView.hSent to the delegate to indicate the authorization object has been created or changed. If you have saved a copy of the authorization object for your own purposes, you should discard it and call authorization for a new authorization object.
- (void)authorizationViewCreatedAuthorization:(SFAuthorizationView *)view
SFAuthorizationView.hSent to the delegate to indicate the user was authorized and the authorization view was changed to unlocked.
- (void)authorizationViewDidAuthorize:(SFAuthorizationView *)view
SFAuthorizationView.hSent to the delegate to indicate the user was deauthorized and the authorization view was changed to locked.
- (void)authorizationViewDidDeauthorize:(SFAuthorizationView *)view
SFAuthorizationView.hSent to the delegate to indicate that deauthorization is about to occur.
- (void)authorizationViewReleasedAuthorization:(SFAuthorizationView *)view
This method is called after deauthorization has been approved (either you called the deauthorize: method, or the user clicked an open lock icon and the authorizationViewShouldDeauthorize: delegate method did not cancel the operation), and before the user is deauthorized (that is, before the authorizationViewDidDeauthorize: delegate method is called).
SFAuthorizationView.hSent to the delegate when a user clicks the open lock icon.
- (BOOL)authorizationViewShouldDeauthorize:(SFAuthorizationView *)view
The delegate can react to this before deauthorization happens and avoid it by returning NO. This delegate method is not called when you call the deauthorize: method.
SFAuthorizationView.hThese constants are of type SFAuthorizationViewState and define the current state of the authorization view.
Last updated: 2006-05-23