01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.jmx;
09:
10: import java.security.Permission;
11: import java.security.ProtectionDomain;
12: import java.security.AccessController;
13: import java.security.PrivilegedAction;
14: import javax.management.ObjectName;
15: import javax.management.MBeanPermission;
16: import javax.management.MBeanTrustPermission;
17:
18: /**
19: *
20: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
21: */
22:
23: public class PermissionChecker {
24: public static void checkMBeanPermission(String classname,
25: String member, ObjectName objectName, String actions)
26: throws SecurityException {
27: SecurityManager sm = System.getSecurityManager();
28: if (sm != null) {
29: Permission perm = new MBeanPermission(classname, member,
30: objectName, actions);
31: sm.checkPermission(perm);
32: }
33: }
34:
35: public static void checkMBeanTrustPermission(final Class theClass)
36: throws SecurityException {
37: SecurityManager sm = System.getSecurityManager();
38: if (sm != null) {
39: Permission perm = new MBeanTrustPermission("*");
40: ProtectionDomain pd = (ProtectionDomain) AccessController
41: .doPrivileged(new PrivilegedAction() {
42: public Object run() {
43: return theClass.getProtectionDomain();
44: }
45: });
46:
47: if (!pd.implies(perm)) {
48: throw new SecurityException("access denied ("
49: + perm.getClass().getName() + " "
50: + perm.getName() + ")");
51: }
52: }
53: }
54:
55: public static void main(String[] args) {
56:
57: }
58: }
|