javax.management.loading.ClassLoaderRepository Java Examples

The following examples show how to use javax.management.loading.ClassLoaderRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmxMBeanServer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <b>Package:</b> Creates an MBeanServer.
 * @param domain The default domain name used by this MBeanServer.
 * @param outer A pointer to the MBeanServer object that must be
 *        passed to the MBeans when invoking their
 *        {@link javax.management.MBeanRegistration} interface.
 * @param delegate A pointer to the MBeanServerDelegate associated
 *        with the new MBeanServer. The new MBeanServer must register
 *        this MBean in its MBean repository.
 * @param instantiator The MBeanInstantiator that will be used to
 *        instantiate MBeans and take care of class loading issues.
 * @param metadata The MetaData object that will be used by the
 *        MBean server in order to invoke the MBean interface of
 *        the registered MBeans.
 * @param interceptors If <code>true</code>,
 *        {@link MBeanServerInterceptor} will be enabled (default is
 *        <code>false</code>).
 * @param fairLock If {@code true}, the MBean repository will use a {@link
 *        java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
 *        fair locking} policy.
 */
JmxMBeanServer(String domain, MBeanServer outer,
               MBeanServerDelegate    delegate,
               MBeanInstantiator      instantiator,
               boolean                interceptors,
               boolean                fairLock)  {

    if (instantiator == null) {
        final ModifiableClassLoaderRepository
            clr = new ClassLoaderRepositorySupport();
        instantiator = new MBeanInstantiator(clr);
    }

    final MBeanInstantiator fInstantiator = instantiator;
    this.secureClr = new
        SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {
            @Override
            public ClassLoaderRepository run() {
                return fInstantiator.getClassLoaderRepository();
            }
        })
    );
    if (delegate == null)
        delegate = new MBeanServerDelegateImpl();
    if (outer == null)
        outer = this;

    this.instantiator = instantiator;
    this.mBeanServerDelegateObject = delegate;
    this.outerShell   = outer;

    final Repository repository = new Repository(domain);
    this.mbsInterceptor =
        new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
                                          repository);
    this.interceptorsEnabled = interceptors;
    initialize();
}
 
Example #2
Source File: JmxMBeanServer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <b>Package:</b> Creates an MBeanServer.
 * @param domain The default domain name used by this MBeanServer.
 * @param outer A pointer to the MBeanServer object that must be
 *        passed to the MBeans when invoking their
 *        {@link javax.management.MBeanRegistration} interface.
 * @param delegate A pointer to the MBeanServerDelegate associated
 *        with the new MBeanServer. The new MBeanServer must register
 *        this MBean in its MBean repository.
 * @param instantiator The MBeanInstantiator that will be used to
 *        instantiate MBeans and take care of class loading issues.
 * @param metadata The MetaData object that will be used by the
 *        MBean server in order to invoke the MBean interface of
 *        the registered MBeans.
 * @param interceptors If <code>true</code>,
 *        {@link MBeanServerInterceptor} will be enabled (default is
 *        <code>false</code>).
 * @param fairLock If {@code true}, the MBean repository will use a {@link
 *        java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
 *        fair locking} policy.
 */
JmxMBeanServer(String domain, MBeanServer outer,
               MBeanServerDelegate    delegate,
               MBeanInstantiator      instantiator,
               boolean                interceptors,
               boolean                fairLock)  {

    if (instantiator == null) {
        final ModifiableClassLoaderRepository
            clr = new ClassLoaderRepositorySupport();
        instantiator = new MBeanInstantiator(clr);
    }

    final MBeanInstantiator fInstantiator = instantiator;
    this.secureClr = new
        SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {
            @Override
            public ClassLoaderRepository run() {
                return fInstantiator.getClassLoaderRepository();
            }
        })
    );
    if (delegate == null)
        delegate = new MBeanServerDelegateImpl();
    if (outer == null)
        outer = this;

    this.instantiator = instantiator;
    this.mBeanServerDelegateObject = delegate;
    this.outerShell   = outer;

    final Repository repository = new Repository(domain);
    this.mbsInterceptor =
        new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
                                          repository);
    this.interceptorsEnabled = interceptors;
    initialize();
}
 
