Specifying Users for a Folder and Granting Access Rights

To limit access to a folder, you specify the list of users and their privileges for the folder. You can create a community of users.

To specify the list of users and their access rights, you add entries to the access control list for a folder, as described in the following procedure:

  1. Create a vector of AclEntry objects. Specify the users and privileges as you construct the entries.

  2. To retrieve the access control list for the folder for which you want to specify users, call the getAcl method of the folder or context.

  3. Call the addEntries method of the access control list of the context to add the vector to the list of users.

Example: Granting access rights to users of a folder

The following code example adds several users to a folder named MyFolder and all of its subfolders, granting different access rights to each user. This code assumes a PersistenceManager object that is named pmMyFolder, which represents MyFolder.


//create and fill the vector of entries Vector entries = new Vector(); entries.addElement(new AclEntryImpl(new UserImpl("John Jones"),   Privilege.LIST)); entries.addElement(new AclEntryImpl(new UserImpl("Ann Smith"),   Privilege.READ)); entries.addElement(new AclEntryImpl(new UserImpl("Ron Green"),   Privilege.ADD_FOLDER)); entries.addElement(new AclEntryImpl(new UserImpl("Becky Davis"),   Privilege.WRITE)); entries.addElement(new AclEntryImpl(new UserImpl("Tim Franklin"),   Privilege.FULL_CONTROL)); try{   //get the access control list for MyFolder   AclObject acl = (AclObject) pmMyFolder.getAcl();   // add the entries to the acl object   // the true argument grants the same access for the same users   // to the subfolders of MyFolder   acl.addEntries(entries, true); } catch (NamingException ne){   ne.printStackTrace(); }

Note: Removing access rights is similar to granting them. You create a vector of entries, as shown in the previous example, and call the removeEntries method to remove the access rights.

Changing Access Rights of a User for a Folder
Creating a Community of Authorized Users
Granting Privileges to Users