portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r357085 [2/2] - in /portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager: ./ src/java/JETSPEED-INF/castor/ src/java/org/apache/jetspeed/om/folder/psml/ src/java/org/apache/jetspeed/om/page/psml/ src/java/org/apache/jets...
Date Thu, 15 Dec 2005 23:13:04 GMT
Added: portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecureCastorXmlPageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecureCastorXmlPageManager.java?rev=357085&view=auto
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecureCastorXmlPageManager.java
(added)
+++ portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecureCastorXmlPageManager.java
Thu Dec 15 15:12:55 2005
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.page;
+
+import java.io.File;
+import java.io.FileFilter;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.jetspeed.page.psml.CastorXmlPageManager;
+
+/**
+ * TestSecureCastorXmlPageManager
+ * 
+ * @author <a href="rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+public class TestSecureCastorXmlPageManager extends TestCase implements PageManagerTestShared

+{
+    protected CastorXmlPageManager pageManager;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        pageManager = Shared.makeCastorXMLPageManager("secure-pages", false, true);
+    }
+
+    /**
+     * <p>
+     * tearDown
+     * </p>
+     * 
+     * @see junit.framework.TestCase#tearDown()
+     * @throws java.lang.Exception
+     */
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+    }
+
+    /**
+     * Defines the testcase name for JUnit.
+     * 
+     * @param name
+     *            the testcase's name.
+     */
+    public TestSecureCastorXmlPageManager( String name )
+    {
+        super(name);
+    }
+
+    /**
+     * Start the tests.
+     * 
+     * @param args
+     *            the arguments. Not used
+     */
+    public static void main( String args[] )
+    {
+        junit.awtui.TestRunner.main(new String[]{TestSecureCastorXmlPageManager.class.getName()});
+    }
+
+    /**
+     * Creates the test suite.
+     * 
+     * @return a test suite (<code>TestSuite</code>) that includes all
+     *         methods starting with "test"
+     */
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(TestSecureCastorXmlPageManager.class);
+    }
+
+    public void testSecurePageManager() throws Exception
+    {
+        // utilize standard secure page manager test
+        Shared.testSecurePageManager(this, pageManager);
+    }
+}

