KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jacc > test > portal > ComponentPermissionCollection


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jacc.test.portal;
23
24 import org.jboss.logging.Logger;
25
26 import java.io.Serializable JavaDoc;
27 import java.security.Permission JavaDoc;
28 import java.security.PermissionCollection JavaDoc;
29 import java.util.Enumeration JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 /**
34  * A permission collection to cache portal object permissions.
35  * <p>The <code>PermissionCollection</code> is used by the JACC Policy to cache permissions for a given PolicyContext.</p>
36  *
37  * @author <a HREF="mailto:mholzner@novell.com">Martin Holzner</a>
38  * @version $Revision: 40338 $
39  */

40 public final class ComponentPermissionCollection extends PermissionCollection JavaDoc implements Serializable JavaDoc
41 {
42    private static Logger log = Logger.getLogger(ComponentPermissionCollection.class);
43    private final Vector JavaDoc permissions;
44    private boolean trace;
45
46    public ComponentPermissionCollection()
47    {
48       trace = log.isTraceEnabled();
49       if (trace)
50       {
51          log.trace("creating portal object permission collection...");
52       }
53
54       permissions = new Vector JavaDoc();
55    }
56
57    public void add(Permission JavaDoc permission)
58    {
59       if (trace)
60       {
61          log.trace("adding " + permission);
62       }
63
64       if (!(permission instanceof ComponentPermission))
65       {
66          throw new IllegalArgumentException JavaDoc();
67       }
68       permissions.add(permission);
69    }
70
71    public boolean implies(Permission JavaDoc permission)
72    {
73       if (trace)
74       {
75          log.trace("implies ? " + permission);
76       }
77       if (!(permission instanceof ComponentPermission))
78       {
79          return false;
80       }
81
82       Iterator JavaDoc permIterator = permissions.iterator();
83       while (permIterator.hasNext())
84       {
85          ComponentPermission p = (ComponentPermission)permIterator.next();
86          if (p.implies(permission))
87          {
88             return true;
89          }
90       }
91
92       return false;
93    }
94
95    public Enumeration JavaDoc elements()
96    {
97       return permissions.elements();
98    }
99 }
100
Popular Tags