source: trunk/src/gcc/libjava/java/security/ProtectionDomain.java@ 154

Last change on this file since 154 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.7 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 ([email protected])
53 */
54public class ProtectionDomain
55{
56 private static final String linesep = System.getProperty("line.separator");
57
58 /**
59 * This is the <code>CodeSource</code> for this protection domain
60 */
61 private CodeSource code_source;
62
63 /**
64 * This is the set of permissions granted to this domain
65 */
66 private PermissionCollection perms;
67
68 /**
69 * This method initializes a new instance of <code>ProtectionDomain</code>
70 * representing the specified <code>CodeSource</code> and permission set.
71 * No permissions may be added to the <code>PermissionCollection</code>
72 * and this contructor will call the <code>setReadOnly</code> method on
73 * the specified permission set.
74 *
75 * @param code_source The <code>CodeSource</code> for this domain
76 * @param perms The permission set for this domain
77 *
78 * @see java.security.PermissionCollection#setReadOnly()
79 */
80 public ProtectionDomain(CodeSource code_source, PermissionCollection perms)
81 {
82 this.code_source = code_source;
83 this.perms = perms;
84 if (perms != null)
85 perms.setReadOnly();
86 }
87
88 /**
89 * This method returns the <code>CodeSource</code> for this domain.
90 *
91 * @return This domain's <code>CodeSource</code>.
92 */
93 public final CodeSource getCodeSource()
94 {
95 return code_source;
96 }
97
98 /**
99 * This method returns the set of permissions granted to this domain.
100 *
101 * @return The permission set for this domain
102 */
103 public final PermissionCollection getPermissions()
104 {
105 return perms;
106 }
107
108 /**
109 * This method tests whether or not the specified <code>Permission</code> is
110 * implied by the set of permissions granted to this domain.
111 *
112 * @param perm The <code>Permission</code> to test.
113 *
114 * @return <code>true</code> if the specified <code>Permission</code> is implied for this domain, <code>false</code> otherwise.
115 */
116 public boolean implies(Permission perm)
117 {
118 PermissionCollection pc = getPermissions();
119 if (pc == null)
120 return (false);
121
122 return (pc.implies(perm));
123 }
124
125 /**
126 * This method returns a <code>String</code> representation of this
127 * object. It will print the <code>CodeSource</code> and
128 * permission set associated with this domain.
129 *
130 * @return A <code>String</code> representation of this object.
131 */
132 public String toString()
133 {
134 StringBuffer sb = new StringBuffer("");
135
136 sb.append(super.toString() + " (" + linesep);
137 sb.append(code_source.toString());
138 sb.append(perms.toString());
139 sb.append(")" + linesep);
140
141 return sb.toString();
142 }
143}
Note: See TracBrowser for help on using the repository browser.