1 9 package org.jboss.portal.test.core.security; 10 11 import java.util.Iterator ; 12 import java.util.Map ; 13 14 import org.jboss.portal.core.security.Item; 15 import org.jboss.portal.core.security.Model; 16 import org.jboss.portal.core.security.ModelAuthorizationRealm; 17 import org.jboss.portal.core.security.Scheme; 18 import org.jboss.portal.core.security.SchemeStore; 19 20 import junit.framework.TestCase; 21 22 26 public class ModelAuthorizationRealmTestCase extends TestCase 27 { 28 29 public ModelAuthorizationRealmTestCase(String name) 30 { 31 super(name); 32 } 33 34 private Model model; 35 private Scheme scheme; 36 private ModelAuthorizationRealm realm; 37 private SchemeStore store; 38 39 public void setUp() 40 { 41 model = new Model() 42 { 43 public Item getItem(String [] path) 44 { 45 throw new UnsupportedOperationException ("should not be used in this test"); 46 } 47 public Iterator getChildren(String [] path) 48 { 49 throw new UnsupportedOperationException ("should not be used in this test"); 50 } 51 public Map getPermissionDescriptions() 52 { 53 throw new UnsupportedOperationException (""); 54 } 55 public boolean implies(String sourcePermission, String targetPermission) throws IllegalArgumentException 56 { 57 if ("p1".equals(sourcePermission)) 58 { 59 return "p1".equals(targetPermission) | "p2".equals(targetPermission); 60 } 61 if ("p2".equals(sourcePermission)) 62 { 63 return "p2".equals(targetPermission); 64 } 65 return false; 66 } 67 public Scheme getDefaultScheme() 68 { 69 throw new UnsupportedOperationException ("should not be used in this test"); 70 } 71 }; 72 scheme = new Scheme(); 73 scheme.add(new String [0], "Admins", "p1"); 74 scheme.add(new String []{"A"}, "Users", "p2"); 75 store = new SchemeStore() 76 { 77 public Scheme getScheme(String id) 78 { 79 return null; 80 } 81 public void removeScheme(String id) 82 { 83 throw new UnsupportedOperationException (); 84 } 85 public Scheme createScheme(String id) 86 { 87 throw new UnsupportedOperationException (); 88 } 89 public void saveScheme(String id, Scheme scheme) 90 { 91 throw new UnsupportedOperationException (); 92 } 93 }; 94 realm = new ModelAuthorizationRealm(model, store); 95 } 96 97 public void testBasic() 98 { 99 assertTrue(realm.hasPermission(null, "Admins", new String []{},"p1")); 100 assertTrue(realm.hasPermission(null, "Admins", new String []{"A"},"p2")); 101 assertTrue(realm.hasPermission(null, "Users", new String []{"A"},"p2")); 102 assertFalse(realm.hasPermission(null, "Users", new String []{},"p1")); 103 } 104 105 } 106 | Popular Tags |