portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r702323 - in /portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src: main/java/org/apache/jetspeed/serializer/ test/java/org/apache/jetspeed/page/
Date Tue, 07 Oct 2008 01:55:13 GMT
Author: ate
Date: Mon Oct  6 18:55:12 2008
New Revision: 702323

URL: http://svn.apache.org/viewvc?rev=702323&view=rev
Log:
Fixing page-manager tests

Modified:
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/PageManagerTestShared.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCreateUserHomePagesFromRoles.java

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java?rev=702323&r1=702322&r2=702323&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java
Mon Oct  6 18:55:12 2008
@@ -100,8 +100,8 @@
             if (adminUser == null)
                 throw new SerializerException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER,
"admin"));
             
-            for (JSPrincipal user : snapshot.getUsers())
-            {
+//            for (JSPrincipal user : snapshot.getUsers())
+//            {
                 // TODO: should have a specific user JSPrincipal class?
 //                String folderTemplate = user.getUserTemplate();
 //                String ssubsite = user.getSubsite();
@@ -123,7 +123,7 @@
 //                    this.createUserTemplate(folderTemplate, userTemplate, subsite, this.pageManager,
user.getName(), adminUser);
 //                }
 
-            }
+//            }
         }
     }
 

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/PageManagerTestShared.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/PageManagerTestShared.java?rev=702323&r1=702322&r2=702323&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/PageManagerTestShared.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/PageManagerTestShared.java
Mon Oct  6 18:55:12 2008
@@ -27,6 +27,7 @@
 import java.security.PrivilegedAction;
 import java.security.ProtectionDomain;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -39,6 +40,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.cache.file.FileCache;
 import org.apache.jetspeed.idgenerator.IdGenerator;
 import org.apache.jetspeed.idgenerator.JetspeedIdGenerator;
@@ -63,13 +65,19 @@
 import org.apache.jetspeed.page.document.psml.FileSystemFolderHandler;
 import org.apache.jetspeed.page.psml.CastorXmlPageManager;
 import org.apache.jetspeed.security.JSSubject;
+import org.apache.jetspeed.security.JetspeedPermission;
+import org.apache.jetspeed.security.JetspeedPrincipal;
+import org.apache.jetspeed.security.JetspeedPrincipalType;
+import org.apache.jetspeed.security.PermissionFactory;
 import org.apache.jetspeed.security.PrincipalsSet;
 import org.apache.jetspeed.security.Role;
+import org.apache.jetspeed.security.SecurityAttributeType;
+import org.apache.jetspeed.security.SecurityAttributeTypes;
 import org.apache.jetspeed.security.User;
-import org.apache.jetspeed.security.impl.RoleImpl;
-import org.apache.jetspeed.security.impl.UserImpl;
+import org.apache.jetspeed.security.impl.TransientJetspeedPrincipal;
 import org.apache.jetspeed.security.spi.impl.FolderPermission;
 import org.apache.jetspeed.security.spi.impl.FragmentPermission;