Example #3
Source File: ClassLoaderWithRepository.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ClassLoaderWithRepository(ClassLoaderRepository clr,
                                  ClassLoader cl2) {

     if (clr == null) throw new
         IllegalArgumentException("Null ClassLoaderRepository object.");

     repository = clr;
     this.cl2 = cl2;
}
 
Example #4
Source File: ClassLoaderWithRepository.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public ClassLoaderWithRepository(ClassLoaderRepository clr,
                                  ClassLoader cl2) {

     if (clr == null) throw new
         IllegalArgumentException("Null ClassLoaderRepository object.");

     repository = clr;
     this.cl2 = cl2;
}
 
Example #5
Source File: JmxMBeanServer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <b>Package:</b> Creates an MBeanServer.
 * @param domain The default domain name used by this MBeanServer.
 * @param outer A pointer to the MBeanServer object that must be
 *        passed to the MBeans when invoking their
 *        {@link javax.management.MBeanRegistration} interface.
 * @param delegate A pointer to the MBeanServerDelegate associated
 *        with the new MBeanServer. The new MBeanServer must register
 *        this MBean in its MBean repository.
 * @param instantiator The MBeanInstantiator that will be used to
 *        instantiate MBeans and take care of class loading issues.
 * @param metadata The MetaData object that will be used by the
 *        MBean server in order to invoke the MBean interface of
 *        the registered MBeans.
 * @param interceptors If <code>true</code>,
 *        {@link MBeanServerInterceptor} will be enabled (default is
 *        <code>false</code>).
 * @param fairLock If {@code true}, the MBean repository will use a {@link
 *        java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
 *        fair locking} policy.
 */
JmxMBeanServer(String domain, MBeanServer outer,
               MBeanServerDelegate    delegate,
               MBeanInstantiator      instantiator,
               boolean                interceptors,
               boolean                fairLock)  {

    if (instantiator == null) {
        final ModifiableClassLoaderRepository
            clr = new ClassLoaderRepositorySupport();
        instantiator = new MBeanInstantiator(clr);
    }

    final MBeanInstantiator fInstantiator = instantiator;
    this.secureClr = new
        SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {
            @Override
            public ClassLoaderRepository run() {
                return fInstantiator.getClassLoaderRepository();
            }
        })
    );
    if (delegate == null)
        delegate = new MBeanServerDelegateImpl();
    if (outer == null)
        outer = this;

    this.instantiator = instantiator;
    this.mBeanServerDelegateObject = delegate;
    this.outerShell   = outer;

    final Repository repository = new Repository(domain);
    this.mbsInterceptor =
        new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
                                          repository);
    this.interceptorsEnabled = interceptors;
    initialize();
}
 
Example #6
Source File: JmxMBeanServer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * De-serializes a byte array in the context of a given MBean class loader.
 * The class loader is the one that loaded the class with name "className".
 *
 * @param className The name of the class whose class loader should be
 *      used for the de-serialization.
 * @param data The byte array to be de-sererialized.
 *
 * @return  The de-serialized object stream.
 *
 * @exception OperationsException Any of the usual Input/Output
 *      related exceptions.
 * @exception ReflectionException The specified class could not be
 *      loaded by the default loader repository
 *
 */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data)
    throws OperationsException, ReflectionException {

    if (className == null) {
        throw new  RuntimeOperationsException(
                                    new IllegalArgumentException(),
                                    "Null className passed in parameter");
    }

    /* Permission check */
    // This call requires MBeanPermission 'getClassLoaderRepository'
    final ClassLoaderRepository clr = getClassLoaderRepository();

    Class<?> theClass;
    try {
        if (clr == null) throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e,
                                      "The given class could not be " +
                                      "loaded by the default loader " +
                                      "repository");
    }

    return instantiator.deserialize(theClass.getClassLoader(), data);
}
 
