Note: the AC code is somewhat deprecated right now, since it is designed mostly to work with mirrored nodes, and CCK does not yet have good support for "by field" access control. But if you want to use it, here's how:
Access control to contacts is probably the most difficult piece of the CiviNode code base, and needs a bit of discussion. Perhaps the best way to start is with the basic scheme, and then a discussion of how this is different from what CiviCRM already does, and how it differs from different schemes used or under discussion for Drupal.
CiviNode defines a node type, 'civinode_access', that defines a basic unit of access. Since CRM groups are the core way of accessing and organizing contacts in CiviCRM, I've defined an access as the combination of:
The access related information is stored in civinode_access, which gets merged into the node at node_load time.
Defining accesses as nodes is just a convenience; it made it easy to manage them. But I don't see any drawbacks in doing this so far. When a more elaborate UI is needed for managing access, it seems to me I can use Views of access nodes to do this for anything I'd expect be needed.
Most of this works via hook_access, and for everything but the 'view' access, it works well. For 'view', it turns out, it doesn't work at all :-( In the end, I swallowed the whole frog and create records in the node_access table on the fly. I also support hook_db_rewrite_sql. This requires me to do a few things that I hate doing:
Mostly this code works, although I am still finding SQL errors in some cases. If someone can tell me how to do this in a simpler way, I'm all ears. But from what I've heard from the Drupalers who know the node access system well, I don't think there is one.
Earl Mile's new module, na_arbitrator, has been suggested as one way to handle this problem. I looked at it, and while Earl's scheme is quite clever, it really is designed to handle nodes, and it is designed to handle them via static tables. Therein lies its problem for this application: an external system (CiviCRM) determines who can see what, and in general it isn't possible to construct a query that uses CiviCRM's database tables, which need not be in the same database, or even on the same host. So I need similar tables to the ones Earl implements, but I need somewhat more information about contacts than na_arbitrator will allow for.
There are going to be a number of applications that will be much easier to do thanks to Earl's work. But it doesn't look like CiviCRM related work will be among them.