source: trunk/gcc/libjava/java/security/ProtectionDomain.java

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.8 KB
Line 
1/* ProtectionDomain.java -- A security domain
2 Copyright (C) 1998 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package java.security;
39
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>.
49 *
50 * @version 0.0
51 *
52 * @author Aaron M. Renn (arenn@urbanophile.com)
53 */
54public class ProtectionDomain
55{
56 /**
57 * This is the <code>CodeSource</code> for this protection domain
58 */
59 private CodeSource code_source;
60
61 /**
62 * This is the set of permissions granted to this domain
63 */
64 private PermissionCollection perms;
65
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.
72 *
73 * @param code_source The <code>CodeSource</code> for this domain
74 * @param perms The permission set for this domain
75 *
76 * @see java.security.PermissionCollection#setReadOnly()
77 */
78 public ProtectionDomain(CodeSource code_source, PermissionCollection perms)
79 {
80 this.code_source = code_source;
81 this.perms = perms;
82 if (perms != null)
83 perms.setReadOnly();
84 }
85
86 /**
87 * This method returns the <code>CodeSource</code> for this domain.
88 *
89 * @return This domain's <code>CodeSource</code>.
90 */
91 public final CodeSource getCodeSource()
92 {
93 return code_source;
94 }
95
96 /**
97 * This method returns the set of permissions granted to this domain.
98 *
99 * @return The permission set for this domain
100 */
101 public final PermissionCollection getPermissions()
102 {
103 return perms;
104 }
105
106 /**
107 * This method tests whether or not the specified <code>Permission</code> is
108 * implied by the set of permissions granted to this domain.
109 *
110 * @param perm The <code>Permission</code> to test.
111 *
112 * @return <code>true</code> if the specified <code>Permission</code> is implied for this domain, <code>false</code> otherwise.
113 */
114 public boolean implies(Permission perm)
115 {
116 PermissionCollection pc = getPermissions();
117 if (pc == null)
118 return (false);
119
120 return (pc.implies(perm));
121 }
122
123 /**
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.
127 *
128 * @return A <code>String</code> representation of this object.
129 */
130 public String toString()
131 {
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);
141
142 return sb.toString();
143 }
144}
Note: See TracBrowser for help on using the repository browser.