Example #7
Source File: ClassLoaderWithRepository.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public ClassLoaderWithRepository(ClassLoaderRepository clr,
                                  ClassLoader cl2) {

     if (clr == null) throw new
         IllegalArgumentException("Null ClassLoaderRepository object.");

     repository = clr;
     this.cl2 = cl2;
}
 
Example #8
Source File: RequiredModelMBean.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Class<?> loadClass(final String className)
    throws ClassNotFoundException {
    AccessControlContext stack = AccessController.getContext();
    final ClassNotFoundException[] caughtException = new ClassNotFoundException[1];

    Class c = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {

        @Override
        public Class<?> run() {
            try {
                ReflectUtil.checkPackageAccess(className);
                return Class.forName(className);
            } catch (ClassNotFoundException e) {
                final ClassLoaderRepository clr =
                    getClassLoaderRepository();
                try {
                    if (clr == null) throw new ClassNotFoundException(className);
                    return clr.loadClass(className);
                } catch (ClassNotFoundException ex) {
                    caughtException[0] = ex;
                }
            }
            return null;
        }
    }, stack, acc);

    if (caughtException[0] != null) {
        throw caughtException[0];
    }

    return c;
}
 
Example #9
Source File: RequiredModelMBean.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Class<?> loadClass(final String className)
    throws ClassNotFoundException {
    AccessControlContext stack = AccessController.getContext();
    final ClassNotFoundException[] caughtException = new ClassNotFoundException[1];

    Class c = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {

        @Override
        public Class<?> run() {
            try {
                ReflectUtil.checkPackageAccess(className);
                return Class.forName(className);
            } catch (ClassNotFoundException e) {
                final ClassLoaderRepository clr =
                    getClassLoaderRepository();
                try {
                    if (clr == null) throw new ClassNotFoundException(className);
                    return clr.loadClass(className);
                } catch (ClassNotFoundException ex) {
                    caughtException[0] = ex;
                }
            }
            return null;
        }
    }, stack, acc);

    if (caughtException[0] != null) {
        throw caughtException[0];
    }

    return c;
}
 
Example #10
Source File: JmxMBeanServer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * De-serializes a byte array in the context of a given MBean class loader.
 * The class loader is the one that loaded the class with name "className".
 *
 * @param className The name of the class whose class loader should be
 *      used for the de-serialization.
 * @param data The byte array to be de-sererialized.
 *
 * @return  The de-serialized object stream.
 *
 * @exception OperationsException Any of the usual Input/Output
 *      related exceptions.
 * @exception ReflectionException The specified class could not be
 *      loaded by the default loader repository
 *
 */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data)
    throws OperationsException, ReflectionException {

    if (className == null) {
        throw new  RuntimeOperationsException(
                                    new IllegalArgumentException(),
                                    "Null className passed in parameter");
    }

    /* Permission check */
    // This call requires MBeanPermission 'getClassLoaderRepository'
    final ClassLoaderRepository clr = getClassLoaderRepository();

    Class<?> theClass;
    try {
        if (clr == null) throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e,
                                      "The given class could not be " +
                                      "loaded by the default loader " +
                                      "repository");
    }

    return instantiator.deserialize(theClass.getClassLoader(), data);
}
 
