use of org.mule.runtime.container.internal.ContainerOnlyLookupStrategy in project mule by mulesoft.
the class IsolatedClassLoaderFactory method extendLookupPolicyForPrivilegedAccess.
private ClassLoaderLookupPolicy extendLookupPolicyForPrivilegedAccess(ClassLoaderLookupPolicy childClassLoaderLookupPolicy, ModuleRepository moduleRepository, TestContainerClassLoaderFactory testContainerClassLoaderFactory, PluginUrlClassification pluginUrlClassification) {
ContainerOnlyLookupStrategy containerOnlyLookupStrategy = new ContainerOnlyLookupStrategy(testContainerClassLoaderFactory.getContainerClassLoader().getClassLoader());
Map<String, LookupStrategy> privilegedLookupStrategies = new HashMap<>();
for (MuleModule module : moduleRepository.getModules()) {
if (hasPrivilegedApiAccess(pluginUrlClassification, module)) {
for (String packageName : module.getPrivilegedExportedPackages()) {
privilegedLookupStrategies.put(packageName, containerOnlyLookupStrategy);
}
}
}
if (privilegedLookupStrategies.isEmpty()) {
return childClassLoaderLookupPolicy;
} else {
return childClassLoaderLookupPolicy.extend(privilegedLookupStrategies);
}
}
use of org.mule.runtime.container.internal.ContainerOnlyLookupStrategy in project mule by mulesoft.
the class DefaultRegionPluginClassLoadersFactory method createPluginLookupPolicy.
private ClassLoaderLookupPolicy createPluginLookupPolicy(List<ArtifactClassLoader> classLoaders, ArtifactPluginDescriptor descriptor, ClassLoaderLookupPolicy baseLookupPolicy, List<ArtifactPluginDescriptor> artifactPluginDescriptors) {
Map<String, LookupStrategy> pluginsLookupPolicies = new HashMap<>();
List<ArtifactPluginDescriptor> pluginDescriptors = getPluginDescriptors(descriptor, artifactPluginDescriptors);
for (ArtifactPluginDescriptor dependencyPluginDescriptor : pluginDescriptors) {
if (dependencyPluginDescriptor.getName().equals(descriptor.getName())) {
continue;
}
LookupStrategy lookupStrategy = getClassLoaderLookupStrategy(descriptor, dependencyPluginDescriptor);
for (String exportedPackage : dependencyPluginDescriptor.getClassLoaderModel().getExportedPackages()) {
pluginsLookupPolicies.put(exportedPackage, lookupStrategy);
}
if (isPrivilegedPluginDependency(descriptor, dependencyPluginDescriptor)) {
Optional<ArtifactClassLoader> pluginClassLoader = classLoaders.stream().filter(c -> c.getArtifactDescriptor().getBundleDescriptor().getArtifactId().equals(dependencyPluginDescriptor.getBundleDescriptor().getArtifactId())).findFirst();
if (!pluginClassLoader.isPresent()) {
throw new IllegalStateException("Cannot find classloader for plugin: " + dependencyPluginDescriptor.getBundleDescriptor().getArtifactId());
}
lookupStrategy = new DelegateOnlyLookupStrategy(pluginClassLoader.get().getClassLoader());
for (String exportedPackage : dependencyPluginDescriptor.getClassLoaderModel().getPrivilegedExportedPackages()) {
pluginsLookupPolicies.put(exportedPackage, lookupStrategy);
}
}
}
ContainerOnlyLookupStrategy containerOnlyLookupStrategy = new ContainerOnlyLookupStrategy(this.getClass().getClassLoader());
for (MuleModule module : moduleRepository.getModules()) {
if (module.getPrivilegedArtifacts().contains(descriptor.getBundleDescriptor().getGroupId() + ":" + descriptor.getBundleDescriptor().getArtifactId())) {
for (String packageName : module.getPrivilegedExportedPackages()) {
pluginsLookupPolicies.put(packageName, containerOnlyLookupStrategy);
}
}
}
return baseLookupPolicy.extend(pluginsLookupPolicies);
}
Aggregations