Search in sources :

Example 1 with Version

use of org.eclipse.persistence.Version in project eclipselink by eclipse-ee4j.

the class DoPrivilegedTest method test.

/**
 * Direct calls
 */
@Override
public void test() throws Exception {
    String className = "org.eclipse.persistence.Version";
    String fieldName = "buildNumber";
    String fieldValue = "TopLink Blah";
    String methodName = "setProduct";
    Class<?> clazz = null;
    Version version = null;
    Method method = null;
    try {
        clazz = Class.forName(className);
        Class<?>[] methodParameterTypes = { Class.forName("java.lang.String") };
        ClassLoader clazzloader = clazz.getClassLoader();
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        Class.forName(className, true, clazzloader);
        version = (Version) clazz.getConstructor().newInstance();
        Field[] fields = clazz.getFields();
        Field field = getDeclaredField(clazz, fieldName, true);
        try {
            int intValueFromField = field.getInt(version);
        } catch (Exception e) {
        }
        field.get(version);
        try {
            field.set(version, fieldValue);
        } catch (Exception e) {
        }
        String lineSeparator = System.getProperty("file.separator");
        method = getDeclaredMethod(clazz, methodName, methodParameterTypes, true);
        method.getParameterTypes();
        method.getReturnType();
        Object[] parameters = { "TopLink Blah." };
        method.invoke(version, parameters);
        Constructor constructor = clazz.getConstructor((Class<?>[]) null);
        constructor.setAccessible(true);
        Constructor declaredConstructor = clazz.getDeclaredConstructor((Class<?>[]) null);
        declaredConstructor.setAccessible(true);
        constructor.newInstance((Object[]) null);
    // new XMLSessionConfigLoader().loadInternal(new SessionManager(), clazzloader, false, false);
    } catch (Exception e) {
        throw (new TestProblemException("An exception has been caught."));
    }
}
Also used : PrivilegedInvokeConstructor(org.eclipse.persistence.internal.security.PrivilegedInvokeConstructor) PrivilegedGetMethod(org.eclipse.persistence.internal.security.PrivilegedGetMethod) PrivilegedGetValueFromField(org.eclipse.persistence.internal.security.PrivilegedGetValueFromField) PrivilegedGetDeclaredField(org.eclipse.persistence.internal.security.PrivilegedGetDeclaredField) PrivilegedSetValueInField(org.eclipse.persistence.internal.security.PrivilegedSetValueInField) Version(org.eclipse.persistence.Version) PrivilegedGetContextClassLoader(org.eclipse.persistence.internal.security.PrivilegedGetContextClassLoader) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedGetClassLoaderForClass(org.eclipse.persistence.internal.security.PrivilegedGetClassLoaderForClass)

Example 2 with Version

use of org.eclipse.persistence.Version in project eclipselink by eclipse-ee4j.

the class DoPrivilegedTest method testDoPrivileged.