Example #11
Source File: JmxMBeanServer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <b>Package:</b> Creates an MBeanServer.
 * @param domain The default domain name used by this MBeanServer.
 * @param outer A pointer to the MBeanServer object that must be
 *        passed to the MBeans when invoking their
 *        {@link javax.management.MBeanRegistration} interface.
 * @param delegate A pointer to the MBeanServerDelegate associated
 *        with the new MBeanServer. The new MBeanServer must register
 *        this MBean in its MBean repository.
 * @param instantiator The MBeanInstantiator that will be used to
 *        instantiate MBeans and take care of class loading issues.
 * @param metadata The MetaData object that will be used by the
 *        MBean server in order to invoke the MBean interface of
 *        the registered MBeans.
 * @param interceptors If <code>true</code>,
 *        {@link MBeanServerInterceptor} will be enabled (default is
 *        <code>false</code>).
 * @param fairLock If {@code true}, the MBean repository will use a {@link
 *        java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
 *        fair locking} policy.
 */
JmxMBeanServer(String domain, MBeanServer outer,
               MBeanServerDelegate    delegate,
               MBeanInstantiator      instantiator,
               boolean                interceptors,
               boolean                fairLock)  {

    if (instantiator == null) {
        final ModifiableClassLoaderRepository
            clr = new ClassLoaderRepositorySupport();
        instantiator = new MBeanInstantiator(clr);
    }

    final MBeanInstantiator fInstantiator = instantiator;
    this.secureClr = new
        SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {
            @Override
            public ClassLoaderRepository run() {
                return fInstantiator.getClassLoaderRepository();
            }
        })
    );
    if (delegate == null)
        delegate = new MBeanServerDelegateImpl();
    if (outer == null)
        outer = this;

    this.instantiator = instantiator;
    this.mBeanServerDelegateObject = delegate;
    this.outerShell   = outer;

    final Repository repository = new Repository(domain);
    this.mbsInterceptor =
        new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
                                          repository);
    this.interceptorsEnabled = interceptors;
    initialize();
}
 
Example #12
Source File: JmxMBeanServer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * De-serializes a byte array in the context of a given MBean class loader.
 * The class loader is the one that loaded the class with name "className".
 *
 * @param className The name of the class whose class loader should be
 *      used for the de-serialization.
 * @param data The byte array to be de-sererialized.
 *
 * @return  The de-serialized object stream.
 *
 * @exception OperationsException Any of the usual Input/Output
 *      related exceptions.
 * @exception ReflectionException The specified class could not be
 *      loaded by the default loader repository
 *
 */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data)
    throws OperationsException, ReflectionException {

    if (className == null) {
        throw new  RuntimeOperationsException(
                                    new IllegalArgumentException(),
                                    "Null className passed in parameter");
    }

    /* Permission check */
    // This call requires MBeanPermission 'getClassLoaderRepository'
    final ClassLoaderRepository clr = getClassLoaderRepository();

    Class<?> theClass;
    try {
        if (clr == null) throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e,
                                      "The given class could not be " +
                                      "loaded by the default loader " +
                                      "repository");
    }

    return instantiator.deserialize(theClass.getClassLoader(), data);
}
 
Example #13
Source File: ClassLoaderWithRepository.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ClassLoaderWithRepository(ClassLoaderRepository clr,
                                  ClassLoader cl2) {

     if (clr == null) throw new
         IllegalArgumentException("Null ClassLoaderRepository object.");

     repository = clr;
     this.cl2 = cl2;
}
 
Example #14
Source File: RequiredModelMBean.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Class<?> loadClass(final String className)
    throws ClassNotFoundException {
    AccessControlContext stack = AccessController.getContext();
    final ClassNotFoundException[] caughtException = new ClassNotFoundException[1];

    Class c = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {

        @Override
        public Class<?> run() {
            try {
                ReflectUtil.checkPackageAccess(className);
                return Class.forName(className);
            } catch (ClassNotFoundException e) {
                final ClassLoaderRepository clr =
                    getClassLoaderRepository();
                try {
                    if (clr == null) throw new ClassNotFoundException(className);
                    return clr.loadClass(className);
                } catch (ClassNotFoundException ex) {
                    caughtException[0] = ex;
                }
            }
            return null;
        }
    }, stack, acc);

    if (caughtException[0] != null) {
        throw caughtException[0];
    }

    return c;
}
 