Propchange: portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecureCastorXmlPageManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecureDatabasePageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecureDatabasePageManager.java?rev=357085&r1=357084&r2=357085&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecureDatabasePageManager.java
(original)
+++ portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecureDatabasePageManager.java
Thu Dec 15 15:12:55 2005
@@ -81,420 +81,7 @@
 
     public void testSecurePageManager() throws Exception
     {
-        // reset page manager cache
-        pageManager.reset();
-
-        // setup test subjects
-        Principal userPrincipal = new UserPrincipalImpl("admin");
-        Principal rolePrincipal = new RolePrincipalImpl("admin");
-        Set principals = new PrincipalsSet();
-        principals.add(userPrincipal);
-        principals.add(rolePrincipal);
-        Subject adminSubject = new Subject(true, principals, new HashSet(), new HashSet());
-
-        userPrincipal = new UserPrincipalImpl("user");
-        principals = new PrincipalsSet();
-        principals.add(userPrincipal);
-        Subject userSubject = new Subject(true, principals, new HashSet(), new HashSet());
-
-        userPrincipal = new UserPrincipalImpl("manager");
-        rolePrincipal = new RolePrincipalImpl("manager");
-        principals = new PrincipalsSet();
-        principals.add(userPrincipal);
-        principals.add(rolePrincipal);
-        Subject managerSubject = new Subject(true, principals, new HashSet(), new HashSet());
-
-        userPrincipal = new UserPrincipalImpl("guest");
-        principals = new PrincipalsSet();
-        principals.add(userPrincipal);
-        Subject guestSubject = new Subject(true, principals, new HashSet(), new HashSet());
-
-        // setup test as admin user
-        Exception setup = (Exception)Subject.doAsPrivileged(adminSubject, new PrivilegedAction()
-            {
-                public Object run()
-                {
-                    try
-                    {
-                        // create test documents and folders
-                        Folder folder = pageManager.newFolder("/");
-                        SecurityConstraints constraints = pageManager.newSecurityConstraints();
-                        constraints.setOwner("admin");
-                        List constraintsRefs = new ArrayList(1);
-                        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);
-                        assertNotNull(page.getRootFragment());
-                        assertNotNull(page.getRootFragment().getFragments());
-                        assertEquals(2, page.getRootFragment().getFragments().size());
-                        assertEquals("some-app::SomePortlet", ((Fragment)page.getRootFragment().getFragments().get(1)).getName());
-                        assertFalse("0".equals(((Fragment)page.getRootFragment().getFragments().get(1)).getId()));
-                        TestSecureDatabasePageManager.this.somePortletId = ((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;
-        }
-
-        // access test as admin user
-        Exception adminAccess = (Exception)Subject.doAsPrivileged(adminSubject, new PrivilegedAction()
-            {
-                public Object run()
-                {
-                    try
-                    {
-                        // test view access
-                        Folder folder = pageManager.getFolder("/");
-                        assertNotNull(folder.getPageSecurity());
-                        assertNotNull(folder.getPages());
-                        assertEquals(2, folder.getPages().size());
-                        PageSecurity pageSecurity = pageManager.getPageSecurity();
-                        Page page0 = pageManager.getPage("/default-page.psml");
-                        assertNotNull(page0.getRootFragment());
-                        assertNotNull(page0.getRootFragment().getFragments());
-                        assertEquals(2, page0.getRootFragment().getFragments().size());
-                        assertNotNull(page0.getFragmentById(TestSecureDatabasePageManager.this.somePortletId));
-                        assertNotNull(page0.getFragmentsByName("some-app::SomePortlet"));
-                        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)Subject.doAsPrivileged(userSubject, new PrivilegedAction()
-            {
-                public Object run()
-                {
-                    try
-                    {
-                        // test view access
-                        Folder folder = pageManager.getFolder("/");
-                        assertNotNull(folder.getPageSecurity());
-                        assertNotNull(folder.getPages());
-                        assertEquals(2, folder.getPages().size());
-                        PageSecurity pageSecurity = pageManager.getPageSecurity();
-                        Page page0 = pageManager.getPage("/default-page.psml");
-                        assertNotNull(page0.getRootFragment());
-                        assertNotNull(page0.getRootFragment().getFragments());
-                        assertEquals(2, page0.getRootFragment().getFragments().size());
-                        assertNotNull(page0.getFragmentById(TestSecureDatabasePageManager.this.somePortletId));
-                        assertNotNull(page0.getFragmentsByName("some-app::SomePortlet"));
-                        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);
-                            assertTrue("Folder / not editable for user", false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }
-                        try
-                        {
-                            pageManager.updatePageSecurity(pageSecurity);
-                            assertTrue("PageSecurity not editable for user", false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }
-                        try
-                        {
-                            pageManager.updatePage(page0);
-                            assertTrue("Page /default-page.psml not editable for user", false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }
-                        pageManager.updatePage(page1);
-                        try
-                        {
-                            pageManager.updateLink(link);
-                            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)Subject.doAsPrivileged(managerSubject, new PrivilegedAction()
-            {
-                public Object run()
-                {
-                    try
-                    {
-                        // test view access
-                        Folder folder = pageManager.getFolder("/");
-                        assertNotNull(folder.getPageSecurity());
-                        assertNotNull(folder.getPages());
-                        assertEquals(1, folder.getPages().size());
-                        PageSecurity pageSecurity = pageManager.getPageSecurity();
-                        Page page0 = pageManager.getPage("/default-page.psml");
-                        assertNotNull(page0.getRootFragment());
-                        assertNotNull(page0.getRootFragment().getFragments());
-                        assertEquals(1, page0.getRootFragment().getFragments().size());
-                        assertNull(page0.getFragmentById(TestSecureDatabasePageManager.this.somePortletId));
-                        assertNull(page0.getFragmentsByName("some-app::SomePortlet"));
-                        Link link = pageManager.getLink("/default.link");
-                        try
-                        {
-                            Page page1 = pageManager.getPage("/user-page.psml");
-                            assertTrue("Page /user-page.psml not viewable for manager", false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }                        
-                        // test edit access
-                        try
-                        {
-                            pageManager.updateFolder(folder);
-                            assertTrue("Folder / not editable for manager", false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }
-                        try
-                        {
-                            pageManager.updatePageSecurity(pageSecurity);
-                            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)Subject.doAsPrivileged(guestSubject, new PrivilegedAction()
-            {
-                public Object run()
-                {
-                    try
-                    {
-                        // test view access
-                        Folder folder = pageManager.getFolder("/");
-                        assertNotNull(folder.getPageSecurity());
-                        assertNotNull(folder.getPages());
-                        assertEquals(1, folder.getPages().size());
-                        PageSecurity pageSecurity = pageManager.getPageSecurity();
-                        Page page0 = pageManager.getPage("/default-page.psml");
-                        assertNotNull(page0.getRootFragment());
-                        assertNotNull(page0.getRootFragment().getFragments());
-                        assertEquals(1, page0.getRootFragment().getFragments().size());
-                        assertNull(page0.getFragmentById(TestSecureDatabasePageManager.this.somePortletId));
-                        assertNull(page0.getFragmentsByName("some-app::SomePortlet"));
-                        Link link = pageManager.getLink("/default.link");
-                        try
-                        {
-                            Page page1 = pageManager.getPage("/user-page.psml");
-                            assertTrue("Page /user-page.psml not viewable for guest", false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }                        
-                        // test edit access
-                        try
-                        {
-                            pageManager.updateFolder(folder);
-                            assertTrue("Folder / not editable for guest", false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }
-                        try
-                        {
-                            pageManager.updatePageSecurity(pageSecurity);
-                            assertTrue("PageSecurity not editable for guest", false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }
-                        try
-                        {
-                            pageManager.updatePage(page0);
-                            assertTrue("Page /default-page.psml not editable for guest",
false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }
-                        try
-                        {
-                            pageManager.updateLink(link);
-                            assertTrue("Page /default.link not editable for guest", false);
-                        }
-                        catch (SecurityException se)
-                        {
-                        }
-                        return null;
-                    }
-                    catch (Exception e)
-                    {
-                        return e;
-                    }
-                }
-            }, null);
-        if (guestAccess != null)
-        {
-            throw guestAccess;
-        }
-
-        // cleanup test as admin user
-        Exception cleanup = (Exception)Subject.doAsPrivileged(adminSubject, new PrivilegedAction()
-            {
-                public Object run()
-                {
-                    try
-                    {
-                        // cleanup by removing root folder
-                        try
-                        {
-                            Folder remove = pageManager.getFolder("/");
-                            assertEquals("/", remove.getPath());
-                            pageManager.removeFolder(remove);
-                        }
-                        catch (FolderNotFoundException e)
-                        {
-                            assertTrue("Folder / NOT FOUND", false);
-                        }
-
-                        return null;
-                    }
-                    catch (Exception e)
-                    {
-                        return e;
-                    }
-                }
-            }, null);
-        if (cleanup != null)
-        {
-            throw cleanup;
-        }
+        // utilize standard secure page manager test
+        Shared.testSecurePageManager(this, pageManager);
     }
 }

Added: portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecurePermissionsCastorXmlPageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecurePermissionsCastorXmlPageManager.java?rev=357085&view=auto
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecurePermissionsCastorXmlPageManager.java
(added)
+++ portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecurePermissionsCastorXmlPageManager.java
Thu Dec 15 15:12:55 2005
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.page;
+
+import java.security.Policy;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * TestSecurePermissionsCastorXmlPageManager
+ * 
+ * @author <a href="rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+public class TestSecurePermissionsCastorXmlPageManager extends TestSecureCastorXmlPageManager
+{
+    public TestSecurePermissionsCastorXmlPageManager( String name )
+    {
+        super(name);
+    }
+
+    public static void main( String args[] )
+    {
+        junit.awtui.TestRunner.main(new String[]{TestSecurePermissionsCastorXmlPageManager.class.getName()});
+    }
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        // configure custom policy for test
+        Policy.setPolicy(new PageManagerPermissionsPolicy(Policy.getPolicy()));
+        Policy.getPolicy().refresh();
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(TestSecurePermissionsCastorXmlPageManager.class);
+    }
+}

Propchange: portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecurePermissionsCastorXmlPageManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecurePermissionsDatabasePageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecurePermissionsDatabasePageManager.java?rev=357085&r1=357084&r2=357085&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecurePermissionsDatabasePageManager.java
(original)
+++ portals/jetspeed-2/branches/JETSPEED-BRANCH-2.0.1/components/page-manager/src/test/org/apache/jetspeed/page/TestSecurePermissionsDatabasePageManager.java
Thu Dec 15 15:12:55 2005
@@ -15,21 +15,7 @@
  */
 package org.apache.jetspeed.page;
 
-import java.security.AllPermission;
-import java.security.CodeSource;
-import java.security.Permission;
-import java.security.PermissionCollection;
-import java.security.Permissions;
 import java.security.Policy;
-import java.security.Principal;
-import java.security.ProtectionDomain;
-
-import org.apache.jetspeed.security.FolderPermission;
-import org.apache.jetspeed.security.FragmentPermission;
-import org.apache.jetspeed.security.GroupPrincipal;
-import org.apache.jetspeed.security.PagePermission;
-import org.apache.jetspeed.security.RolePrincipal;
-import org.apache.jetspeed.security.UserPrincipal;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -43,123 +29,6 @@
  */
 public class TestSecurePermissionsDatabasePageManager extends TestSecureDatabasePageManager
 {
-    public static class PageManagerPermissionsPolicy extends Policy
-    {
-        private Policy defaultPolicy;
-
-        public PageManagerPermissionsPolicy(Policy defaultPolicy)
-        {
-            this.defaultPolicy = defaultPolicy;
-        }
-
-        public boolean implies(ProtectionDomain domain, Permission permission)
-        {
-            // classify policy query for local test case; this implementation
-            // is not optimized: multiple protection domains exist on the
-            // call stack, so this method will be invoked 2-3 times for each
-            // access check with the identical principals and permission
-            Principal[] principals = domain.getPrincipals();
-            if ((principals != null) && (principals.length > 0) &&
-                ((permission instanceof FolderPermission) ||
-                 (permission instanceof PagePermission) ||
-                 (permission instanceof FragmentPermission)))
-            {
-                // check permission using principals if available
-                Permissions permissions = new Permissions();
-                for (int i = 0; (i < principals.length); i++)
-                {
-                    if (principals[i] instanceof UserPrincipal)
-                    {
-                        // get permissions for users
-                        String user = principals[i].getName();
-                        if (user.equals("admin"))
-                        {
-                            // owner permissions
-                            permissions.add(new FolderPermission("/", "view, edit"));
-                            permissions.add(new PagePermission("/default-page.psml", "view,
edit"));
-                        }
-                        else if (user.equals("user"))
-                        {
-                            // owner permissions
-                            permissions.add(new FragmentPermission("/default-page.psml/some-app::SomePortlet",
"view, edit"));
-                            
-                            // granted permissions
-                            permissions.add(new PagePermission("/user-page.psml", "view,
edit"));
-                            permissions.add(new FragmentPermission("/user-page.psml/*", "view"));
-                        }
-                        
-                        // public view permissions
-                        permissions.add(new FolderPermission("/", "view"));
-                        permissions.add(new PagePermission("/default-page.psml", "view"));
-                        permissions.add(new PagePermission("/page.security", "view"));
-                        permissions.add(new FragmentPermission("security::*", "view"));
-                    }
-                    else if (principals[i] instanceof RolePrincipal)
-                    {
-                        // get permissions for roles
-                        String role = principals[i].getName();
-                        if (role.equals("admin"))
-                        {
-                            // global permissions
-                            permissions.add(new FolderPermission("<<ALL FILES>>",
"view, edit"));
-                            permissions.add(new FragmentPermission("<<ALL FRAGMENTS>>",
"view, edit"));
-                        }
-                        else if (role.equals("manager"))
-                        {
-                            // granted permissions
-                            permissions.add(new PagePermission("/default-page.psml", "edit"));
-                            permissions.add(new PagePermission("/default.link", "edit"));
-                        }
-                    }
-                }
-                
-                // check permission
-                if (permissions.implies(permission))
-                {
-                    return true;
-                }
-            }
-
-            // check default permissions
-            if (defaultPolicy != null)
-            {
-                return defaultPolicy.implies(domain, permission);
-            }
-            return false;
-        }
-
-        public PermissionCollection getPermissions(ProtectionDomain domain)
-        {
-            // return default permissions only since
-            // domain and permsission not available
-            if (defaultPolicy != null)
-            {
-                return defaultPolicy.getPermissions(domain);
-            }
-            return new Permissions();
-        }
-
-        public PermissionCollection getPermissions(CodeSource codesource)
-        {
-            // return default permissions only since
-            // domain and permsission not available
-            if (defaultPolicy != null)
-            {
-                return defaultPolicy.getPermissions(codesource);
-            }
-            return new Permissions();
-        }
-
-        public void refresh()
-        {
-            // propagate refresh
-            if (defaultPolicy != null)
-            {
-                defaultPolicy.refresh();
-            }
-        }
-    }
-
     public static void main(String args[])
     {
         junit.awtui.TestRunner.main(new String[]



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message