Prevent loading interceptors explicitly, as they might be private.
For instance, the Jakarta Validation implementation doesn't export its
interceptor package: org.hibernate.validator.cdi.internal.interceptor
Loading anything from this package will crash GF.
Signed-off-by: arjantijms <arjan.tijms@gmail.com>
diff --git a/appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/InterceptorDescriptor.java b/appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/InterceptorDescriptor.java
index 047f0e4..db14dea 100644
--- a/appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/InterceptorDescriptor.java
+++ b/appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/InterceptorDescriptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,16 +16,21 @@
package com.sun.enterprise.deployment;
-import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType;
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.util.LocalStringManagerImpl;
-import java.util.*;
-import java.util.logging.Logger;
-
/**
* Contains information about 1 Java EE interceptor.
- */
+ */
public class InterceptorDescriptor extends JndiEnvironmentRefsGroupDescriptor
{
@@ -38,15 +43,13 @@
private Set<LifecycleCallbackDescriptor> aroundTimeoutDescriptors;
private String interceptorClassName;
- // Should ONLY be used for system-level interceptors whose class
- // is loaded by something other than the application class-loader
- private Class interceptorClass;
+ private Class<?> interceptorClass;
- // true if the AroundInvoke/AroundTimeout/Callback methods for this
+ // true if the AroundInvoke/AroundTimeout/Callback methods for this
// descriptor were defined on the bean class itself (or one of its
// super-classes). false if the methods are defined
- // on a separate interceptor class (or one of its super-classes).
+ // on a separate interceptor class (or one of its super-classes).
private boolean fromBeanClass = false;
public String getInterceptorClassName() {
@@ -73,7 +76,7 @@
public Set<LifecycleCallbackDescriptor> getAroundInvokeDescriptors() {
if (aroundInvokeDescriptors == null) {
aroundInvokeDescriptors =
- new HashSet<LifecycleCallbackDescriptor>();
+ new HashSet<LifecycleCallbackDescriptor>();
}
return aroundInvokeDescriptors;
}
@@ -92,7 +95,7 @@
public Set<LifecycleCallbackDescriptor> getAroundTimeoutDescriptors() {
if (aroundTimeoutDescriptors == null) {
aroundTimeoutDescriptors =
- new HashSet<LifecycleCallbackDescriptor>();
+ new HashSet<LifecycleCallbackDescriptor>();
}
return aroundTimeoutDescriptors;
}
@@ -196,11 +199,11 @@
/**
* Order a set of lifecycle method descriptors for a particular
* inheritance hierarchy with highest precedence assigned to the
- * least derived class.
+ * least derived class.
*/
private List<LifecycleCallbackDescriptor> orderDescriptors
- (Set<LifecycleCallbackDescriptor> lcds, ClassLoader loader)
- throws Exception
+ (Set<LifecycleCallbackDescriptor> lcds, ClassLoader loader)
+ throws Exception
{
LinkedList<LifecycleCallbackDescriptor> orderedDescs =
@@ -213,7 +216,7 @@
map.put(next.getLifecycleCallbackClass(), next);
}
- Class nextClass = loader.loadClass(getInterceptorClassName());
+ Class<?> nextClass = interceptorClass != null? interceptorClass : loader.loadClass(getInterceptorClassName());
while((nextClass != Object.class) && (nextClass != null)) {
String nextClassName = nextClass.getName();
@@ -230,6 +233,7 @@
}
+ @Override
public String toString() {
return "InterceptorDescriptor class = " + getInterceptorClassName();
}
diff --git a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/interceptors/InterceptorManager.java b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/interceptors/InterceptorManager.java
index 12040d0..06cffff 100644
--- a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/interceptors/InterceptorManager.java
+++ b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/interceptors/InterceptorManager.java
@@ -27,9 +27,9 @@
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
-import jakarta.annotation.PostConstruct;
-import jakarta.ejb.EJBException;
-import jakarta.interceptor.InvocationContext;
+
+import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
+import org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor;
import com.sun.ejb.EJBUtils;
import com.sun.ejb.containers.BaseContainer;
@@ -40,8 +40,10 @@
import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
import com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType;
import com.sun.enterprise.deployment.MethodDescriptor;
-import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
-import org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor;
+
+import jakarta.annotation.PostConstruct;
+import jakarta.ejb.EJBException;
+import jakarta.interceptor.InvocationContext;
/**
@@ -69,7 +71,7 @@
private Logger _logger;
private Class[] interceptorClasses;
-
+
private Class[] serializableInterceptorClasses;
private Map<String, Integer> instanceIndexMap
@@ -222,7 +224,7 @@
for (InterceptorDescriptor interceptor : list) {
String className = interceptor.getInterceptorClassName();
- Set<LifecycleCallbackDescriptor> aroundInvokeDescs =
+ Set<LifecycleCallbackDescriptor> aroundInvokeDescs =
interceptor.getAroundInvokeDescriptors();
if(aroundInvokeDescs.isEmpty() ) {
continue;
@@ -233,10 +235,12 @@
orderedAIInterceptors = interceptor.getOrderedAroundInvokeDescriptors(loader);
} catch (Exception e) {
throw new IllegalStateException("No AroundInvokeIntercetpors found "
- + " on class " + className, e);
+ + " on class " + className, e);
}
+
addAroundInvokeInterceptors(interceptors, interceptor,
- orderedAIInterceptors, className, loader);
+ orderedAIInterceptors, className,
+ interceptor.getInterceptorClass() != null ? interceptor.getInterceptorClass().getClassLoader() : loader);
}
AroundInvokeInterceptor[] inter = interceptors.toArray(
@@ -280,7 +284,7 @@
for (EjbInterceptor interceptor : list) {
String className = interceptor.getInterceptorClassName();
- Set<LifecycleCallbackDescriptor> aroundTimeoutDescs =
+ Set<LifecycleCallbackDescriptor> aroundTimeoutDescs =
interceptor.getAroundTimeoutDescriptors();
if(aroundTimeoutDescs.isEmpty() ) {
continue;
@@ -291,9 +295,9 @@
orderedATInterceptors = interceptor.getOrderedAroundTimeoutDescriptors(loader);
} catch (Exception e) {
throw new IllegalStateException("No AroundTimeoutIntercetpors found "
- + " on class " + className, e);
+ + " on class " + className, e);
}
- addAroundInvokeInterceptors(interceptors, interceptor,
+ addAroundInvokeInterceptors(interceptors, interceptor,
orderedATInterceptors, className, loader);
}
@@ -305,7 +309,7 @@
private void addAroundInvokeInterceptors(
List<AroundInvokeInterceptor> interceptors,
InterceptorDescriptor interceptor,
- List<LifecycleCallbackDescriptor> orderedInterceptors,
+ List<LifecycleCallbackDescriptor> orderedInterceptors,
String className,
ClassLoader classLoaderToUse) {
@@ -315,8 +319,8 @@
method = desc.getLifecycleCallbackMethodObject(classLoaderToUse);
} catch(Exception e) {
throw new IllegalStateException("No callback method of name " +
- desc.getLifecycleCallbackMethod()
- + " found on class " + className, e);
+ desc.getLifecycleCallbackMethod()
+ + " found on class " + className, e);
}
if (interceptor.getFromBeanClass()) {
@@ -328,8 +332,8 @@
throw new IllegalStateException(getInternalErrorString(className));
}
Class clazz = interceptorClasses[index];
- _logger.log(Level.FINE, "*[md.getDeclaredMethod() => "
- + method + " FOR CLAZZ: " + clazz);
+ _logger.log(Level.FINE, "*[md.getDeclaredMethod() => "
+ + method + " FOR CLAZZ: " + clazz);
interceptors.add(new AroundInvokeInterceptor(index, method));
}
}
@@ -367,10 +371,10 @@
case AROUND_CONSTRUCT:
chain = callbackChain[eventType.ordinal()];
if (container != null) {
- invContext = new CallbackInvocationContext(beanClass,
+ invContext = new CallbackInvocationContext(beanClass,
interceptorInstances, chain, eventType, container, ctx);
} else {
- invContext = new CallbackInvocationContext(beanClass,
+ invContext = new CallbackInvocationContext(beanClass,
interceptorInstances, chain, eventType, interceptorInfo);
}
if (chain != null) {
@@ -382,7 +386,7 @@
case POST_ACTIVATE:
case PRE_DESTROY:
chain = callbackChain[eventType.ordinal()];
- invContext = new CallbackInvocationContext(targetObject,
+ invContext = new CallbackInvocationContext(targetObject,
interceptorInstances, chain, eventType);
if (chain != null) {
chain.invokeNext(0, invContext);
@@ -402,9 +406,14 @@
private void buildEjbInterceptorChain()
throws Exception {
- Set<Class> listOfClasses = new HashSet<Class>();
- for(String name : ejbDesc.getInterceptorClassNames()) {
- listOfClasses.add( loader.loadClass(name));
+ Set<Class<?>> listOfClasses = new HashSet<>();
+
+ for (EjbInterceptor ejbInterceptor : ejbDesc.getInterceptorClasses()) {
+ if (ejbInterceptor.getInterceptorClass() != null) {
+ listOfClasses.add(ejbInterceptor.getInterceptorClass());
+ } else {
+ listOfClasses.add(loader.loadClass(ejbInterceptor.getInterceptorClassName()));
+ }
}
// Add framework interceptors to list, but check for existence of
@@ -430,7 +439,7 @@
throws Exception {
- Set<Class> listOfClasses = new HashSet<Class>();
+ Set<Class<?>> listOfClasses = new HashSet<>();
for(String name : interceptorInfo.getInterceptorClassNames()) {
listOfClasses.add( loader.loadClass(name));
}
@@ -460,20 +469,20 @@
}
- private void initInterceptorClasses(Set<Class> classes) throws Exception {
+ private void initInterceptorClasses(Set<Class<?>> classes) throws Exception {
int size = classes.size();
interceptorClasses = new Class[size];
serializableInterceptorClasses = new Class[size];
int index = 0;
- for (Class interClass : classes) {
+ for (Class<?> interClass : classes) {
interceptorClasses[index] = interClass;
serializableInterceptorClasses[index] = interClass;
instanceIndexMap.put(interClass.getName(), index);
if (!Serializable.class.isAssignableFrom(interClass)) {
- serializableInterceptorClasses[index] =
+ serializableInterceptorClasses[index] =
EJBUtils.loadGeneratedSerializableClass(interClass.getClassLoader(),
interClass.getName());
@@ -544,17 +553,17 @@
if (scanFor2xLifecycleMethods) {
load2xLifecycleMethods(callbacks);
}
-
+
//The next set of lines are to handle the case where
- // the app doesn't have a @PostConstruct or it
+ // the app doesn't have a @PostConstruct or it
// doesn't implement the EntrerpriseBean interface
// In this case we scan for ejbCreate() for MDBs and SLSBs
boolean lookForEjbCreateMethod = container.scanForEjbCreateMethod();
-
+
if (lookForEjbCreateMethod) {
loadOnlyEjbCreateMethod(callbacks, numPostConstructFrameworkCallbacks);
}
-
+
callbackChain = new CallbackChainImpl[size];
for (CallbackType eventType : CallbackType.values()) {
int index = eventType.ordinal();
@@ -594,8 +603,7 @@
// move above callbackChain = new CallbackChainImpl[size];
- CallbackInterceptor[] interceptors = (CallbackInterceptor[])
- callbacks.toArray(new CallbackInterceptor[callbacks.size()]);
+ CallbackInterceptor[] interceptors = callbacks.toArray(new CallbackInterceptor[callbacks.size()]);
callbackChain[index] = new CallbackChainImpl(interceptors);
}
@@ -611,8 +619,8 @@
InterceptorDescriptor inter,
ClassLoader classLoaderToUse) throws Exception {
List<CallbackInterceptor> callbackList = new ArrayList<CallbackInterceptor>();
-
- List<LifecycleCallbackDescriptor> orderedCallbackMethods =
+
+ List<LifecycleCallbackDescriptor> orderedCallbackMethods =
inter.getOrderedCallbackDescriptors(eventType, classLoaderToUse);
String className = inter.getInterceptorClassName();
@@ -623,7 +631,7 @@
method = callbackDesc.getLifecycleCallbackMethodObject(classLoaderToUse);
} catch(Exception e) {
throw new IllegalStateException("No callback method of name " +
- callbackDesc.getLifecycleCallbackMethod()
+ callbackDesc.getLifecycleCallbackMethod()
+ " found on class " + className, e);
}
@@ -657,7 +665,7 @@
try {
Method method = beanClass.getMethod(
pre30LCMethodNames[i], (Class[]) null);
- if (method != null) {
+ if (method != null) {
CallbackInterceptor meta =
new BeanCallbackInterceptor(method);
metaArray[i].add(meta);
@@ -670,8 +678,8 @@
}
}
}
-
- //TODO: load2xLifecycleMethods and loadOnlyEjbCreateMethod can be
+
+ //TODO: load2xLifecycleMethods and loadOnlyEjbCreateMethod can be
// refactored to use a common method.
private void loadOnlyEjbCreateMethod(
ArrayList<CallbackInterceptor>[] metaArray,
@@ -687,7 +695,7 @@
ArrayList<CallbackInterceptor> al = metaArray[i];
needToScan = (al.size() == numPostConstructFrameworkCallbacks);
}
-
+
if (! needToScan) {
// We already have found a @PostConstruct method
// So just ignore any ejbCreate() method
@@ -710,8 +718,9 @@
}
}
}
-
+
+ @Override
public String toString() {
StringBuilder sbldr = new StringBuilder();
sbldr.append("##########################################################\n");
@@ -793,6 +802,7 @@
this.size = (interceptors == null) ? 0 : interceptors.length;
}
+ @Override
public Object invokeNext(int index, InterceptorManager.AroundInvokeContext inv)
throws Throwable {
return ( index < size ) ?
@@ -800,6 +810,7 @@
inv.invokeBeanMethod();
}
+ @Override
public String toString() {
StringBuilder bldr = new StringBuilder();
for (AroundInvokeInterceptor inter : interceptors) {
@@ -828,6 +839,7 @@
} else {
java.security.AccessController
.doPrivileged(new java.security.PrivilegedExceptionAction() {
+ @Override
public java.lang.Object run() throws Exception {
if (!finalM.isAccessible()) {
finalM.setAccessible(true);
@@ -850,6 +862,7 @@
// allow for private/protected field access.
return java.security.AccessController
.doPrivileged(new java.security.PrivilegedExceptionAction() {
+ @Override
public java.lang.Object run() throws Exception {
return method.invoke(interceptors[index], invCtx);
}
@@ -870,6 +883,7 @@
}
}
+ @Override
public String toString() {
return "[" + index + "]: " + method;
}
@@ -884,6 +898,7 @@
super(-1, method);
}
+ @Override
Object intercept(final InterceptorManager.AroundInvokeContext invCtx) throws Throwable {
try {
@@ -892,6 +907,7 @@
// allow for private/protected field access.
return java.security.AccessController
.doPrivileged(new java.security.PrivilegedExceptionAction() {
+ @Override
public java.lang.Object run() throws Exception {
return method.invoke(invCtx.getTarget(), invCtx);
}
@@ -928,6 +944,7 @@
} else {
java.security.AccessController
.doPrivileged(new java.security.PrivilegedExceptionAction() {
+ @Override
public java.lang.Object run() throws Exception {
if (!finalM.isAccessible()) {
finalM.setAccessible(true);
@@ -941,7 +958,7 @@
}
- Object intercept(final CallbackInvocationContext invContext)
+ Object intercept(final CallbackInvocationContext invContext)
throws Throwable {
try {
@@ -953,6 +970,7 @@
// allow for private/protected field access.
return java.security.AccessController
.doPrivileged(new java.security.PrivilegedExceptionAction() {
+ @Override
public java.lang.Object run() throws Exception {
return method.invoke(interceptors[index],
invContext);
@@ -960,7 +978,7 @@
});
} else {
return method.invoke(interceptors[index], invContext);
-
+
}
} catch (java.lang.reflect.InvocationTargetException invEx) {
throw invEx.getCause();
@@ -977,6 +995,7 @@
return false;
}
+ @Override
public String toString() {
return "callback[" + index + "]: " + method;
}
@@ -990,7 +1009,8 @@
super(-1, method);
}
- Object intercept(final CallbackInvocationContext invContext)
+ @Override
+ Object intercept(final CallbackInvocationContext invContext)
throws Throwable {
try {
@@ -999,6 +1019,7 @@
// allow for private/protected field access.
java.security.AccessController
.doPrivileged(new java.security.PrivilegedExceptionAction() {
+ @Override
public java.lang.Object run() throws Exception {
method.invoke(invContext.getTarget(),
@@ -1024,10 +1045,12 @@
}
}
+ @Override
boolean isBeanCallback() {
return true;
}
+ @Override
public String toString() {
return "beancallback[" + index + "]: " + method;
}
diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/EjbServicesImpl.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/EjbServicesImpl.java
index 0466658..d7dfcff 100644
--- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/EjbServicesImpl.java
+++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/EjbServicesImpl.java
@@ -22,15 +22,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import jakarta.annotation.PostConstruct;
-import jakarta.annotation.PreDestroy;
-import jakarta.ejb.PostActivate;
-import jakarta.ejb.PrePassivate;
-import jakarta.enterprise.inject.spi.InterceptionType;
-import jakarta.enterprise.inject.spi.Interceptor;
-import jakarta.interceptor.AroundConstruct;
-import jakarta.interceptor.AroundInvoke;
-import jakarta.interceptor.AroundTimeout;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -49,10 +40,20 @@
import com.sun.enterprise.deployment.EjbSessionDescriptor;
import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import jakarta.ejb.PostActivate;
+import jakarta.ejb.PrePassivate;
+import jakarta.enterprise.inject.spi.InterceptionType;
+import jakarta.enterprise.inject.spi.Interceptor;
+import jakarta.interceptor.AroundConstruct;
+import jakarta.interceptor.AroundInvoke;
+import jakarta.interceptor.AroundTimeout;
+
/**
- * An implementation of th <code>EJBServices</code> Weld SPI. The Weld
+ * An implementation of th <code>EJBServices</code> Weld SPI. The Weld
* implementation uses this SPI to resolve EJB and register CDI Interceptors
- * for EJBs.
+ * for EJBs.
*/
public class EjbServicesImpl implements EjbServices {
private ServiceLocator services;
@@ -66,10 +67,11 @@
* Request a reference to an EJB session object from the container. If the
* EJB being resolved is a stateful session bean, the container should ensure
* the session bean is created before this method returns.
- *
+ *
* @param ejbDescriptor the ejb to resolve
* @return a reference to the session object
*/
+ @Override
public SessionObjectReference resolveEjb(EjbDescriptor<?> ejbDescriptor) {
SessionObjectReference sessionObj = null;
@@ -101,7 +103,7 @@
return sessionObj;
}
-
+
private String getDefaultGlobalJndiName(EjbDescriptor<?> ejbDesc) {
@@ -122,16 +124,16 @@
}
+ @Override
public void registerInterceptors(EjbDescriptor<?> ejbDesc, InterceptorBindings interceptorBindings) {
//no need to continue with this work around as jboss has provided the resolution for https://issues.jboss.org/browse/WELD-2184
-
+
// Work around bug that ejbDesc might be internal 299 descriptor.
/* if( ejbDesc instanceof org.jboss.weld.module.ejb.InternalEjbDescriptor ) {
ejbDesc = ((org.jboss.weld.module.ejb.InternalEjbDescriptor<?>)ejbDesc).delegate();
}*/
- com.sun.enterprise.deployment.EjbDescriptor glassfishEjbDesc = (com.sun.enterprise.deployment.EjbDescriptor)
- ((EjbDescriptorImpl<?>) ejbDesc).getEjbDescriptor();
+ com.sun.enterprise.deployment.EjbDescriptor glassfishEjbDesc = ((EjbDescriptorImpl<?>) ejbDesc).getEjbDescriptor();
// Convert to EjbInterceptor
// First create master list of EjbInterceptor descriptors
@@ -189,7 +191,7 @@
// 299-provided list is organized as per-method. Append each method chain to EjbDescriptor.
-
+
Class<?> ejbBeanClass = null;
try {
@@ -199,7 +201,7 @@
throw new IllegalStateException("Cannot load bean class " + glassfishEjbDesc.getEjbClassName(),
cnfe);
}
-
+
Class<?> ejbBeanSuperClass = ejbBeanClass;
while (!ejbBeanSuperClass.equals(java.lang.Object.class)) {
for(Method m : ejbBeanSuperClass.getDeclaredMethods()) {
@@ -343,7 +345,7 @@
EjbInterceptor ejbInt = new EjbInterceptor();
ejbInt.setBundleDescriptor(bundle);
- ejbInt.setInterceptorClassName(interceptor.getBeanClass().getName());
+ ejbInt.setInterceptorClass(interceptor.getBeanClass());
ejbInt.setCDIInterceptor(true);
ejbInt.setInterceptor( interceptor );
@@ -351,6 +353,7 @@
}
+ @Override
public void cleanup() {
//Nothing to do here.
}