Example #15
Source File: JmxMBeanServer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * De-serializes a byte array in the context of a given MBean class loader.
 * The class loader is the one that loaded the class with name "className".
 *
 * @param className The name of the class whose class loader should be
 *      used for the de-serialization.
 * @param data The byte array to be de-sererialized.
 *
 * @return  The de-serialized object stream.
 *
 * @exception OperationsException Any of the usual Input/Output
 *      related exceptions.
 * @exception ReflectionException The specified class could not be
 *      loaded by the default loader repository
 *
 */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data)
    throws OperationsException, ReflectionException {

    if (className == null) {
        throw new  RuntimeOperationsException(
                                    new IllegalArgumentException(),
                                    "Null className passed in parameter");
    }

    /* Permission check */
    // This call requires MBeanPermission 'getClassLoaderRepository'
    final ClassLoaderRepository clr = getClassLoaderRepository();

    Class<?> theClass;
    try {
        if (clr == null) throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e,
                                      "The given class could not be " +
                                      "loaded by the default loader " +
                                      "repository");
    }

    return instantiator.deserialize(theClass.getClassLoader(), data);
}
 
Example #16
Source File: JmxMBeanServer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <b>Package:</b> Creates an MBeanServer.
 * @param domain The default domain name used by this MBeanServer.
 * @param outer A pointer to the MBeanServer object that must be
 *        passed to the MBeans when invoking their
 *        {@link javax.management.MBeanRegistration} interface.
 * @param delegate A pointer to the MBeanServerDelegate associated
 *        with the new MBeanServer. The new MBeanServer must register
 *        this MBean in its MBean repository.
 * @param instantiator The MBeanInstantiator that will be used to
 *        instantiate MBeans and take care of class loading issues.
 * @param metadata The MetaData object that will be used by the
 *        MBean server in order to invoke the MBean interface of
 *        the registered MBeans.
 * @param interceptors If <code>true</code>,
 *        {@link MBeanServerInterceptor} will be enabled (default is
 *        <code>false</code>).
 * @param fairLock If {@code true}, the MBean repository will use a {@link
 *        java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
 *        fair locking} policy.
 */
JmxMBeanServer(String domain, MBeanServer outer,
               MBeanServerDelegate    delegate,
               MBeanInstantiator      instantiator,
               boolean                interceptors,
               boolean                fairLock)  {

    if (instantiator == null) {
        final ModifiableClassLoaderRepository
            clr = new ClassLoaderRepositorySupport();
        instantiator = new MBeanInstantiator(clr);
    }

    final MBeanInstantiator fInstantiator = instantiator;
    this.secureClr = new
        SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {
            @Override
            public ClassLoaderRepository run() {
                return fInstantiator.getClassLoaderRepository();
            }
        })
    );
    if (delegate == null)
        delegate = new MBeanServerDelegateImpl();
    if (outer == null)
        outer = this;

    this.instantiator = instantiator;
    this.mBeanServerDelegateObject = delegate;
    this.outerShell   = outer;

    final Repository repository = new Repository(domain);
    this.mbsInterceptor =
        new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
                                          repository);
    this.interceptorsEnabled = interceptors;
    initialize();
}
 
Example #17
Source File: ClassLoaderWithRepository.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ClassLoaderWithRepository(ClassLoaderRepository clr,
                                  ClassLoader cl2) {

     if (clr == null) throw new
         IllegalArgumentException("Null ClassLoaderRepository object.");

     repository = clr;
     this.cl2 = cl2;
}
 