public void testDoPrivileged() {
    String className = "org.eclipse.persistence.Version";
    String fieldName = "product";
    String fieldValue = "TopLink Blah";
    String methodName = "setProduct";
    Class<?> clazz = null;
    Version version = null;
    Method method = null;
    try {
        clazz = AccessController.doPrivileged(new PrivilegedClassForName<>(className));
        Class<?>[] methodParameterTypes = { AccessController.doPrivileged(new PrivilegedClassForName<>("java.lang.String")) };
        ClassLoader clazzloader = AccessController.doPrivileged(new PrivilegedGetClassLoaderForClass(clazz));
        ClassLoader classloader = AccessController.doPrivileged(new PrivilegedGetContextClassLoader(Thread.currentThread()));
        AccessController.doPrivileged(new PrivilegedClassForName<>(className, true, clazzloader));
        version = (Version) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(clazz));
        Field[] fields = AccessController.doPrivileged(new PrivilegedGetFields(clazz));
        Field field = AccessController.doPrivileged(new PrivilegedGetDeclaredField(clazz, fieldName, true));
        try {
            int intValueFromField = (Integer) AccessController.doPrivileged(new PrivilegedGetValueFromField(field, version));
        } catch (Exception e) {
        }
        AccessController.doPrivileged(new PrivilegedGetValueFromField(field, version));
        try {
            AccessController.doPrivileged(new PrivilegedSetValueInField(field, version, fieldValue));
        } catch (Exception e) {
        }
        String lineSeparator = PrivilegedAccessHelper.getLineSeparator();
        method = AccessController.doPrivileged(new PrivilegedGetMethod(clazz, methodName, methodParameterTypes, true));
        AccessController.doPrivileged(new PrivilegedGetMethodParameterTypes(method));
        AccessController.doPrivileged(new PrivilegedGetMethodReturnType(method));
        Object[] parameters = { "TopLink Blah." };
        AccessController.doPrivileged(new PrivilegedMethodInvoker(method, version, parameters));
        Constructor<?> constructor = AccessController.doPrivileged(new PrivilegedGetConstructorFor<>(clazz, null, true));
        Constructor declaredConstructor = AccessController.doPrivileged(new PrivilegedGetDeclaredConstructorFor(clazz, null, true));
        AccessController.doPrivileged(new PrivilegedInvokeConstructor(constructor, null));
    // PrivilegedAccessController.loadDeploymentXML(new XMLSessionConfigLoader(),new SessionManager(), clazzloader, false, false);
    } catch (Exception e) {
        throw (new TestProblemException("An exception has been caught."));
    }
}
Also used : PrivilegedGetDeclaredConstructorFor(org.eclipse.persistence.internal.security.PrivilegedGetDeclaredConstructorFor) PrivilegedGetValueFromField(org.eclipse.persistence.internal.security.PrivilegedGetValueFromField) PrivilegedGetDeclaredField(org.eclipse.persistence.internal.security.PrivilegedGetDeclaredField) PrivilegedSetValueInField(org.eclipse.persistence.internal.security.PrivilegedSetValueInField) PrivilegedGetDeclaredField(org.eclipse.persistence.internal.security.PrivilegedGetDeclaredField) Version(org.eclipse.persistence.Version) PrivilegedGetValueFromField(org.eclipse.persistence.internal.security.PrivilegedGetValueFromField) PrivilegedGetContextClassLoader(org.eclipse.persistence.internal.security.PrivilegedGetContextClassLoader) PrivilegedGetMethodParameterTypes(org.eclipse.persistence.internal.security.PrivilegedGetMethodParameterTypes) PrivilegedInvokeConstructor(org.eclipse.persistence.internal.security.PrivilegedInvokeConstructor) PrivilegedGetMethod(org.eclipse.persistence.internal.security.PrivilegedGetMethod) PrivilegedGetContextClassLoader(org.eclipse.persistence.internal.security.PrivilegedGetContextClassLoader) PrivilegedGetFields(org.eclipse.persistence.internal.security.PrivilegedGetFields) PrivilegedGetMethod(org.eclipse.persistence.internal.security.PrivilegedGetMethod) PrivilegedSetValueInField(org.eclipse.persistence.internal.security.PrivilegedSetValueInField) PrivilegedGetMethodReturnType(org.eclipse.persistence.internal.security.PrivilegedGetMethodReturnType) PrivilegedMethodInvoker(org.eclipse.persistence.internal.security.PrivilegedMethodInvoker) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedGetClassLoaderForClass(org.eclipse.persistence.internal.security.PrivilegedGetClassLoaderForClass) PrivilegedInvokeConstructor(org.eclipse.persistence.internal.security.PrivilegedInvokeConstructor) PrivilegedGetClassLoaderForClass(org.eclipse.persistence.internal.security.PrivilegedGetClassLoaderForClass) PrivilegedClassForName(org.eclipse.persistence.internal.security.PrivilegedClassForName)

Aggregations

Version (org.eclipse.persistence.Version)2 PrivilegedGetClassLoaderForClass (org.eclipse.persistence.internal.security.PrivilegedGetClassLoaderForClass)2 PrivilegedGetContextClassLoader (org.eclipse.persistence.internal.security.PrivilegedGetContextClassLoader)2 PrivilegedGetDeclaredField (org.eclipse.persistence.internal.security.PrivilegedGetDeclaredField)2 PrivilegedGetMethod (org.eclipse.persistence.internal.security.PrivilegedGetMethod)2 PrivilegedGetValueFromField (org.eclipse.persistence.internal.security.PrivilegedGetValueFromField)2 PrivilegedInvokeConstructor (org.eclipse.persistence.internal.security.PrivilegedInvokeConstructor)2 PrivilegedNewInstanceFromClass (org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass)2 PrivilegedSetValueInField (org.eclipse.persistence.internal.security.PrivilegedSetValueInField)2 PrivilegedClassForName (org.eclipse.persistence.internal.security.PrivilegedClassForName)1 PrivilegedGetDeclaredConstructorFor (org.eclipse.persistence.internal.security.PrivilegedGetDeclaredConstructorFor)1 PrivilegedGetFields (org.eclipse.persistence.internal.security.PrivilegedGetFields)1 PrivilegedGetMethodParameterTypes (org.eclipse.persistence.internal.security.PrivilegedGetMethodParameterTypes)1 PrivilegedGetMethodReturnType (org.eclipse.persistence.internal.security.PrivilegedGetMethodReturnType)1 PrivilegedMethodInvoker (org.eclipse.persistence.internal.security.PrivilegedMethodInvoker)1