FSF GCC merge 02/23/03
[official-gcc.git] / libjava / java / security / ProtectionDomain.java
blobe8ead466565b80375636dedd5664db32b7da92f2
1 /* ProtectionDomain.java -- A security domain
2 Copyright (C) 1998 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.security;
40 /**
41 * This class represents a group of classes, along with the permissions
42 * they are granted. The classes are identified by a <code>CodeSource</code>.
43 * Thus, any class loaded from the specified <code>CodeSource</code> is
44 * treated as part of this domain. The set of permissions is represented
45 * by a <code>PermissionCollection</code>.
46 * <p>
47 * Every class in the system will belong to one and only one
48 * <code>ProtectionDomain</code>.
50 * @version 0.0
52 * @author Aaron M. Renn (arenn@urbanophile.com)
54 public class ProtectionDomain
56 /**
57 * This is the <code>CodeSource</code> for this protection domain
59 private CodeSource code_source;
61 /**
62 * This is the set of permissions granted to this domain
64 private PermissionCollection perms;
66 /**
67 * This method initializes a new instance of <code>ProtectionDomain</code>
68 * representing the specified <code>CodeSource</code> and permission set.
69 * No permissions may be added to the <code>PermissionCollection</code>
70 * and this contructor will call the <code>setReadOnly</code> method on
71 * the specified permission set.
73 * @param code_source The <code>CodeSource</code> for this domain
74 * @param perms The permission set for this domain
76 * @see java.security.PermissionCollection#setReadOnly()
78 public ProtectionDomain(CodeSource code_source, PermissionCollection perms)
80 this.code_source = code_source;
81 this.perms = perms;
82 if (perms != null)
83 perms.setReadOnly();
86 /**
87 * This method returns the <code>CodeSource</code> for this domain.
89 * @return This domain's <code>CodeSource</code>.
91 public final CodeSource getCodeSource()
93 return code_source;
96 /**
97 * This method returns the set of permissions granted to this domain.
99 * @return The permission set for this domain
101 public final PermissionCollection getPermissions()
103 return perms;
107 * This method tests whether or not the specified <code>Permission</code> is
108 * implied by the set of permissions granted to this domain.
110 * @param perm The <code>Permission</code> to test.
112 * @return <code>true</code> if the specified <code>Permission</code> is implied for this domain, <code>false</code> otherwise.
114 public boolean implies(Permission perm)
116 PermissionCollection pc = getPermissions();
117 if (pc == null)
118 return (false);
120 return (pc.implies(perm));
124 * This method returns a <code>String</code> representation of this
125 * object. It will print the <code>CodeSource</code> and
126 * permission set associated with this domain.
128 * @return A <code>String</code> representation of this object.
130 public String toString()
132 String linesep = System.getProperty("line.separator");
133 StringBuffer sb = new StringBuffer("");
134 sb.append("ProtectionDomain (" + linesep);
135 if (code_source == null)
136 sb.append("CodeSource:null" + linesep);
137 else
138 sb.append(code_source + linesep);
139 sb.append(perms);
140 sb.append(linesep + ")" + linesep);
142 return sb.toString();