Example #18
Source File: JmxMBeanServer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * De-serializes a byte array in the context of a given MBean class loader.
 * The class loader is the one that loaded the class with name "className".
 *
 * @param className The name of the class whose class loader should be
 *      used for the de-serialization.
 * @param data The byte array to be de-sererialized.
 *
 * @return  The de-serialized object stream.
 *
 * @exception OperationsException Any of the usual Input/Output
 *      related exceptions.
 * @exception ReflectionException The specified class could not be
 *      loaded by the default loader repository
 *
 */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data)
    throws OperationsException, ReflectionException {

    if (className == null) {
        throw new  RuntimeOperationsException(
                                    new IllegalArgumentException(),
                                    "Null className passed in parameter");
    }

    /* Permission check */
    // This call requires MBeanPermission 'getClassLoaderRepository'
    final ClassLoaderRepository clr = getClassLoaderRepository();

    Class<?> theClass;
    try {
        if (clr == null) throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e,
                                      "The given class could not be " +
                                      "loaded by the default loader " +
                                      "repository");
    }

    return instantiator.deserialize(theClass.getClassLoader(), data);
}
 
Example #19
Source File: ClassLoaderWithRepository.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ClassLoaderWithRepository(ClassLoaderRepository clr,
                                  ClassLoader cl2) {

     if (clr == null) throw new
         IllegalArgumentException("Null ClassLoaderRepository object.");

     repository = clr;
     this.cl2 = cl2;
}
 
Example #20
Source File: ClassLoaderWithRepository.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ClassLoaderWithRepository(ClassLoaderRepository clr,
                                  ClassLoader cl2) {

     if (clr == null) throw new
         IllegalArgumentException("Null ClassLoaderRepository object.");

     repository = clr;
     this.cl2 = cl2;
}
 
Example #21
Source File: RequiredModelMBean.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Class<?> loadClass(final String className)
    throws ClassNotFoundException {
    AccessControlContext stack = AccessController.getContext();
    final ClassNotFoundException[] caughtException = new ClassNotFoundException[1];

    Class c = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {

        @Override
        public Class<?> run() {
            try {
                ReflectUtil.checkPackageAccess(className);
                return Class.forName(className);
            } catch (ClassNotFoundException e) {
                final ClassLoaderRepository clr =
                    getClassLoaderRepository();
                try {
                    if (clr == null) throw new ClassNotFoundException(className);
                    return clr.loadClass(className);
                } catch (ClassNotFoundException ex) {
                    caughtException[0] = ex;
                }
            }
            return null;
        }
    }, stack, acc);

    if (caughtException[0] != null) {
        throw caughtException[0];
    }

    return c;
}
 
Example #22
Source File: JmxMBeanServer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * De-serializes a byte array in the context of a given MBean class loader.
 * The class loader is the one that loaded the class with name "className".
 *
 * @param className The name of the class whose class loader should be
 *      used for the de-serialization.
 * @param data The byte array to be de-sererialized.
 *
 * @return  The de-serialized object stream.
 *
 * @exception OperationsException Any of the usual Input/Output
 *      related exceptions.
 * @exception ReflectionException The specified class could not be
 *      loaded by the default loader repository
 *
 */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data)
    throws OperationsException, ReflectionException {

    if (className == null) {
        throw new  RuntimeOperationsException(
                                    new IllegalArgumentException(),
                                    "Null className passed in parameter");
    }

    /* Permission check */
    // This call requires MBeanPermission 'getClassLoaderRepository'
    final ClassLoaderRepository clr = getClassLoaderRepository();

    Class<?> theClass;
    try {
        if (clr == null) throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e,
                                      "The given class could not be " +
                                      "loaded by the default loader " +
                                      "repository");
    }

    return instantiator.deserialize(theClass.getClassLoader(), data);
}
 
