author | darcy |
Wed, 23 Oct 2019 13:01:40 -0700 | |
changeset 58766 | 54ffb15c4839 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20814
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, 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 javax.management; |
|
27 |
||
28 |
import java.security.BasicPermission; |
|
20814 | 29 |
import java.io.IOException; |
30 |
import java.io.InvalidObjectException; |
|
31 |
import java.io.ObjectInputStream; |
|
2 | 32 |
|
33 |
/** |
|
34 |
* This permission represents "trust" in a signer or codebase. |
|
35 |
* <p> |
|
36 |
* MBeanTrustPermission contains a target name but no actions list. |
|
37 |
* A single target name, "register", is defined for this permission. |
|
38 |
* The target "*" is also allowed, permitting "register" and any future |
|
39 |
* targets that may be defined. |
|
40 |
* Only the null value or the empty string are allowed for the action |
|
41 |
* to allow the policy object to create the permissions specified in |
|
42 |
* the policy file. |
|
43 |
* <p> |
|
44 |
* If a signer, or codesource is granted this permission, then it is |
|
45 |
* considered a trusted source for MBeans. Only MBeans from trusted |
|
46 |
* sources may be registered in the MBeanServer. |
|
47 |
* |
|
48 |
* @since 1.5 |
|
49 |
*/ |
|
50 |
public class MBeanTrustPermission extends BasicPermission { |
|
51 |
||
52 |
private static final long serialVersionUID = -2952178077029018140L; |
|
53 |
||
54 |
/** <p>Create a new MBeanTrustPermission with the given name.</p> |
|
55 |
<p>This constructor is equivalent to |
|
56 |
<code>MBeanTrustPermission(name,null)</code>.</p> |
|
57 |
@param name the name of the permission. It must be |
|
58 |
"register" or "*" for this permission. |
|
59 |
* |
|
60 |
* @throws NullPointerException if <code>name</code> is <code>null</code>. |
|
61 |
* @throws IllegalArgumentException if <code>name</code> is neither |
|
62 |
* "register" nor "*". |
|
63 |
*/ |
|
64 |
public MBeanTrustPermission(String name) { |
|
65 |
this(name, null); |
|
66 |
} |
|
67 |
||
68 |
/** <p>Create a new MBeanTrustPermission with the given name.</p> |
|
69 |
@param name the name of the permission. It must be |
|
70 |
"register" or "*" for this permission. |
|
71 |
@param actions the actions for the permission. It must be |
|
72 |
null or <code>""</code>. |
|
73 |
* |
|
74 |
* @throws NullPointerException if <code>name</code> is <code>null</code>. |
|
75 |
* @throws IllegalArgumentException if <code>name</code> is neither |
|
76 |
* "register" nor "*"; or if <code>actions</code> is a non-null |
|
77 |
* non-empty string. |
|
78 |
*/ |
|
79 |
public MBeanTrustPermission(String name, String actions) { |
|
80 |
super(name, actions); |
|
20814 | 81 |
validate(name,actions); |
82 |
} |
|
83 |
||
84 |
private static void validate(String name, String actions) { |
|
2 | 85 |
/* Check that actions is a null empty string */ |
20814 | 86 |
if (actions != null && actions.length() > 0) { |
87 |
throw new IllegalArgumentException("MBeanTrustPermission actions must be null: " + |
|
2 | 88 |
actions); |
20814 | 89 |
} |
2 | 90 |
|
20814 | 91 |
if (!name.equals("register") && !name.equals("*")) { |
92 |
throw new IllegalArgumentException("MBeanTrustPermission: Unknown target name " + |
|
2 | 93 |
"[" + name + "]"); |
20814 | 94 |
} |
95 |
} |
|
96 |
||
97 |
private void readObject(ObjectInputStream in) |
|
98 |
throws IOException, ClassNotFoundException { |
|
99 |
||
100 |
// Reading private fields of base class |
|
101 |
in.defaultReadObject(); |
|
102 |
try { |
|
103 |
validate(super.getName(),super.getActions()); |
|
104 |
} catch (IllegalArgumentException e) { |
|
105 |
throw new InvalidObjectException(e.getMessage()); |
|
106 |
} |
|
2 | 107 |
} |
108 |
} |