Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove security manager usage from several additional packages #25111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -23,13 +23,10 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import java.security.PrivilegedAction;
import java.util.Enumeration;

import org.glassfish.appclient.common.ClassPathUtils;

import static java.security.AccessController.doPrivileged;

/**
* Used as the system class loader during app client launch.
* <p>
Expand Down Expand Up @@ -57,9 +54,9 @@ public ACCAgentClassLoader(ClassLoader parent) {


private static URLClassLoader prepareLoader(ClassLoader parent) {
PrivilegedAction<URLClassLoader> action = () -> new URLClassLoader(
new URL[] {ClassPathUtils.getGFClientJarURL()}, new ClassLoaderWrapper(parent));
return doPrivileged(action);
return new URLClassLoader(
new URL[] {ClassPathUtils.getGFClientJarURL()},
new ClassLoaderWrapper(parent));
}


Expand All @@ -85,6 +82,7 @@ public synchronized Class<?> loadClass(String name) throws ClassNotFoundExceptio
if (isActive && isStillActive()) {
return super.loadClass(name);
}

return getParent().loadClass(name);
}

Expand All @@ -93,6 +91,7 @@ public URL getResource(String name) {
if (isActive && isStillActive()) {
return super.getResource(name);
}

return getParent().getResource(name);
}

Expand All @@ -101,6 +100,7 @@ public Enumeration<URL> getResources(String name) throws IOException {
if (isActive && isStillActive()) {
return super.getResources(name);
}

return getParent().getResources(name);
}

Expand All @@ -109,6 +109,7 @@ private boolean isStillActive() {
String propValue = System.getProperty("org.glassfish.appclient.acc.agentLoaderDone");
isActive = (propValue != null);
}

return isActive;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -23,9 +23,6 @@
import jakarta.inject.Inject;

import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;

import org.glassfish.api.admin.ProcessEnvironment;
import org.glassfish.api.deployment.ApplicationContainer;
Expand All @@ -39,16 +36,13 @@
import org.jvnet.hk2.annotations.Service;

/**
* Represents an app client module, either stand-alone or nested inside
* an EAR, loaded on the server.
* Represents an app client module, either stand-alone or nested inside an EAR, loaded on the server.
* <p>
* The primary purpose of this class is to implement Java Web Start support for
* launches of this app client. Other than in that sense, app clients do not
* run in the server. To support a client for Java Web Start launches, this
* class figures out what static content (JAR files) and dynamic content (JNLP
* documents) are needed by the client. It then generates the required
* dynamic content templates and submits them and the static content to a
* Grizzly adapter which actually serves the data in response to requests.
* The primary purpose of this class is to implement Java Web Start support for launches of this app client. Other than
* in that sense, app clients do not run in the server. To support a client for Java Web Start launches, this class
* figures out what static content (JAR files) and dynamic content (JNLP documents) are needed by the client. It then
* generates the required dynamic content templates and submits them and the static content to a Grizzly adapter which
* actually serves the data in response to requests.
*
* @author tjquinn
*/
Expand All @@ -57,28 +51,28 @@
public class AppClientServerApplication implements ApplicationContainer<ApplicationClientDescriptor> {

@Inject
private ServiceLocator habitat;
private ServiceLocator serviceLocator;

@Inject
private ProcessEnvironment processEnv;


private DeploymentContext dc;
private DeploymentContext deploymentContext;

private AppClientDeployerHelper helper;

private ApplicationClientDescriptor acDesc;
private ApplicationClientDescriptor applicationClientDescriptor;
private Application appDesc;

private String deployedAppName;

private JavaWebStartInfo jwsInfo;

public void init(final DeploymentContext dc, final AppClientDeployerHelper helper) {
this.dc = dc;
this.deploymentContext = dc;
this.helper = helper;
acDesc = helper.appClientDesc();
appDesc = acDesc.getApplication();

applicationClientDescriptor = helper.appClientDesc();
appDesc = applicationClientDescriptor.getApplication();
deployedAppName = dc.getCommandParameters(DeployCommandParameters.class).name();
}

Expand All @@ -88,26 +82,25 @@ public String deployedAppName() {

@Override
public ApplicationClientDescriptor getDescriptor() {
return acDesc;
return applicationClientDescriptor;
}

public AppClientDeployerHelper helper() {
return helper;
}

public boolean matches(final String appName, final String moduleName) {
return (appName.equals(deployedAppName)
&& (moduleName != null &&
(moduleName.equals(acDesc.getModuleName())
|| acDesc.getModuleName().equals(moduleName + ".jar"))));
return
appName.equals(deployedAppName) &&
(moduleName != null &&
(moduleName.equals(applicationClientDescriptor.getModuleName()) || applicationClientDescriptor.getModuleName().equals(moduleName + ".jar")));
}

@Override
public boolean start(ApplicationContext startupContext) throws Exception {
return start();
}


boolean start() {
if (processEnv.getProcessType().isEmbedded()) {
return true;
Expand All @@ -121,7 +114,7 @@ boolean start() {
}

private JavaWebStartInfo newJavaWebStartInfo() {
final JavaWebStartInfo info = habitat.getService(JavaWebStartInfo.class);
final JavaWebStartInfo info = serviceLocator.getService(JavaWebStartInfo.class);
info.init(this);
return info;
}
Expand Down Expand Up @@ -158,15 +151,13 @@ public boolean resume() throws Exception {
@Override
public ClassLoader getClassLoader() {
/*
* This cannot be null or it prevents the framework from invoking unload
* on the deployer for this app.
* This cannot be null or it prevents the framework from invoking unload on the deployer for this app.
*/
PrivilegedAction<URLClassLoader> action = () -> new GlassfishUrlClassLoader(new URL[0]);
return AccessController.doPrivileged(action);
return new GlassfishUrlClassLoader(new URL[0]);
}

public DeploymentContext dc() {
return dc;
return deploymentContext;
}

public String registrationName() {
Expand All @@ -178,7 +169,7 @@ public String moduleExpression() {
if (appDesc.isVirtual()) {
moduleExpression = appDesc.getRegistrationName();
} else {
moduleExpression = appDesc.getRegistrationName() + "/" + acDesc.getModuleName();
moduleExpression = appDesc.getRegistrationName() + "/" + applicationClientDescriptor.getModuleName();
}
return moduleExpression;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -27,9 +27,6 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.logging.Level;

import javax.naming.Context;

Expand All @@ -38,6 +35,8 @@
import org.jvnet.hk2.annotations.Service;

import static com.sun.enterprise.naming.util.LogFacade.logger;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.SEVERE;
import static org.glassfish.common.util.ObjectInputOutputStreamFactoryFactory.getFactory;

/**
Expand All @@ -61,15 +60,13 @@ public <T> NamingObjectFactory createSimpleNamingObjectFactory(SimpleJndiName na


@Override
public NamingObjectFactory createLazyNamingObjectFactory(SimpleJndiName name, SimpleJndiName jndiName,
boolean cacheResult) {
public NamingObjectFactory createLazyNamingObjectFactory(SimpleJndiName name, SimpleJndiName jndiName, boolean cacheResult) {
return new JndiNamingObjectFactory(name, jndiName, cacheResult);
}


@Override
public NamingObjectFactory createLazyInitializationNamingObjectFactory(SimpleJndiName name, SimpleJndiName jndiName,
boolean cacheResult) {
public NamingObjectFactory createLazyInitializationNamingObjectFactory(SimpleJndiName name, SimpleJndiName jndiName, boolean cacheResult) {
return new JndiInitializationNamingObjectFactory(name, jndiName, cacheResult);
}

Expand All @@ -80,13 +77,16 @@ public NamingObjectFactory createCloningNamingObjectFactory(SimpleJndiName name,
}


@SuppressWarnings("unchecked")
@Override
public <T> T makeCopyOfObject(T obj) {
if (obj instanceof Context || !(obj instanceof Serializable)) {
// XXX no copy ?
return obj;
}
logger.log(Level.FINE, "makeCopyOfObject({0})", obj);

logger.log(FINE, "makeCopyOfObject({0})", obj);

try {
// first serialize the object
final byte[] data;
Expand All @@ -96,13 +96,16 @@ public <T> T makeCopyOfObject(T obj) {
oos.flush();
data = bos.toByteArray();
}
// now deserialize it
try (ByteArrayInputStream bis = new ByteArrayInputStream(data);
ObjectInputStream ois = getFactory().createObjectInputStream(bis)) {
return (T) AccessController.doPrivileged((PrivilegedExceptionAction<Object>) ois::readObject);

// Now deserialize it
try (
ByteArrayInputStream bis = new ByteArrayInputStream(data);
ObjectInputStream ois = getFactory().createObjectInputStream(bis)) {

return (T) ois.readObject();
}
} catch (Exception ex) {
logger.log(Level.SEVERE, EXCEPTION_COPY_MUTABLE, obj);
logger.log(SEVERE, EXCEPTION_COPY_MUTABLE, obj);
throw new RuntimeException("Cant copy Serializable object " + obj, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import jakarta.resource.spi.endpoint.MessageEndpointFactory;

import java.lang.reflect.Method;
import java.security.AccessController;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
Expand All @@ -56,6 +55,8 @@
import org.glassfish.resourcebase.resources.api.ResourceConstants;
import org.glassfish.server.ServerEnvironmentImpl;

import static java.util.logging.Level.FINEST;

/**
* Main helper implementation for message-beans associated with
* a queue. Uses connection consumer for concurrent message
Expand Down Expand Up @@ -89,7 +90,6 @@ public final class ConnectorMessageBeanClient implements MessageBeanClient, Mess
/** unique identification of a message-driven bean: appName:modlueID:beanName */
private final String beanID_;


/**
* Creates an instance of <code>ConnectorMessageBeanClient</code>
*
Expand Down Expand Up @@ -155,8 +155,8 @@ public void setup(MessageBeanProtocolManager messageBeanPM)
throw new IllegalStateException("Unsupported message listener type");
}

if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "ActivationSpecClassName = " + activationSpecClassName);
if (logger.isLoggable(FINEST)) {
logger.log(FINEST, "ActivationSpecClassName = " + activationSpecClassName);
}
try {
ActivationSpec activationSpec = getActivationSpec(aira, activationSpecClassName);
Expand Down Expand Up @@ -218,24 +218,25 @@ private String getResourceAdapterMid(EjbMessageBeanDescriptor descriptor) throws
}
}
}

return resourceAdapterMid;
}

private ActivationSpec getActivationSpec(ActiveInboundResourceAdapter aira, String activationSpecClassName)
throws Exception {
ClassLoader cl = aira.getClassLoader();
Class<?> aClass = cl.loadClass(activationSpecClassName);
private ActivationSpec getActivationSpec(ActiveInboundResourceAdapter activeInboundResourceAdapter, String activationSpecClassName) throws Exception {
ClassLoader classLoader = activeInboundResourceAdapter.getClassLoader();
Class<?> aClass = classLoader.loadClass(activationSpecClassName);

if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "classloader = " + aClass.getClassLoader());
logger.log(Level.FINEST, "classloader parent = " + aClass.getClassLoader().getParent());
if (logger.isLoggable(FINEST)) {
logger.log(FINEST, "classloader = " + aClass.getClassLoader());
logger.log(FINEST, "classloader parent = " + aClass.getClassLoader().getParent());
}

ActivationSpec activationSpec = (ActivationSpec) aClass.getDeclaredConstructor().newInstance();
Set<EnvironmentProperty> props = ConnectorsUtil.getMergedActivationConfigProperties(getDescriptor());

SetMethodAction<EnvironmentProperty> action = new SetMethodAction<>(activationSpec, props);
AccessController.doPrivileged(action);
action.run();

return activationSpec;
}

Expand All @@ -250,6 +251,7 @@ private MessageListener getMessageListener(ConnectorDescriptor desc) {
return msgListener;
}
}

return null;
}

Expand Down Expand Up @@ -286,7 +288,7 @@ private ActiveInboundResourceAdapter getActiveResourceAdapter(String resourceAda
*/
@Override
public void start() throws Exception {
logger.logp(Level.FINEST, "ConnectorMessageBeanClient", "start", "Starting the ConnectorMessageBeanClient");
logger.logp(FINEST, "ConnectorMessageBeanClient", "start", "Starting the ConnectorMessageBeanClient");
started = true;
synchronized (this) {
myState = UNBLOCKED;
Expand All @@ -302,7 +304,7 @@ public void start() throws Exception {
*/
@Override
public void close() {
logger.logp(Level.FINEST, "ConnectorMessageBeanClient", "close", "Closing the ConnectorMessageBeanClient");
logger.logp(FINEST, "ConnectorMessageBeanClient", "close", "Closing the ConnectorMessageBeanClient");

started = false; //no longer available

Expand Down
Loading