+import org.apache.jetspeed.security.spi.impl.JetspeedPermissionFactory;
 import org.apache.jetspeed.security.spi.impl.PagePermission;
 
 /**
@@ -214,21 +222,21 @@
             
             // setup test subjects
             Set principals = new PrincipalsSet();
-            principals.add(new UserImpl("admin"));
-            principals.add(new RoleImpl("admin"));
+            principals.add(new TestUser("admin"));
+            principals.add(new TestRole("admin"));
             Subject adminSubject = new Subject(true, principals, new HashSet(), new HashSet());
             
             principals = new PrincipalsSet();
-            principals.add(new UserImpl("user"));
+            principals.add(new TestUser("user"));
             Subject userSubject = new Subject(true, principals, new HashSet(), new HashSet());
             
             principals = new PrincipalsSet();
-            principals.add(new UserImpl("manager"));
-            principals.add(new RoleImpl("manager"));
+            principals.add(new TestUser("manager"));
+            principals.add(new TestRole("manager"));
             Subject managerSubject = new Subject(true, principals, new HashSet(), new HashSet());
 
             principals = new PrincipalsSet();
-            principals.add(new UserImpl("guest"));
+            principals.add(new TestUser("guest"));
             Subject guestSubject = new Subject(true, principals, new HashSet(), new HashSet());
 
             // setup test as admin user
@@ -649,6 +657,16 @@
     static class PageManagerPermissionsPolicy extends Policy
     {
         private Policy defaultPolicy;
+        private static PermissionFactory pf = new TestPermissionFactory();
+        static 
+        {
+            org.apache.jetspeed.om.page.psml.AbstractBaseElement.setPermissionsFactory(pf);
+            org.apache.jetspeed.om.page.impl.BaseElementImpl.setPermissionsFactory(pf);
+            org.apache.jetspeed.om.folder.impl.FolderImpl.setPermissionsFactory(pf);
+            org.apache.jetspeed.om.folder.psml.FolderImpl.setPermissionsFactory(pf);
+            org.apache.jetspeed.om.page.impl.FragmentImpl.setPermissionsFactory(pf);
+            org.apache.jetspeed.om.page.psml.FragmentImpl.setPermissionsFactory(pf);
+        }
 
         public PageManagerPermissionsPolicy(Policy defaultPolicy)
         {
@@ -661,11 +679,10 @@
             // 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
+            JetspeedPermission j2p = permission instanceof JetspeedPermission ? (JetspeedPermission)permission
: null;
+            boolean testPermission = j2p != null && (j2p.getType().equals("folder")||j2p.getType().equals("page")||j2p.getType().equals("fragment"));
             Principal[] principals = domain.getPrincipals();
-            if ((principals != null) && (principals.length > 0) &&
-                ((permission instanceof FolderPermission) ||
-                 (permission instanceof PagePermission) ||
-                 (permission instanceof FragmentPermission)))
+            if ((principals != null) && (principals.length > 0) && (testPermission))
             {
                 // check permission using principals if available
                 Permissions permissions = new Permissions();
@@ -678,24 +695,24 @@
                         if (user.equals("admin"))
                         {
                             // owner permissions                            
-                            permissions.add(new FolderPermission.Factory().newPermission("/",
"view, edit"));
-                            permissions.add(new PagePermission.Factory().newPermission("/default-page.psml",
"view, edit"));
+                            permissions.add((Permission)pf.newPermission("folder", "/", "view,
edit"));
+                            permissions.add((Permission)pf.newPermission("page", "/default-page.psml",
"view, edit"));
                         }
                         else if (user.equals("user"))
                         {
                             // owner permissions
-                            permissions.add(new FragmentPermission.Factory().newPermission("/default-page.psml/some-app::SomePortlet",
"view, edit"));
+                            permissions.add((Permission)pf.newPermission("fragment", "/default-page.psml/some-app::SomePortlet",
"view, edit"));
                             
                             // granted permissions
-                            permissions.add(new PagePermission.Factory().newPermission("/user-page.psml",
"view, edit"));
-                            permissions.add(new FragmentPermission.Factory().newPermission("/user-page.psml/*",
"view"));
+                            permissions.add((Permission)pf.newPermission("page", "/user-page.psml",
"view, edit"));
+                            permissions.add((Permission)pf.newPermission("fragment", "/user-page.psml/*",
"view"));
                         }
                         
                         // public view permissions
-                        permissions.add(new FolderPermission.Factory().newPermission("/",
"view"));
-                        permissions.add(new PagePermission.Factory().newPermission("/default-page.psml",
"view"));
-                        permissions.add(new PagePermission.Factory().newPermission("/page.security",
"view"));
-                        permissions.add(new FragmentPermission.Factory().newPermission("security::*",
"view"));
+                        permissions.add((Permission)pf.newPermission("folder", "/", "view"));
+                        permissions.add((Permission)pf.newPermission("page", "/default-page.psml",
"view"));
+                        permissions.add((Permission)pf.newPermission("page", "/page.security",
"view"));
+                        permissions.add((Permission)pf.newPermission("fragment", "security::*",
"view"));
                     }
                     else if (principals[i] instanceof Role)
                     {
@@ -704,14 +721,14 @@
                         if (role.equals("admin"))
                         {
                             // global permissions
-                            permissions.add(new FolderPermission.Factory().newPermission("<<ALL
FILES>>", "view, edit"));
-                            permissions.add(new FragmentPermission.Factory().newPermission("<<ALL
FRAGMENTS>>", "view, edit"));
+                            permissions.add((Permission)pf.newPermission("folder", "<<ALL
FILES>>", "view, edit"));
+                            permissions.add((Permission)pf.newPermission("fragment", "<<ALL
FRAGMENTS>>", "view, edit"));
                         }
                         else if (role.equals("manager"))
                         {
                             // granted permissions
-                            permissions.add(new PagePermission.Factory().newPermission("/default-page.psml",
"edit"));
-                            permissions.add(new PagePermission.Factory().newPermission("/default.link",
"edit"));
+                            permissions.add((Permission)pf.newPermission("page", "/default-page.psml",
"edit"));
+                            permissions.add((Permission)pf.newPermission("page", "/default.link",
"edit"));
                         }
                     }
                 }
@@ -762,4 +779,115 @@
             }
         }
     }
+    
+    static class AbstractTestPrincipal extends TransientJetspeedPrincipal
+    {
+        private static final SecurityAttributeTypes attributeTypes = new SecurityAttributeTypes()
+        {
+
+            public Map<String, SecurityAttributeType> getAttributeTypeMap()
+            {
+                return Collections.emptyMap();
+            }
+
+            public Map<String, SecurityAttributeType> getAttributeTypeMap(String category)
+            {
+                return Collections.emptyMap();
+            }
+
+            public boolean isExtendable()
+            {
+                return false;
+            }
+
+            public boolean isReadOnly()
+            {
+                return true;
+            }
+        };
+        
+        private JetspeedPrincipalType type;
+        
+        private static final long serialVersionUID = 1L;
+        
+
+        public AbstractTestPrincipal(final String type, String name)
+        {
+            super(type, name);
+            this.type = new JetspeedPrincipalType()
+            {               
+                public SecurityAttributeTypes getAttributeTypes()
+                {
+                    return attributeTypes;
+                }
+
+                public String getClassName()
+                {
+                    return null;
+                }
+
+                public String getName()
+                {
+                    return type;
+                }
+
+                public Class<JetspeedPrincipal> getPrincipalClass()
+                {
+                    return null;
+                }
+            };
+        }
+
+        @Override
+        public synchronized JetspeedPrincipalType getType()
+        {
+            return type;
+        }
+    }
+    
+    static class TestUser extends AbstractTestPrincipal implements User
+    {
+        private static final long serialVersionUID = 1L;
+
+        public TestUser(String name)
+        {
+            super(JetspeedPrincipalType.USER, name);
+        }
+    }
+
+    static class TestRole extends AbstractTestPrincipal implements Role
+    {
+        private static final long serialVersionUID = 1L;
+
+        public TestRole(String name)
+        {
+            super(JetspeedPrincipalType.ROLE, name);
+        }
+    }
+    
+    static class TestPermissionFactory implements PermissionFactory
+    {
+        private static Map<String, JetspeedPermissionFactory> factories = new HashMap<String,
JetspeedPermissionFactory>();
+        static
+        {
+            factories.put("folder", new FolderPermission.Factory());
+            factories.put("page", new PagePermission.Factory());
+            factories.put("fragment", new FragmentPermission.Factory());
+        }
+
+        public JetspeedPermission newPermission(String type, String name, String actions)
+        {
+            return factories.get(type).newPermission(name, actions);
+        }
+
+        public JetspeedPermission newPermission(String type, String name, int mask)
+        {
+            return factories.get(type).newPermission(name, mask);
+        }
+
+        public int parseActions(String actions)
+        {
+            return JetspeedActions.getContainerActionsMask(actions);
+        }
+    }
 }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCreateUserHomePagesFromRoles.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCreateUserHomePagesFromRoles.java?rev=702323&r1=702322&r2=702323&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCreateUserHomePagesFromRoles.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCreateUserHomePagesFromRoles.java
Mon Oct  6 18:55:12 2008
@@ -16,7 +16,6 @@
  */
 package org.apache.jetspeed.page;
 
-import java.security.Principal;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -27,8 +26,6 @@
 
 import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.page.psml.CastorXmlPageManager;
-import org.apache.jetspeed.security.impl.RoleImpl;
-import org.apache.jetspeed.security.impl.UserImpl;
 import org.apache.jetspeed.test.JetspeedTestCase;
 
 /**
@@ -109,12 +106,12 @@
         Set principals = new HashSet();
         
         // create the role principals
-        principals.add(new RoleImpl("role1"));
-        principals.add(new RoleImpl("role2"));
-        principals.add(new RoleImpl("role3"));
+        principals.add(new TestRole("role1"));
+        principals.add(new TestRole("role2"));
+        principals.add(new TestRole("role3"));
         
         // create the user principal
-        principals.add(new UserImpl("david"));
+        principals.add(new TestUser("david"));
         
         // create the subject
         Subject subject = new Subject(true, principals, new HashSet(), new HashSet());



---------------------------------------------------------------------
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