Example #23
Source File: JmxMBeanServer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <b>Package:</b> Creates an MBeanServer.
 * @param domain The default domain name used by this MBeanServer.
 * @param outer A pointer to the MBeanServer object that must be
 *        passed to the MBeans when invoking their
 *        {@link javax.management.MBeanRegistration} interface.
 * @param delegate A pointer to the MBeanServerDelegate associated
 *        with the new MBeanServer. The new MBeanServer must register
 *        this MBean in its MBean repository.
 * @param instantiator The MBeanInstantiator that will be used to
 *        instantiate MBeans and take care of class loading issues.
 * @param metadata The MetaData object that will be used by the
 *        MBean server in order to invoke the MBean interface of
 *        the registered MBeans.
 * @param interceptors If <code>true</code>,
 *        {@link MBeanServerInterceptor} will be enabled (default is
 *        <code>false</code>).
 * @param fairLock If {@code true}, the MBean repository will use a {@link
 *        java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
 *        fair locking} policy.
 */
JmxMBeanServer(String domain, MBeanServer outer,
               MBeanServerDelegate    delegate,
               MBeanInstantiator      instantiator,
               boolean                interceptors,
               boolean                fairLock)  {

    if (instantiator == null) {
        final ModifiableClassLoaderRepository
            clr = new ClassLoaderRepositorySupport();
        instantiator = new MBeanInstantiator(clr);
    }

    final MBeanInstantiator fInstantiator = instantiator;
    this.secureClr = new
        SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {
            @Override
            public ClassLoaderRepository run() {
                return fInstantiator.getClassLoaderRepository();
            }
        })
    );
    if (delegate == null)
        delegate = new MBeanServerDelegateImpl();
    if (outer == null)
        outer = this;

    this.instantiator = instantiator;
    this.mBeanServerDelegateObject = delegate;
    this.outerShell   = outer;

    final Repository repository = new Repository(domain);
    this.mbsInterceptor =
        new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
                                          repository);
    this.interceptorsEnabled = interceptors;
    initialize();
}
 
Example #24
Source File: JmxMBeanServer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * De-serializes a byte array in the context of a given MBean class loader.
 * The class loader is the one that loaded the class with name "className".
 *
 * @param className The name of the class whose class loader should be
 *      used for the de-serialization.
 * @param data The byte array to be de-sererialized.
 *
 * @return  The de-serialized object stream.
 *
 * @exception OperationsException Any of the usual Input/Output
 *      related exceptions.
 * @exception ReflectionException The specified class could not be
 *      loaded by the default loader repository
 *
 */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data)
    throws OperationsException, ReflectionException {

    if (className == null) {
        throw new  RuntimeOperationsException(
                                    new IllegalArgumentException(),
                                    "Null className passed in parameter");
    }

    /* Permission check */
    // This call requires MBeanPermission 'getClassLoaderRepository'
    final ClassLoaderRepository clr = getClassLoaderRepository();

    Class<?> theClass;
    try {
        if (clr == null) throw new ClassNotFoundException(className);
        theClass = clr.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e,
                                      "The given class could not be " +
                                      "loaded by the default loader " +
                                      "repository");
    }

    return instantiator.deserialize(theClass.getClassLoader(), data);
}
 
Example #25
Source File: ClassLoaderWithRepository.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public ClassLoaderWithRepository(ClassLoaderRepository clr,
                                  ClassLoader cl2) {

     if (clr == null) throw new
         IllegalArgumentException("Null ClassLoaderRepository object.");

     repository = clr;
     this.cl2 = cl2;
}
 
Example #26
Source File: RequiredModelMBean.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Class<?> loadClass(final String className)
    throws ClassNotFoundException {
    AccessControlContext stack = AccessController.getContext();
    final ClassNotFoundException[] caughtException = new ClassNotFoundException[1];

    Class c = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {

        @Override
        public Class<?> run() {
            try {
                ReflectUtil.checkPackageAccess(className);
                return Class.forName(className);
            } catch (ClassNotFoundException e) {
                final ClassLoaderRepository clr =
                    getClassLoaderRepository();
                try {
                    if (clr == null) throw new ClassNotFoundException(className);
                    return clr.loadClass(className);
                } catch (ClassNotFoundException ex) {
                    caughtException[0] = ex;
                }
            }
            return null;
        }
    }, stack, acc);

    if (caughtException[0] != null) {
        throw caughtException[0];
    }

    return c;
}
 
