Controlling Access to Private AOL Blogs

Continuing our work interacting with the AOL Journals API, this post will demonstrate how to control access to your private blogs using the AOL.Journals CFC.

Each of your private blogs allows you to control who has read access through a simple access control handling API. You can access this list through a link in the collection document of your private blog. With three formats available for data interchange (xhtml,xoxo, and json), the API is flexible and simple. If you're a ColdFusion developer, it's even simpler to use the AOL.Journals CFC since much of the heavy lifting is done for you. Like most of the other examples we've worked with in the past, start off by creating a new AOL.Journals component instance and get a workspace configuration as shown below:

<!--- create a new Journals object --->
<cfset obj_aolJournals = CreateObject( "component", "AOL.Journals" ).init( "bricemason", session.obj_openAuth ) />

<!--- get the workspace --->
<cfset st_workspace = obj_aolJournals.getWorkspace() />

The ColdFusion structure returned from the getWorkspace method contains the URL to the collection document of a particular blog. We'll use this data as an argument to the getAccessList method which retrieves the reader access control list. The result of the code in Listing 1 which gets the access list of a private blog named My Private Journal is shown in Figure 1.

<!--- get the current access list --->
<cfset xml_accessList = obj_aolJournals.getAccessList( st_workspace[ "My Private Journal" ].href ) />

<cfdump var="#xml_accessList#" />
Listing 1 - Getting the original access list


Figure 1 - Dump of original access list

Since the default return type for this request is xhtml, it fits perfectly with the AOL.Journals CFC. The response is parsed as XML and made available back to ColdFusion as an XML object. Based on the results in Figure 1, you can see that we don't have any readers currently configured for the My Private Journal blog. We can change this easily by using the setAccessList method of the AOL.Journals CFC. Simply configure a structure with a key named list and a value which is an array of screennames you want to allow read access. Behind the scenes, this data structure will be encoded as JSON and submitted to the AOL Journals service as a replacement reader access list.

<!--- configure the access list --->
<cfset st_accessList = StructNew() />
<cfset StructInsert( st_accessList, "list", ArrayNew(1) ) />
<cfset ArrayAppend( st_accessList.list, "reader1" ) />

<!--- set a new access list --->
<cfset xml_accessList = obj_aolJournals.setAccessList( st_workspace[ "My Private Journal" ].href,
                                                       st_accessList ) />

<!--- setAccessList returns the new access list, dump it --->
<cfdump var="#xml_accessList#" />

As you can see below, we have a single entry in our access control list for the reader1 screenname.

Resources