This chapter provides sample code that shows how to work with nodes. Opening a session, finding a node, and authenticating a user to the node are fundamental Open Directory tasks.
The sample code in Listing 2-1 demonstrates how to initialize a session object and retrieve a list of all registered nodes. Corresponding C API for this and all other Cocoa examples in this document can be found in Open Directory Functions Reference.
Listing 2-1 Listing registered nodes
ODSession *mySession = [ODSession defaultSession]; |
NSError *err; |
NSArray *nodeNames = [mySession nodeNamesAndReturnError:&err]; |
Open Directory nodes can be found by type or by name. Listing 2-2 demonstrates how to find the authentication node of a session by its type.
Listing 2-2 Finding a node by type
ODNode *myNode = [ODNode nodeWithSession:mySession type:kODNodeTypeAuthentication error:&err]; |
The sample code in Listing 2-3 demonstrates how to find the node for a specific pathname.
Listing 2-3 Finding the node for a pathname
NSString *nodeName = @"/LDAPv3/127.0.0.1"; |
ODNode *myNode = [ODNode nodeWithSession:mySession name:nodeName error:&err]; |
To authenticate itself to the Open Directory for the purposes of reading, writing, or making changes to a node, an Open Directory client application calls one of the three following methods of an ODNode object:
setCredentialsWithRecordType:recordName:password:error:
authenticates using standard username-password authentication.
setCredentialsUsingKerberosCache:error:
authenticates using a provided Kerberos cache..
setCredentialsWithRecordType:authenticationType:authenticationItems:continueItems:context:error:
allows the application to authenticate using one of several other types of authentication supported by the node. See Authentication Types
for a list of possible authentication types.
Last updated: 2009-08-12