author | darcy |
Wed, 09 Oct 2019 09:57:41 -0700 | |
changeset 58519 | 6e017b301287 |
parent 58242 | 94bb65cb37d3 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.security; |
|
27 |
||
28 |
/** |
|
29 |
* A GuardedObject is an object that is used to protect access to |
|
30 |
* another object. |
|
31 |
* |
|
32 |
* <p>A GuardedObject encapsulates a target object and a Guard object, |
|
33 |
* such that access to the target object is possible |
|
34 |
* only if the Guard object allows it. |
|
35 |
* Once an object is encapsulated by a GuardedObject, |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
5506
diff
changeset
|
36 |
* access to that object is controlled by the {@code getObject} |
2 | 37 |
* method, which invokes the |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
5506
diff
changeset
|
38 |
* {@code checkGuard} method on the Guard object that is |
2 | 39 |
* guarding access. If access is not allowed, |
40 |
* an exception is thrown. |
|
41 |
* |
|
42 |
* @see Guard |
|
43 |
* @see Permission |
|
44 |
* |
|
45 |
* @author Roland Schemers |
|
46 |
* @author Li Gong |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
25859
diff
changeset
|
47 |
* @since 1.2 |
2 | 48 |
*/ |
49 |
||
50 |
public class GuardedObject implements java.io.Serializable { |
|
51 |
||
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
52 |
@java.io.Serial |
2 | 53 |
private static final long serialVersionUID = -5240450096227834308L; |
54 |
||
58519
6e017b301287
8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents:
58242
diff
changeset
|
55 |
@SuppressWarnings("serial") // Not statically typed as Serializable |
2 | 56 |
private Object object; // the object we are guarding |
58519
6e017b301287
8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents:
58242
diff
changeset
|
57 |
@SuppressWarnings("serial") // Not statically typed as Serializable |
2 | 58 |
private Guard guard; // the guard |
59 |
||
60 |
/** |
|
61 |
* Constructs a GuardedObject using the specified object and guard. |
|
62 |
* If the Guard object is null, then no restrictions will |
|
63 |
* be placed on who can access the object. |
|
64 |
* |
|
65 |
* @param object the object to be guarded. |
|
66 |
* |
|
67 |
* @param guard the Guard object that guards access to the object. |
|
68 |
*/ |
|
69 |
||
70 |
public GuardedObject(Object object, Guard guard) |
|
71 |
{ |
|
72 |
this.guard = guard; |
|
73 |
this.object = object; |
|
74 |
} |
|
75 |
||
76 |
/** |
|
77 |
* Retrieves the guarded object, or throws an exception if access |
|
78 |
* to the guarded object is denied by the guard. |
|
79 |
* |
|
80 |
* @return the guarded object. |
|
81 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57950
diff
changeset
|
82 |
* @throws SecurityException if access to the guarded object is |
2 | 83 |
* denied. |
84 |
*/ |
|
85 |
public Object getObject() |
|
86 |
throws SecurityException |
|
87 |
{ |
|
88 |
if (guard != null) |
|
89 |
guard.checkGuard(object); |
|
90 |
||
91 |
return object; |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* Writes this object out to a stream (i.e., serializes it). |
|
96 |
* We check the guard if there is one. |
|
97 |
*/ |
|
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
98 |
@java.io.Serial |
2 | 99 |
private void writeObject(java.io.ObjectOutputStream oos) |
100 |
throws java.io.IOException |
|
101 |
{ |
|
102 |
if (guard != null) |
|
103 |
guard.checkGuard(object); |
|
104 |
||
105 |
oos.defaultWriteObject(); |
|
106 |
} |
|
107 |
} |