inlineConstraints.add(constraint);
constraints.setSecurityConstraints(inlineConstraints);
page.setSecurityConstraints(constraints);
pageManager.updatePage(page);
Link link = pageManager.newLink("/default.link");
link.setUrl("http://www.default.org/");
constraints = pageManager.newSecurityConstraints();
constraints.setOwner("admin");
inlineConstraints = new ArrayList(1);
constraint = pageManager.newLinkSecurityConstraint();
constraint.setRoles(Shared.makeListFromCSV("manager"));
constraint.setPermissions(Shared.makeListFromCSV("edit"));
inlineConstraints.add(constraint);
constraints.setSecurityConstraints(inlineConstraints);
link.setSecurityConstraints(constraints);
pageManager.updateLink(link);
return null;
}
catch (Exception e)
{
return e;
}
}
}, null);
if (setup != null)
{
throw setup;
}
// reset page manager cache
pageManager.reset();
// access test as admin user
Exception adminAccess = (Exception)JSSubject.doAsPrivileged(adminSubject, new PrivilegedAction()
{
public Object run()
{
try
{
// test view access
Folder folder = pageManager.getFolder("/");
TestCase.assertNotNull(folder.getPageSecurity());
TestCase.assertNotNull(folder.getPages());
TestCase.assertEquals(2, folder.getPages().size());
TestCase.assertNotNull(pageManager.getPages(folder));
TestCase.assertEquals(2, pageManager.getPages(folder).size());
PageSecurity pageSecurity = pageManager.getPageSecurity();
Page page0 = pageManager.getPage("/default-page.psml");
TestCase.assertNotNull(page0.getRootFragment());
TestCase.assertNotNull(page0.getRootFragment().getFragments());
TestCase.assertEquals(2, page0.getRootFragment().getFragments().size());
TestCase.assertNotNull(page0.getFragmentById(somePortletId[0]));
TestCase.assertNotNull(page0.getFragmentsByName("some-app::SomePortlet"));
TestCase.assertEquals(1, page0.getFragmentsByName("some-app::SomePortlet").size());
Page page1 = pageManager.getPage("/user-page.psml");
Link link = pageManager.getLink("/default.link");
// test edit access
pageManager.updateFolder(folder);
pageManager.updatePageSecurity(pageSecurity);
pageManager.updatePage(page0);
pageManager.updatePage(page1);
pageManager.updateLink(link);
return null;
}
catch (Exception e)
{
return e;
}
}
}, null);
if (adminAccess != null)
{
throw adminAccess;
}
// access test as user user
Exception userAccess = (Exception)JSSubject.doAsPrivileged(userSubject, new PrivilegedAction()
{
public Object run()
{
try
{
// test view access
Folder folder = pageManager.getFolder("/");
TestCase.assertNotNull(folder.getPageSecurity());
TestCase.assertNotNull(folder.getPages());
TestCase.assertEquals(2, folder.getPages().size());
PageSecurity pageSecurity = pageManager.getPageSecurity();
Page page0 = pageManager.getPage("/default-page.psml");
TestCase.assertNotNull(page0.getRootFragment());
TestCase.assertNotNull(page0.getRootFragment().getFragments());
TestCase.assertEquals(2, page0.getRootFragment().getFragments().size());
TestCase.assertNotNull(page0.getFragmentById(somePortletId[0]));
TestCase.assertNotNull(page0.getFragmentsByName("some-app::SomePortlet"));
TestCase.assertEquals(1, page0.getFragmentsByName("some-app::SomePortlet").size());
Page page1 = pageManager.getPage("/user-page.psml");
Link link = pageManager.getLink("/default.link");
// test edit access
try
{
pageManager.updateFolder(folder);
TestCase.assertTrue("Folder / not editable for user", false);
}
catch (SecurityException se)
{
}
try
{
pageManager.updatePageSecurity(pageSecurity);
TestCase.assertTrue("PageSecurity not editable for user", false);
}
catch (SecurityException se)
{
}
try
{
pageManager.updatePage(page0);
TestCase.assertTrue("Page /default-page.psml not editable for user", false);
}
catch (SecurityException se)
{
}
pageManager.updatePage(page1);
try
{
pageManager.updateLink(link);
TestCase.assertTrue("Page /default.link not editable for user", false);
}
catch (SecurityException se)
{
}
return null;
}
catch (Exception e)
{
return e;
}
}
}, null);
if (userAccess != null)
{
throw userAccess;
}
// access test as manager user
Exception managerAccess = (Exception)JSSubject.doAsPrivileged(managerSubject, new PrivilegedAction()
{
public Object run()
{
try
{
// test view access
Folder folder = pageManager.getFolder("/");
TestCase.assertNotNull(folder.getPageSecurity());
TestCase.assertNotNull(folder.getPages());
TestCase.assertEquals(1, folder.getPages().size());
PageSecurity pageSecurity = pageManager.getPageSecurity();
Page page0 = pageManager.getPage("/default-page.psml");
TestCase.assertNotNull(page0.getRootFragment());
TestCase.assertNotNull(page0.getRootFragment().getFragments());
TestCase.assertEquals(1, page0.getRootFragment().getFragments().size());
TestCase.assertNull(page0.getFragmentById(somePortletId[0]));
TestCase.assertTrue(page0.getFragmentsByName("some-app::SomePortlet").isEmpty());
Link link = pageManager.getLink("/default.link");
try
{
pageManager.getPage("/user-page.psml");
TestCase.assertTrue("Page /user-page.psml not viewable for manager", false);
}
catch (SecurityException se)
{
}
// test edit access
try
{
pageManager.updateFolder(folder);
TestCase.assertTrue("Folder / not editable for manager", false);
}
catch (SecurityException se)
{
}
try
{
pageManager.updatePageSecurity(pageSecurity);
TestCase.assertTrue("PageSecurity not editable for manager", false);
}
catch (SecurityException se)
{
}
pageManager.updatePage(page0);
pageManager.updateLink(link);
return null;
}
catch (Exception e)
{
return e;
}
}
}, null);
if (managerAccess != null)
{
throw managerAccess;
}
// access test as guest user
Exception guestAccess = (Exception)JSSubject.doAsPrivileged(guestSubject, new PrivilegedAction()
{
public Object run()
{
try
{
// test view access
Folder folder = pageManager.getFolder("/");
TestCase.assertNotNull(folder.getPageSecurity());
TestCase.assertNotNull(folder.getPages());
TestCase.assertEquals(1, folder.getPages().size());
PageSecurity pageSecurity = pageManager.getPageSecurity();
Page page0 = pageManager.getPage("/default-page.psml");
TestCase.assertNotNull(page0.getRootFragment());
TestCase.assertNotNull(page0.getRootFragment().getFragments());
TestCase.assertEquals(1, page0.getRootFragment().getFragments().size());
TestCase.assertNull(page0.getFragmentById(somePortletId[0]));
TestCase.assertTrue(page0.getFragmentsByName("some-app::SomePortlet").isEmpty());
Link link = pageManager.getLink("/default.link");
try
{
pageManager.getPage("/user-page.psml");
TestCase.assertTrue("Page /user-page.psml not viewable for guest", false);
}