constraintsRefs.add("public-view");
constraints.setSecurityConstraintsRefs(constraintsRefs);
folder.setSecurityConstraints(constraints);
pageManager.updateFolder(folder);
PageSecurity pageSecurity = pageManager.newPageSecurity();
List constraintsDefs = new ArrayList(2);
SecurityConstraintsDef constraintsDef = pageManager.newSecurityConstraintsDef();
constraintsDef.setName("public-view");
List defConstraints = new ArrayList(1);
SecurityConstraint defConstraint = pageManager.newPageSecuritySecurityConstraint();
defConstraint.setUsers(Shared.makeListFromCSV("*"));
defConstraint.setPermissions(Shared.makeListFromCSV("view"));
defConstraints.add(defConstraint);
constraintsDef.setSecurityConstraints(defConstraints);
constraintsDefs.add(constraintsDef);
constraintsDef = pageManager.newSecurityConstraintsDef();
constraintsDef.setName("admin-all");
defConstraints = new ArrayList(1);
defConstraint = pageManager.newPageSecuritySecurityConstraint();
defConstraint.setRoles(Shared.makeListFromCSV("admin"));
defConstraint.setPermissions(Shared.makeListFromCSV("view,edit"));
defConstraints.add(defConstraint);
constraintsDef.setSecurityConstraints(defConstraints);
constraintsDefs.add(constraintsDef);
pageSecurity.setSecurityConstraintsDefs(constraintsDefs);
List globalConstraintsRefs = new ArrayList(1);
globalConstraintsRefs.add("admin-all");
pageSecurity.setGlobalSecurityConstraintsRefs(globalConstraintsRefs);
pageManager.updatePageSecurity(pageSecurity);
Page page = pageManager.newPage("/default-page.psml");
constraints = pageManager.newSecurityConstraints();
constraints.setOwner("admin");
List inlineConstraints = new ArrayList(1);
SecurityConstraint constraint = pageManager.newPageSecurityConstraint();
constraint.setRoles(Shared.makeListFromCSV("manager"));
constraint.setPermissions(Shared.makeListFromCSV("edit"));
inlineConstraints.add(constraint);
constraints.setSecurityConstraints(inlineConstraints);
constraintsRefs = new ArrayList(1);
constraintsRefs.add("public-view");
constraints.setSecurityConstraintsRefs(constraintsRefs);
page.setSecurityConstraints(constraints);
Fragment root = page.getRootFragment();
root.setName("jetspeed-layouts::VelocityTwoColumns");
Fragment portlet = pageManager.newPortletFragment();
portlet.setName("security::LoginPortlet");
root.getFragments().add(portlet);
portlet = pageManager.newPortletFragment();
portlet.setName("some-app::SomePortlet");
SecurityConstraints fragmentConstraints = pageManager.newSecurityConstraints();
fragmentConstraints.setOwner("user");
portlet.setSecurityConstraints(fragmentConstraints);
root.getFragments().add(portlet);
pageManager.updatePage(page);
TestCase.assertNotNull(page.getRootFragment());
TestCase.assertNotNull(page.getRootFragment().getFragments());
TestCase.assertEquals(2, page.getRootFragment().getFragments().size());
TestCase.assertEquals("some-app::SomePortlet", ((Fragment)page.getRootFragment().getFragments().get(1)).getName());
TestCase.assertFalse("0".equals(((Fragment)page.getRootFragment().getFragments().get(1)).getId()));
somePortletId[0] = ((Fragment)page.getRootFragment().getFragments().get(1)).getId();
page = pageManager.newPage("/user-page.psml");
constraints = pageManager.newSecurityConstraints();
inlineConstraints = new ArrayList(1);
constraint = pageManager.newPageSecurityConstraint();
constraint.setUsers(Shared.makeListFromCSV("user"));
constraint.setPermissions(Shared.makeListFromCSV("view,edit"));
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]));