Skip to content
Permalink
Browse files
Merge branch 'classbasedesc_doprivileged' into 'ibm-trunk'
Classbasedesc doprivileged

See merge request !48
  • Loading branch information
ngmr committed May 27, 2015
2 parents ca997b7 + e130c21 commit f00755897697aebbd3a8795bde7741ea547c5909
Showing 5 changed files with 50 additions and 47 deletions.
@@ -52,7 +52,7 @@ public String getRepositoryID() {
} else {
TypeDescriptor desc = getTypeRepository()
.getDescriptor(elementType);
String elemRep = desc.getRepositoryIDForArray();
String elemRep = desc.getRepositoryID();
String hash = elemRep.substring(elemRep.indexOf(':', 4));
_repid = "RMI:" + getJavaClass().getName() + hash;
}
@@ -74,7 +74,7 @@ public String getElementRepositoryID() {
} else {
TypeDescriptor desc = getTypeRepository()
.getDescriptor(elementType);
_elementRepid = desc.getRepositoryIDForArray();
_elementRepid = desc.getRepositoryID();
}

// System.out.println ("Element REPID "+getJavaClass()+" >> "+_elementRepid);
@@ -1,12 +1,14 @@
package org.apache.yoko.rmi.impl;

import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;

import javax.rmi.CORBA.ClassDesc;

import org.omg.CORBA.MARSHAL;

public abstract class ClassBaseDescriptor extends ValueDescriptor {
abstract class ClassBaseDescriptor extends ValueDescriptor {

ClassBaseDescriptor(Class type, TypeRepository repository) {
super(type, repository);
@@ -16,16 +18,23 @@ public abstract class ClassBaseDescriptor extends ValueDescriptor {
public void init() {
super.init();

Class<?> clz = ClassDesc.class;
try {
final Field repid_field = clz.getDeclaredField("repid");
repid_field.setAccessible(true);
final Field codebase_field = clz.getDeclaredField("codebase");
codebase_field.setAccessible(true);
init(repid_field, codebase_field);
} catch (NoSuchFieldException ex) {
throw new MARSHAL("no such field: " + ex);
}
final Class<?> clz = ClassDesc.class;

AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
try {
final Field repid_field = clz.getDeclaredField("repid");
repid_field.setAccessible(true);
final Field codebase_field = clz.getDeclaredField("codebase");
codebase_field.setAccessible(true);
init(repid_field, codebase_field);
} catch (NoSuchFieldException ex) {
throw (MARSHAL)new MARSHAL("no such field: " + ex).initCause(ex);
}
return null;
}
});
}

abstract void init(Field repid_field, Field codebase_field);
@@ -33,34 +33,33 @@ void init(Field repid_field, Field codebase_field) {
public Serializable readResolve(final Serializable value) {
final ClassDesc desc = (ClassDesc) value;

Class<?> result = AccessController
.doPrivileged(new PrivilegedAction<Class<?>>() {
public Class<?> run() {
String className = "<unknown>";
try {
String repid = (String) repid_field.get(desc);
String codebase = (String) codebase_field.get(desc);

TypeDescriptor typeDesc = repository.getDescriptor(repid);
if (null != typeDesc) {
Class<?> type = typeDesc.getJavaClass();
if (null != type) return type;
}

int beg = repid.indexOf(':');
int end = repid.indexOf(':', beg + 1);

className = repid.substring(beg + 1, end);
ClassLoader loader = Thread.currentThread().getContextClassLoader();

return Util.loadClass(className, codebase, loader);
} catch (ClassNotFoundException ex) {
throw (MARSHAL)new MARSHAL("cannot load class " + className).initCause(ex);
} catch (IllegalAccessException ex) {
throw (MARSHAL)new MARSHAL("no such field: " + ex).initCause(ex);
}
Class<?> result = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
public Class<?> run() {
String className = "<unknown>";
try {
String repid = (String) repid_field.get(desc);
String codebase = (String) codebase_field.get(desc);

TypeDescriptor typeDesc = repository.getDescriptor(repid);
if (null != typeDesc) {
Class<?> type = typeDesc.getJavaClass();
if (null != type) return type;
}
});

int beg = repid.indexOf(':');
int end = repid.indexOf(':', beg + 1);

className = repid.substring(beg + 1, end);
ClassLoader loader = Thread.currentThread().getContextClassLoader();

return Util.loadClass(className, codebase, loader);
} catch (ClassNotFoundException ex) {
throw (MARSHAL)new MARSHAL("cannot load class " + className).initCause(ex);
} catch (IllegalAccessException ex) {
throw (MARSHAL)new MARSHAL("no such field: " + ex).initCause(ex);
}
}
});

if (logger.isLoggable(Level.FINE))
logger.fine(String.format("readResolve %s => %s", value, result));
@@ -41,9 +41,9 @@ public Class getJavaClass() {

@Override
public String toString() {
return String.format("%s{class=\"%s\",repId=\"%s\",arrRepId=\"%s\"}",
return String.format("%s{class=\"%s\",repId=\"%s\"}",
this.getClass().getName(), getJavaClass(),
getRepositoryID(), getRepositoryIDForArray());
getRepositoryID());
}

protected TypeDescriptor(Class type, TypeRepository repository) {
@@ -65,10 +65,6 @@ protected TypeDescriptor(Class type, TypeRepository repository) {
}
}

public String getRepositoryIDForArray() {
return getRepositoryID();
}

public String getRepositoryID() {
if (_repid == null)
_repid = "RMI:" + getJavaClass().getName() + ":0000000000000000";
@@ -69,7 +69,6 @@ public void put(TypeDescriptor typeDesc) {
cleanStaleKeys();
final WeakReference<TypeDescriptor> value = new WeakReference<>(typeDesc);
map.putIfAbsent(new WeakKey<String>(typeDesc.getRepositoryID(), staleKeys), value);
map.putIfAbsent(new WeakKey<String>(typeDesc.getRepositoryIDForArray(), staleKeys), value);
}

private void cleanStaleKeys() {

0 comments on commit f007558

Please sign in to comment.