KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > test > core > security > ModelAuthorizationRealmTestCase


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.test.core.security;
10
11 import java.util.Iterator JavaDoc;
12 import java.util.Map JavaDoc;
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 /**
23  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
24  * @version $Revision: 1.4 $
25  */

26 public class ModelAuthorizationRealmTestCase extends TestCase
27 {
28
29    public ModelAuthorizationRealmTestCase(String JavaDoc 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 JavaDoc[] path)
44          {
45             throw new UnsupportedOperationException JavaDoc("should not be used in this test");
46          }
47          public Iterator JavaDoc getChildren(String JavaDoc[] path)
48          {
49             throw new UnsupportedOperationException JavaDoc("should not be used in this test");
50          }
51          public Map JavaDoc getPermissionDescriptions()
52          {
53             throw new UnsupportedOperationException JavaDoc("");
54          }
55          public boolean implies(String JavaDoc sourcePermission, String JavaDoc targetPermission) throws IllegalArgumentException JavaDoc
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 JavaDoc("should not be used in this test");
70          }
71       };
72       scheme = new Scheme();
73       scheme.add(new String JavaDoc[0], "Admins", "p1");
74       scheme.add(new String JavaDoc[]{"A"}, "Users", "p2");
75       store = new SchemeStore()
76       {
77          public Scheme getScheme(String JavaDoc id)
78          {
79             return null;
80          }
81          public void removeScheme(String JavaDoc id)
82          {
83             throw new UnsupportedOperationException JavaDoc();
84          }
85          public Scheme createScheme(String JavaDoc id)
86          {
87             throw new UnsupportedOperationException JavaDoc();
88          }
89          public void saveScheme(String JavaDoc id, Scheme scheme)
90          {
91             throw new UnsupportedOperationException JavaDoc();
92          }
93       };
94       realm = new ModelAuthorizationRealm(model, store);
95    }
96    
97    public void testBasic()
98    {
99       assertTrue(realm.hasPermission(null, "Admins", new String JavaDoc[]{},"p1"));
100       assertTrue(realm.hasPermission(null, "Admins", new String JavaDoc[]{"A"},"p2"));
101       assertTrue(realm.hasPermission(null, "Users", new String JavaDoc[]{"A"},"p2"));
102       assertFalse(realm.hasPermission(null, "Users", new String JavaDoc[]{},"p1"));
103    }
104    
105 }
106
Popular Tags