Mac Developer Library

Developer

SecurityInterface Framework Reference SFAuthorizationView Class Reference

Options
Deployment Target:

On This Page
Language:

SFAuthorizationView

Inheritance


Import Statement


Not Applicable

Objective-C

@import SecurityInterface;

Availability


Available in OS X v10.3 and later

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.

Figure 1Authorization view lock icon image: ../Art/authview.eps

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 YEStrue if the view is in the unlocked state, NOfalse 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.

  • Sets the requested-right string to use with the default authorization rights set.

    Declaration

    Objective-C

    - (void)setString:(AuthorizationString)authorizationString

    Parameters

    authorizationString

    The string to be displayed.

    Discussion

    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.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sets the authorization rights for this view.

    Declaration

    Objective-C

    - (void)setAuthorizationRights:(const AuthorizationRights *)authorizationRights

    Parameters

    authorizationRights

    An authorization rights structure specifying the authorization rights represented by the authorization view.

    Discussion

    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.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sets the authorization view to update itself automatically.

    Declaration

    Objective-C

    - (void)setAutoupdate:(BOOL)autoupdate

    Parameters

    autoupdate

    Specifies whether the authorization view should update itself automatically. Set to YEStrue to enable autoupdates.

    Discussion

    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.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sets the authorization view to update itself at a specific interval.

    Declaration

    Objective-C

    - (void)setAutoupdate:(BOOL)autoupdate interval:(NSTimeInterval)interval

    Parameters

    autoupdate

    Specifies whether the authorization view should update itself automatically. Set to YEStrue to enable autoupdates.

    interval

    If autoupdate is YEStrue, sets the interval at which updates take place, in seconds.

    Discussion

    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.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sets the current authorization flags for the view.

    Declaration

    Objective-C

    - (void)setFlags:(AuthorizationFlags)flags

    Parameters

    flags

    The authorization flags to set for this view.

    Discussion

    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.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sets the current state of the authorization view.

    Declaration

    Objective-C

    - (void)setEnabled:(BOOL)enabled

    Parameters

    enabled

    Specifies whether the authorization view should be enabled (YEStrue) or disabled (NOfalse).

    Discussion

    A disabled view is visible but dimmed.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sets the delegate for this authorization view.

    Declaration

    Objective-C

    - (void)setDelegate:(id)delegate

    Parameters

    delegate

    The object to which messages about the state of the authorization object should be sent.

    Discussion

    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.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

    See Also

    – delegate.

  • Returns the delegate for this view.

    Declaration

    Objective-C

    - (id)delegate

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Manually updates the authorization view.

    Declaration

    Objective-C

    - (BOOL)updateStatus:(id)inSender

    Parameters

    inSender

    The authorization view to update.

    Discussion

    Calls to updateStatus: return YEStrue if in the unlocked state, NOfalse 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.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Attempts to unlock the lock icon in the view.

    Declaration

    Objective-C

    - (BOOL)authorize:(id)inSender

    Parameters

    inSender

    The authorization view to unlock.

    Discussion

    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 YEStrue; if it fails, the lock icon remains locked and the method returns NOfalse.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sets the authorization state to unauthorized and locks the lock icon in the view.

    Declaration

    Objective-C

    - (BOOL)deauthorize:(id)inSender

    Parameters

    inSender

    The authorization view to lock.

    Discussion

    If this method succeeds, it returns YEStrue; if it fails, the lock icon remains unlocked and the method returns NOfalse.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

    See Also

    – authorize:

  • Sent to the delegate when a user clicks the open lock icon.

    Declaration

    Objective-C

    - (BOOL)authorizationViewShouldDeauthorize:(SFAuthorizationView *)view

    Discussion

    The delegate can react to this before deauthorization happens and avoid it by returning NOfalse. This delegate method is not called when you call the deauthorize: method.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sent 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.

    Declaration

    Objective-C

    - (void)authorizationViewCreatedAuthorization:(SFAuthorizationView *)view

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sent to the delegate to indicate the user was authorized and the authorization view was changed to unlocked.

    Declaration

    Objective-C

    - (void)authorizationViewDidAuthorize:(SFAuthorizationView *)view

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.

  • Sent to the delegate to indicate the user was deauthorized and the authorization view was changed to locked.

    Declaration

    Objective-C

    - (void)authorizationViewDidDeauthorize:(SFAuthorizationView *)view

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 or later.

  • Sent to the delegate to indicate that the view’s visibility has changed.

    Declaration

    Objective-C

    - (void)authorizationViewDidHide:(SFAuthorizationView *)view

    Discussion

    This delegate method, if present, is called whenever the setHidden: method is called to show or hide the view.

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.7 and later.

  • Sent to the delegate to indicate that deauthorization is about to occur.

    Declaration

    Objective-C

    - (void)authorizationViewReleasedAuthorization:(SFAuthorizationView *)view

    Discussion

    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).

    Import Statement

    Objective-C

    @import SecurityInterface;

    Availability

    Available in OS X v10.3 and later.