// first retrieve the authorization manager for the acl-domain.
InitialContext ctx = new InitialContext();
AuthorizationManager manager = (AuthorizationManager) ctx.lookup("java:jaas/acl-domain/authorizationMgr");
// create a resource 1 that has resource 2 as a child.
TestResource resource1 = new TestResource(1);
TestResource resource2 = new TestResource(2);
Collection<Resource> childResources = new ArrayList<Resource>();
childResources.add(resource2);
resource1.getMap().put(ResourceKeys.CHILD_RESOURCES, childResources);
resource2.getMap().put(ResourceKeys.PARENT_RESOURCE, resource1);
// retrieve the identity name from the request.
String name = request.getParameter("identity");
Identity identity = new SimpleIdentity(name);
// now call the getEntitlements method using created resource and identity objects.
EntitlementHolder<EntitlementEntry> holder = manager.getEntitlements(EntitlementEntry.class, resource1,
identity);
// write the results in the response (resource id : permissions)
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
for (EntitlementEntry entry : holder.getEntitled())
{
TestResource resource = (TestResource) entry.getResource();
writer.println(resource.getId() + ":" + entry.getPermission());
}
writer.close();
}
catch (Exception e)
{