Example #27
Source File: DefaultMBeanServerInterceptor.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public ClassLoaderRepository getClassLoaderRepository() {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #28
Source File: LocalMBeanServer.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public ClassLoaderRepository getClassLoaderRepository() {
    return s().getClassLoaderRepository();
}
 
Example #29
Source File: DefaultMBeanServerInterceptor.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public ClassLoaderRepository getClassLoaderRepository() {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #30
Source File: RMIConnectionImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a new {@link RMIConnection}. This connection can be
 * used with either the JRMP or IIOP transport. This object does
 * not export itself: it is the responsibility of the caller to
 * export it appropriately (see {@link
 * RMIJRMPServerImpl#makeClient(String,Subject)} and {@link
 * RMIIIOPServerImpl#makeClient(String,Subject)}.
 *
 * @param rmiServer The RMIServerImpl object for which this
 * connection is created.  The behavior is unspecified if this
 * parameter is null.
 * @param connectionId The ID for this connection.  The behavior
 * is unspecified if this parameter is null.
 * @param defaultClassLoader The default ClassLoader to be used
 * when deserializing marshalled objects.  Can be null, to signify
 * the bootstrap class loader.
 * @param subject the authenticated subject to be used for
 * authorization.  Can be null, to signify that no subject has
 * been authenticated.
 * @param env the environment containing attributes for the new
 * <code>RMIServerImpl</code>.  Can be null, equivalent to an
 * empty map.
 */
public RMIConnectionImpl(RMIServerImpl rmiServer,
                         String connectionId,
                         ClassLoader defaultClassLoader,
                         Subject subject,
                         Map<String,?> env) {
    if (rmiServer == null || connectionId == null)
        throw new NullPointerException("Illegal null argument");
    if (env == null)
        env = Collections.emptyMap();
    this.rmiServer = rmiServer;
    this.connectionId = connectionId;
    this.defaultClassLoader = defaultClassLoader;

    this.subjectDelegator = new SubjectDelegator();
    this.subject = subject;
    if (subject == null) {
        this.acc = null;
        this.removeCallerContext = false;
    } else {
        this.removeCallerContext =
            SubjectDelegator.checkRemoveCallerContext(subject);
        if (this.removeCallerContext) {
            this.acc =
                JMXSubjectDomainCombiner.getDomainCombinerContext(subject);
        } else {
            this.acc =
                JMXSubjectDomainCombiner.getContext(subject);
        }
    }
    this.mbeanServer = rmiServer.getMBeanServer();

    final ClassLoader dcl = defaultClassLoader;

    ClassLoaderRepository repository = AccessController.doPrivileged(
        new PrivilegedAction<ClassLoaderRepository>() {
            public ClassLoaderRepository run() {
                return mbeanServer.getClassLoaderRepository();
            }
        },
        withPermissions(new MBeanPermission("*", "getClassLoaderRepository"))
    );
    this.classLoaderWithRepository = AccessController.doPrivileged(
        new PrivilegedAction<ClassLoaderWithRepository>() {
            public ClassLoaderWithRepository run() {
                return new ClassLoaderWithRepository(
                    repository,
                    dcl);
            }
        },
        withPermissions(new RuntimePermission("createClassLoader"))
    );

    this.defaultContextClassLoader =
        AccessController.doPrivileged(
            new PrivilegedAction<ClassLoader>() {
        @Override
                public ClassLoader run() {
                    return new CombinedClassLoader(Thread.currentThread().getContextClassLoader(),
                            dcl);
                }
            });

    serverCommunicatorAdmin = new
      RMIServerCommunicatorAdmin(EnvHelp.getServerConnectionTimeout(env));

    this.env = env;
}