diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DerbyControl.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DerbyControl.java index 625bfebfb43..76958cef8be 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DerbyControl.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DerbyControl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 2021, 2025 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 @@ -29,6 +29,7 @@ import static com.sun.enterprise.util.Utility.isAllNull; import static com.sun.enterprise.util.Utility.isEmpty; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * This class uses Java reflection to invoke Derby NetworkServerControl class. @@ -125,10 +126,10 @@ public DerbyControl(final String derbyCommand, final String derbyHost, final Str // Do not set derby.system.home if derbyHome is empty if (!isEmpty(derbyHome)) { - System.setProperty("derby.system.home", derbyHome); + setProperty("derby.system.home", derbyHome, true); } // Set the property to not overwrite log file - System.setProperty("derby.infolog.append", "true"); + setProperty("derby.infolog.append", "true", true); } // constructor diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainer.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainer.java index e2348822c6a..a26e7ea0690 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainer.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainer.java @@ -75,6 +75,7 @@ import org.xml.sax.SAXException; import static org.glassfish.appclient.client.acc.AppClientContainer.ClientMainClassSetting.getClientMainClass; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * Embeddable Glassfish app client container (ACC). @@ -303,7 +304,7 @@ private void completePreparation(final Instrumentation inst) throws Exception, U prepareURLStreamHandling(); // This is required for us to enable interrupt jaxws service creation calls - System.setProperty("jakarta.xml.ws.spi.Provider", "com.sun.xml.ws.spi.ProviderImpl"); + setProperty("jakarta.xml.ws.spi.Provider", "com.sun.xml.ws.spi.ProviderImpl", true); // InjectionManager's injectClass will be called from getMainMethod // Load any managed beans diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerBuilder.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerBuilder.java index 725fce7617b..cb6a36c6d93 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerBuilder.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2025 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 @@ -47,6 +47,7 @@ import static org.glassfish.internal.api.ORBLocator.OMG_ORB_INIT_HOST_PROPERTY; import static org.glassfish.internal.api.ORBLocator.OMG_ORB_INIT_PORT_PROPERTY; import static org.glassfish.internal.api.ORBLocator.ORB_SSL_CLIENT_REQUIRED; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * Implements a builder for accumulating configuration information for the app client container and then starting the @@ -239,7 +240,7 @@ private void defineIfNotDefined(final String propName, final String newPropValue "Value for {0} expected but was not configured or assigned", new Object[] { propName })); } - System.setProperty(propName, newPropValue); + setProperty(propName, newPropValue, true); } } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerSecurityHelper.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerSecurityHelper.java index acf77036726..6fcb743fa2d 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerSecurityHelper.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerSecurityHelper.java @@ -44,6 +44,7 @@ import static java.util.Arrays.asList; import static org.glassfish.appclient.client.acc.Util.writeTextToTempFile; import static org.glassfish.embeddable.GlassFishVariable.INSTALL_ROOT; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * @@ -101,7 +102,7 @@ private void initLoginConfig() throws IOException { // The Java com.sun.security.auth.login.ConfigFile class expects the // java.security.auth.login.config property value to be a URL - System.setProperty("java.security.auth.login.config", configFile.toURI().toURL().toExternalForm()); + setProperty("java.security.auth.login.config", configFile.toURI().toURL().toExternalForm(), true); } /** diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/JWSACCMain.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/JWSACCMain.java index 858fc519c34..e5ee12509cb 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/JWSACCMain.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/JWSACCMain.java @@ -42,6 +42,8 @@ import org.glassfish.appclient.client.acc.AppClientContainer; import org.glassfish.appclient.client.acc.JWSACCClassLoader; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; + /** * Alternate main class for ACC, used when launched by Java Web Start. *

@@ -180,7 +182,7 @@ public void run() { *Set a property that the ACC will retrieve during a JWS launch *to locate the app client jar file. */ - System.setProperty("com.sun.aas.downloaded.appclient.jar", downloadedAppclientJarFile.getAbsolutePath()); + setProperty("com.sun.aas.downloaded.appclient.jar", downloadedAppclientJarFile.getAbsolutePath(), true); Thread.currentThread().setContextClassLoader(loader); System.err.println("XXXX: JWSACCMain.run set CL to thread: " + loader); diff --git a/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerProviderImpl.java b/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerProviderImpl.java index 41f35cfc82b..73fdba8042c 100644 --- a/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerProviderImpl.java +++ b/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerProviderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation. + * Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation. * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -56,6 +56,7 @@ import org.glassfish.hk2.api.ServiceLocator; import static org.glassfish.embeddable.GlassFishVariable.INSTANCE_ROOT; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * GlassFish implementation of the EJBContainerProvider. @@ -115,7 +116,7 @@ public EJBContainer createEJBContainer(Map properties) throws EJBException boolean ok = false; Locations l = getLocations(properties); try { - System.setProperty(IS_EJB_CONTAINER, "true"); + setProperty(IS_EJB_CONTAINER, "true", true); createContainer(properties, l); Set modules = addModules(properties, l); if (!DeploymentElement.hasEJBModule(modules)) { @@ -139,7 +140,7 @@ public EJBContainer createEJBContainer(Map properties) throws EJBException _logger.info("[EJBContainerProviderImpl] Error cleaning up..." + t1); } container = null; - System.clearProperty(IS_EJB_CONTAINER); + setProperty(IS_EJB_CONTAINER, null, true); } } } diff --git a/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java b/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java index 2ce06142b4f..addcd88bee2 100644 --- a/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java +++ b/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -37,6 +37,7 @@ import org.glassfish.embeddable.GlassFishRuntime; import org.glassfish.embeddable.spi.RuntimeBuilder; import org.glassfish.main.boot.osgi.OSGiFrameworkLauncher; +import org.glassfish.main.jdke.props.SystemProperties; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; @@ -145,7 +146,8 @@ public GlassFishRuntime build(BootstrapProperties bsOptions, ClassLoader classlo bsOptions.setProperty(OSGI_PLATFORM.getPropertyName(), OsgiPlatform.Felix.name()); } - System.setProperty(UBER_JAR_URI, jar.toString()); // embedded-osgi-main module will need this to extract the modules. + // embedded-osgi-main module will need this to extract the modules. + SystemProperties.setProperty(UBER_JAR_URI, jar.toString(), true); String osgiMainModule = "jar:" + jar.toString() + "!/uber-osgi-main.jar"; bsOptions.setProperty("glassfish.auto.start", osgiMainModule); @@ -160,10 +162,9 @@ public GlassFishRuntime build(BootstrapProperties bsOptions, ClassLoader classlo } bsOptions.setProperty(AUTO_START_BUNDLES_PROP, autoStartBundleLocation); - System.setProperty(AUTO_START_BUNDLES_PROP, autoStartBundleLocation); - - System.setProperty(INSTALL_ROOT.getSystemPropertyName(), installRoot); - System.setProperty(INSTANCE_ROOT.getSystemPropertyName(), instanceRoot); + SystemProperties.setProperty(AUTO_START_BUNDLES_PROP, autoStartBundleLocation, true); + SystemProperties.setProperty(INSTALL_ROOT.getSystemPropertyName(), installRoot, true); + SystemProperties.setProperty(INSTANCE_ROOT.getSystemPropertyName(), instanceRoot, true); String version = loadVersion(); bsOptions.setProperty(FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.glassfish.simpleglassfishapi; version=" + version); diff --git a/appserver/load-balancer/gf-load-balancer-connector/src/main/java/org/glassfish/loadbalancer/config/LbConfig.java b/appserver/load-balancer/gf-load-balancer-connector/src/main/java/org/glassfish/loadbalancer/config/LbConfig.java index 6f7db57e4ea..163e884d203 100644 --- a/appserver/load-balancer/gf-load-balancer-connector/src/main/java/org/glassfish/loadbalancer/config/LbConfig.java +++ b/appserver/load-balancer/gf-load-balancer-connector/src/main/java/org/glassfish/loadbalancer/config/LbConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2025 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -36,7 +36,6 @@ import java.util.Date; import java.util.List; import java.util.Properties; -import java.util.logging.Level; import java.util.logging.Logger; import org.glassfish.api.Param; @@ -59,6 +58,7 @@ import org.jvnet.hk2.config.types.Property; import org.jvnet.hk2.config.types.PropertyBag; +import static java.util.logging.Level.SEVERE; import static org.glassfish.config.support.Constants.NAME_REGEX; /** @@ -297,14 +297,8 @@ private boolean setInternalProperty(String propertyName) { transaction.commit(); } catch (Exception ex) { transaction.rollback(); - Logger logger = LogDomains.getLogger(LbConfig.class, LogDomains.ADMIN_LOGGER); - LocalStringManagerImpl localStrings = new LocalStringManagerImpl(LbConfig.class); - String msg = localStrings.getLocalString( - "UnableToSetPropertyInLbconfig", - "Unable to set property {0} in lbconfig with name {1}", - propertyName, getName()); - logger.log(Level.SEVERE, msg); - logger.log(Level.FINE, "Exception when trying to set property " + propertyName + " in lbconfig " + getName(), ex); + Logger logger = LogDomains.getLogger(LbConfig.class, LogDomains.ADMIN_LOGGER, false); + logger.log(SEVERE, "Unable to set property " + propertyName + " in lbconfig with name " + getName(), ex); return false; } return true; diff --git a/appserver/load-balancer/gf-load-balancer-connector/src/main/java/org/glassfish/loadbalancer/config/LocalStrings.properties b/appserver/load-balancer/gf-load-balancer-connector/src/main/java/org/glassfish/loadbalancer/config/LocalStrings.properties index 8a31bf4c254..57a03762399 100644 --- a/appserver/load-balancer/gf-load-balancer-connector/src/main/java/org/glassfish/loadbalancer/config/LocalStrings.properties +++ b/appserver/load-balancer/gf-load-balancer-connector/src/main/java/org/glassfish/loadbalancer/config/LocalStrings.properties @@ -14,7 +14,6 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 # -UnableToSetPropertyInLbconfig=Unable to set property {0} in lbconfig with name {1} LbConfigIsInUse=LB configuration [{0}] is in use by another load balancer. DeleteLbConfigFailed=Unable to remove lb config {0}. RequiredTargetOrConfig=CLI251: Either option --target or operand config_name is required for this command. diff --git a/appserver/orb/orb-enabler/src/main/java/org/glassfish/enterprise/api/enabler/ORBConnectorStartup.java b/appserver/orb/orb-enabler/src/main/java/org/glassfish/enterprise/api/enabler/ORBConnectorStartup.java index 7af1845dec1..924c9716286 100644 --- a/appserver/orb/orb-enabler/src/main/java/org/glassfish/enterprise/api/enabler/ORBConnectorStartup.java +++ b/appserver/orb/orb-enabler/src/main/java/org/glassfish/enterprise/api/enabler/ORBConnectorStartup.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2025 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 @@ -30,60 +31,47 @@ import org.glassfish.grizzly.config.dom.NetworkListener; import org.glassfish.hk2.api.PostConstruct; import org.glassfish.hk2.runlevel.RunLevel; +import org.glassfish.main.jdke.props.SystemProperties; import org.glassfish.orb.admin.config.IiopListener; import org.glassfish.orb.admin.config.IiopService; import org.jvnet.hk2.annotations.Service; -/** - */ @Service @RunLevel(StartupRunLevel.VAL) public class ORBConnectorStartup implements PostConstruct { // RMI-IIOP delegate constants - private static final String ORB_UTIL_CLASS_PROPERTY = - "javax.rmi.CORBA.UtilClass"; - private static final String RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY = - "javax.rmi.CORBA.StubClass"; - private static final String RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY = - "javax.rmi.CORBA.PortableRemoteObjectClass"; - - // ORB constants: OMG standard - private static final String OMG_ORB_CLASS_PROPERTY = - "org.omg.CORBA.ORBClass"; - private static final String OMG_ORB_SINGLETON_CLASS_PROPERTY = - "org.omg.CORBA.ORBSingletonClass"; - - private static final String ORB_CLASS = - "com.sun.corba.ee.impl.orb.ORBImpl"; - private static final String ORB_SINGLETON_CLASS = - "com.sun.corba.ee.impl.orb.ORBSingleton"; - - private static final String ORB_SE_CLASS = - "com.sun.corba.se.impl.orb.ORBImpl"; - private static final String ORB_SE_SINGLETON_CLASS = - "com.sun.corba.se.impl.orb.ORBSingleton"; - - private static final String RMI_UTIL_CLASS = - "com.sun.corba.ee.impl.javax.rmi.CORBA.Util"; - private static final String RMI_STUB_CLASS = - "com.sun.corba.ee.impl.javax.rmi.CORBA.StubDelegateImpl"; - private static final String RMI_PRO_CLASS = - "com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject"; - - @Inject @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME) + private static final String ORB_UTIL_CLASS_PROPERTY = "javax.rmi.CORBA.UtilClass"; + private static final String RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY = "javax.rmi.CORBA.StubClass"; + private static final String RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY = "javax.rmi.CORBA.PortableRemoteObjectClass"; + + // ORB constants: OMG standard + private static final String OMG_ORB_CLASS_PROPERTY = "org.omg.CORBA.ORBClass"; + private static final String OMG_ORB_SINGLETON_CLASS_PROPERTY = "org.omg.CORBA.ORBSingletonClass"; + + private static final String ORB_CLASS = "com.sun.corba.ee.impl.orb.ORBImpl"; + private static final String ORB_SINGLETON_CLASS = "com.sun.corba.ee.impl.orb.ORBSingleton"; + + private static final String ORB_SE_CLASS = "com.sun.corba.se.impl.orb.ORBImpl"; + private static final String ORB_SE_SINGLETON_CLASS = "com.sun.corba.se.impl.orb.ORBSingleton"; + + private static final String RMI_UTIL_CLASS = "com.sun.corba.ee.impl.javax.rmi.CORBA.Util"; + private static final String RMI_STUB_CLASS = "com.sun.corba.ee.impl.javax.rmi.CORBA.StubDelegateImpl"; + private static final String RMI_PRO_CLASS = "com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject"; + + @Inject + @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME) Config config; @Inject private GrizzlyService grizzlyService; - public void postConstruct() - { + public void postConstruct() { setORBSystemProperties(); initializeLazyListener(); } -/** + /** * Set ORB-related system properties that are required in case * user code in the app server or app client container creates a * new ORB instance. The default result of calling @@ -92,47 +80,11 @@ public void postConstruct() * to a different ORB than the RMI-IIOP delegates. */ private void setORBSystemProperties() { - - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public java.lang.Object run() { - if (System.getProperty(OMG_ORB_CLASS_PROPERTY) == null) { - // Assume Sun ee ORB at all times. - // set ORB based on JVM vendor - // - // if (System.getProperty("java.vendor").equals("Sun Microsystems Inc.")) { - // System.setProperty(OMG_ORB_CLASS_PROPERTY, ORB_SE_CLASS); - // } else { - // if not Sun, then set to EE class - System.setProperty(OMG_ORB_CLASS_PROPERTY, ORB_CLASS); - // } - } - - if (System.getProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY) == null) { - // Assume Sun ee ORB at all times. - // - // set ORBSingleton based on JVM vendor - // if (System.getProperty("java.vendor").equals("Sun Microsystems Inc.")) { - // System.setProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY, ORB_SE_SINGLETON_CLASS); - // } else { - // if not Sun, then set to EE class - System.setProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY, ORB_SINGLETON_CLASS); - // } - } - - System.setProperty(ORB_UTIL_CLASS_PROPERTY, - RMI_UTIL_CLASS); - - System.setProperty(RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY, - RMI_STUB_CLASS); - - System.setProperty(RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY, - RMI_PRO_CLASS); - - return null; - } - } - ); + SystemProperties.setProperty(OMG_ORB_CLASS_PROPERTY, ORB_CLASS, false); + SystemProperties.setProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY, ORB_SINGLETON_CLASS, false); + SystemProperties.setProperty(ORB_UTIL_CLASS_PROPERTY, RMI_UTIL_CLASS, true); + SystemProperties.setProperty(RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY, RMI_STUB_CLASS, true); + SystemProperties.setProperty(RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY, RMI_PRO_CLASS, true); } /** diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBInitializer.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBInitializer.java index 8044377b2ba..ea0554f9fb4 100644 --- a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBInitializer.java +++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBInitializer.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2025 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 @@ -19,7 +20,6 @@ import com.sun.logging.LogDomains; import java.util.Collection; -import java.util.logging.Level; import java.util.logging.Logger; import org.glassfish.enterprise.iiop.api.IIOPInterceptorFactory; @@ -29,9 +29,12 @@ import org.omg.IOP.ENCODING_CDR_ENCAPS; import org.omg.IOP.Encoding; import org.omg.PortableInterceptor.ClientRequestInterceptor; +import org.omg.PortableInterceptor.ORBInitInfo; import org.omg.PortableInterceptor.ORBInitializer; import org.omg.PortableInterceptor.ServerRequestInterceptor; +import static java.util.logging.Level.FINE; + /** * This file implements an initializer class for all portable interceptors * used in the J2EE RI (currently security and transactions). @@ -41,54 +44,31 @@ * @author Mahesh Kannan * */ +public class GlassFishORBInitializer extends org.omg.CORBA.LocalObject implements ORBInitializer { -public class GlassFishORBInitializer extends org.omg.CORBA.LocalObject - implements ORBInitializer { - private static final Logger _logger = - LogDomains.getLogger(GlassFishORBInitializer.class, LogDomains.CORBA_LOGGER); - - private static void fineLog( String fmt, Object... args ) { - if (_logger.isLoggable(Level.FINE)) { - _logger.log(Level.FINE, fmt, args ) ; - } - } - - public GlassFishORBInitializer() { - /* - //Ken feels that adding the property to orbInitProperties - // is better than setting System properties - try { - System.setProperty( - com.sun.jts.pi.InterceptorImpl.CLIENT_POLICY_CHECKING, - String.valueOf(false)); - } catch (Exception ex) { - _logger.log(Level.WARNING, "iiop.readproperty_exception", ex); - } - */ - } + private static final Logger LOG = LogDomains.getLogger(GlassFishORBInitializer.class, LogDomains.CORBA_LOGGER); /** * This method is called during ORB initialization. * - * @param info object that provides initialization attributes - * and operations by which interceptors are registered. + * @param info object that provides initialization attributes and operations by which + * interceptors are registered. */ @Override - public void pre_init(org.omg.PortableInterceptor.ORBInitInfo info) { + public void pre_init(ORBInitInfo info) { } + /** * This method is called during ORB initialization. * - * @param info object that provides initialization attributes - * and operations by which interceptors are registered. + * @param info object that provides initialization attributes and operations by which + * interceptors are registered. */ @Override - public void post_init(org.omg.PortableInterceptor.ORBInitInfo info) { - Codec codec = null; - - fineLog( "J2EE Initializer post_init"); - fineLog( "Creating Codec for CDR encoding"); + public void post_init(ORBInitInfo info) { + LOG.log(FINE, "J2EE Initializer post_init"); + LOG.log(FINE, "Creating Codec for CDR encoding"); CodecFactory cf = info.codec_factory(); @@ -97,36 +77,27 @@ public void post_init(org.omg.PortableInterceptor.ORBInitInfo info) { Encoding encoding = new Encoding(ENCODING_CDR_ENCAPS.value, major_version, minor_version); try { - codec = cf.create_codec(encoding); - + Codec codec = cf.create_codec(encoding); IIOPUtils iiopUtils = IIOPUtils.getInstance(); - Collection interceptorFactories = - iiopUtils.getAllIIOPInterceptrFactories(); + Collection interceptorFactories = iiopUtils.getAllIIOPInterceptrFactories(); for (IIOPInterceptorFactory factory : interceptorFactories) { - fineLog( "Processing interceptor factory: {0}", factory); + LOG.log(FINE, "Processing interceptor factory: {0}", factory); - ClientRequestInterceptor clientReq = - factory.createClientRequestInterceptor(info, codec); - ServerRequestInterceptor serverReq = - factory.createServerRequestInterceptor(info, codec); + ClientRequestInterceptor clientReq = factory.createClientRequestInterceptor(info, codec); + ServerRequestInterceptor serverReq = factory.createServerRequestInterceptor(info, codec); if (clientReq != null) { - fineLog( "Registering client interceptor: {0}", clientReq); + LOG.log(FINE, "Registering client interceptor: {0}", clientReq); info.add_client_request_interceptor(clientReq); } if (serverReq != null) { - fineLog( "Registering server interceptor: {0}", serverReq); + LOG.log(FINE, "Registering server interceptor: {0}", serverReq); info.add_server_request_interceptor(serverReq); } } - } catch (Exception e) { - if (_logger.isLoggable(Level.WARNING)) { - _logger.log(Level.WARNING, "Exception registering interceptors", e ) ; - } - throw new RuntimeException(e.getMessage(), e); + throw new RuntimeException("Exception registering interceptors", e); } } } - diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBManager.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBManager.java index 64ec32256e2..cab58a6799b 100644 --- a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBManager.java +++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2025 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 @@ -55,6 +55,8 @@ import org.glassfish.orb.admin.config.Orb; import org.jvnet.hk2.config.types.Property; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; + /** * This class initializes the ORB with a list of (standard) properties * and provides a few convenience methods to get the ORB etc. @@ -70,10 +72,6 @@ public final class GlassFishORBManager { private static final String ORB_CLASS = ORBImpl.class.getName(); private static final String ORB_SINGLETON_CLASS = ORBSingleton.class.getName(); - // FIXME: Doesn't exist in JDK9+ - private static final String ORB_SE_CLASS = "com.sun.corba.se.impl.orb.ORBImpl"; - private static final String ORB_SE_SINGLETON_CLASS = "com.sun.corba.se.impl.orb.ORBSingleton"; - private static final String PEORB_CONFIG_CLASS = PEORBConfigurator.class.getName(); private static final String IIOP_SSL_SOCKET_FACTORY_CLASS = IIOPSSLSocketFactory.class.getName(); private static final String RMI_UTIL_CLASS = Util.class.getName(); @@ -264,25 +262,11 @@ private void initProperties() { * to a different ORB than the RMI-IIOP delegates. */ private void setORBSystemProperties() { - java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { - - @Override - public java.lang.Object run() { - if (System.getProperty(OMG_ORB_CLASS_PROPERTY) == null) { - System.setProperty(OMG_ORB_CLASS_PROPERTY, ORB_CLASS); - } - - if (System.getProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY) == null) { - System.setProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY, ORB_SINGLETON_CLASS); - } - - System.setProperty(ORB_UTIL_CLASS_PROPERTY, RMI_UTIL_CLASS); - System.setProperty(RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY, RMI_STUB_CLASS); - System.setProperty(RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY, RMI_PRO_CLASS); - - return null; - } - }); + setProperty(OMG_ORB_CLASS_PROPERTY, ORB_CLASS, false); + setProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY, ORB_SINGLETON_CLASS, false); + setProperty(ORB_UTIL_CLASS_PROPERTY, RMI_UTIL_CLASS, true); + setProperty(RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY, RMI_STUB_CLASS, true); + setProperty(RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY, RMI_PRO_CLASS, true); } /** @@ -446,7 +430,7 @@ private void initORB(Properties props) { // Can't run with GlassFishORBManager.class.getClassLoader() as the context ClassLoader // For ORB compatibility with JDK11+ JDKs see https://github.com/eclipse-ee4j/orb-gmbal/issues/22 - System.setProperty("org.glassfish.gmbal.no.multipleUpperBoundsException", "true"); + setProperty("org.glassfish.gmbal.no.multipleUpperBoundsException", "true", true); orb = ORBFactory.create(); ORBFactory.initialize(orb, args, orbInitProperties, useOSGI); diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/NamingClusterInfoImpl.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/NamingClusterInfoImpl.java index 9245ca5e86e..fa9f28c8e3b 100644 --- a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/NamingClusterInfoImpl.java +++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/NamingClusterInfoImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2025 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 @@ -32,6 +32,7 @@ import org.glassfish.hk2.api.ServiceHandle; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.internal.api.ORBLocator; +import org.glassfish.main.jdke.props.SystemProperties; import org.jvnet.hk2.annotations.Service; import org.omg.CORBA.ORB; import org.omg.CORBA.ORBPackage.InvalidName; @@ -107,8 +108,7 @@ private List getEndpointList(Hashtable env, String defaultHost, String d if (!lbList.isEmpty()) { final String first = lbList.remove(0); if (first.equals(IC_BASED) || first.equals(IC_BASED_WEIGHTED)) { - // XXX concurrency issue here: possible race on global - System.setProperty(LOAD_BALANCING_PROPERTY, first ); + SystemProperties.setProperty(LOAD_BALANCING_PROPERTY, first, true); } } list.addAll(lbList); diff --git a/appserver/persistence/jpa-container/src/main/java/org/glassfish/persistence/jpa/PersistenceUnitLoader.java b/appserver/persistence/jpa-container/src/main/java/org/glassfish/persistence/jpa/PersistenceUnitLoader.java index ecb0f99ba8f..575c4954924 100644 --- a/appserver/persistence/jpa-container/src/main/java/org/glassfish/persistence/jpa/PersistenceUnitLoader.java +++ b/appserver/persistence/jpa-container/src/main/java/org/glassfish/persistence/jpa/PersistenceUnitLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation. + * Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation. * Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -36,6 +36,7 @@ import org.glassfish.api.naming.SimpleJndiName; import org.glassfish.deployment.common.RootDeploymentDescriptor; +import org.glassfish.main.jdke.props.SystemProperties; import org.glassfish.persistence.jpa.schemageneration.SchemaGenerationProcessor; import org.glassfish.persistence.jpa.schemageneration.SchemaGenerationProcessorFactory; @@ -137,14 +138,7 @@ public EntityManagerFactory getEMF() { } private void setSystemPropertyToEnableDoPrivilegedInEclipseLink() { - final String PROPERTY_NAME = "eclipselink.security.usedoprivileged"; - // Need not invoke in doPrivileged block as the whole call stack consist of - // trusted code when this code - // is invoked - if (System.getProperty(PROPERTY_NAME) == null) { - // property not set. Set it to true - System.setProperty(PROPERTY_NAME, String.valueOf(Boolean.TRUE)); - } + SystemProperties.setProperty("eclipselink.security.usedoprivileged", Boolean.TRUE.toString(), false); } /** diff --git a/appserver/security/appclient.security/src/main/java/com/sun/enterprise/security/appclient/AppClientSecurityInfoImpl.java b/appserver/security/appclient.security/src/main/java/com/sun/enterprise/security/appclient/AppClientSecurityInfoImpl.java index c47bcca322b..457ffcb738c 100644 --- a/appserver/security/appclient.security/src/main/java/com/sun/enterprise/security/appclient/AppClientSecurityInfoImpl.java +++ b/appserver/security/appclient.security/src/main/java/com/sun/enterprise/security/appclient/AppClientSecurityInfoImpl.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2025 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 @@ -48,6 +49,7 @@ import static java.lang.System.Logger.Level.DEBUG; import static java.lang.System.Logger.Level.ERROR; import static java.lang.System.Logger.Level.WARNING; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * @@ -99,7 +101,7 @@ public void initializeSecurity(List tServers, List unpackedList = new ArrayList(); ArrayList packedList = new ArrayList(); @@ -174,16 +172,18 @@ public void init() SecurityClassLoad.securityClassLoad(catalinaLoader); // Load our startup class and call its process() method - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Loading startup class"); + } Class startupClass = catalinaLoader.loadClass ("org.apache.catalina.startup.Catalina"); Object startupInstance = startupClass.newInstance(); // Set the shared extensions class loader - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Setting startup class properties"); + } String methodName = "setParentClassLoader"; Class paramTypes[] = new Class[1]; paramTypes[0] = Class.forName("java.lang.ClassLoader"); @@ -219,8 +219,9 @@ private void load(String[] arguments) } Method method = catalinaDaemon.getClass().getMethod(methodName, paramTypes); - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Calling startup class " + method); + } method.invoke(catalinaDaemon, param); } @@ -255,7 +256,9 @@ public void init(String[] arguments) */ public void start() throws Exception { - if( catalinaDaemon==null ) init(); + if( catalinaDaemon==null ) { + init(); + } Method method = catalinaDaemon.getClass().getMethod("start",(Class[])null); method.invoke(catalinaDaemon, (Object[])null); @@ -324,11 +327,11 @@ public void destroy() { } public void setCatalinaHome(String s) { - System.setProperty( "catalina.home", s ); + setProperty("catalina.home", s, true); } public void setCatalinaBase(String s) { - System.setProperty( "catalina.base", s ); + setProperty("catalina.base", s, true); } /** @@ -336,16 +339,14 @@ public void setCatalinaBase(String s) { * working directory if it has not been set. */ private void setCatalinaBase() { - - if (System.getProperty("catalina.base") != null) + if (System.getProperty("catalina.base") != null) { return; - if (System.getProperty("catalina.home") != null) - System.setProperty("catalina.base", - System.getProperty("catalina.home")); - else - System.setProperty("catalina.base", - System.getProperty("user.dir")); - + } + if (System.getProperty("catalina.home") == null) { + setProperty("catalina.base", System.getProperty("user.dir"), true); + } else { + setProperty("catalina.base", System.getProperty("catalina.home"), true); + } } /** @@ -353,46 +354,33 @@ private void setCatalinaBase() { * working directory if it has not been set. */ private void setCatalinaHome() { - - if (System.getProperty("catalina.home") != null) + if (System.getProperty("catalina.home") != null) { return; - File bootstrapJar = - new File(System.getProperty("user.dir"), "bootstrap.jar"); + } + File bootstrapJar = new File(System.getProperty("user.dir"), "bootstrap.jar"); if (bootstrapJar.exists()) { try { - System.setProperty - ("catalina.home", - (new File(System.getProperty("user.dir"), "..")) - .getCanonicalPath()); + setProperty("catalina.home", new File(System.getProperty("user.dir"), "..").getCanonicalPath(), true); } catch (Exception e) { - // Ignore - System.setProperty("catalina.home", - System.getProperty("user.dir")); + // Ignore exception + setProperty("catalina.home", System.getProperty("user.dir"), true); } } else { - System.setProperty("catalina.home", - System.getProperty("user.dir")); + setProperty("catalina.home", System.getProperty("user.dir"), true); } - } - /** * Get the value of the catalina.home environment variable. */ public static String getCatalinaHome() { - return System.getProperty("catalina.home", - System.getProperty("user.dir")); + return System.getProperty("catalina.home", System.getProperty("user.dir")); } - /** * Get the value of the catalina.base environment variable. */ public static String getCatalinaBase() { return System.getProperty("catalina.base", getCatalinaHome()); } - - - } diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/startup/CatalinaProperties.java b/appserver/web/web-core/src/main/java/org/apache/catalina/startup/CatalinaProperties.java index 9125182fde7..f7d2bea5009 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/startup/CatalinaProperties.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/startup/CatalinaProperties.java @@ -27,6 +27,7 @@ import java.util.logging.Logger; import org.apache.catalina.LogFacade; +import org.glassfish.main.jdke.props.SystemProperties; /** * Utility class to read the bootstrap Catalina configuration. @@ -136,7 +137,7 @@ private static void loadProperties() { String name = (String) enumeration.nextElement(); String value = properties.getProperty(name); if (value != null) { - System.setProperty(name, value); + SystemProperties.setProperty(name, value, true); } } @@ -147,8 +148,7 @@ private static void loadProperties() { * Get the value of the catalina.home environment variable. */ private static String getCatalinaHome() { - return System.getProperty("catalina.home", - System.getProperty("user.dir")); + return System.getProperty("catalina.home", System.getProperty("user.dir")); } diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/startup/Embedded.java b/appserver/web/web-core/src/main/java/org/apache/catalina/startup/Embedded.java index 332c149616f..15ddb998de5 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/startup/Embedded.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/startup/Embedded.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2025 Contributors to the Eclipse Foundation. * Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved. * Copyright 2004 The Apache Software Foundation * @@ -53,6 +54,10 @@ import org.glassfish.web.util.IntrospectionUtils; import org.glassfish.web.valve.GlassFishValve; +import static javax.naming.Context.INITIAL_CONTEXT_FACTORY; +import static javax.naming.Context.URL_PKG_PREFIXES; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; + /** * Convenience class to embed a Catalina servlet container environment * inside another application. You must call the methods of this class in the @@ -316,11 +321,11 @@ public boolean isAwait() { } public void setCatalinaHome( String s ) { - System.setProperty( "catalina.home", s); + setProperty( "catalina.home", s, true); } public void setCatalinaBase( String s ) { - System.setProperty( "catalina.base", s); + setProperty( "catalina.base", s, true); } public String getCatalinaHome() { @@ -349,6 +354,7 @@ public boolean isDirectoryListing() { * * @exception IllegalStateException if no engines have been added yet */ + @Override public synchronized void addConnector(Connector connector) { if (log.isLoggable(Level.FINE)) { @@ -356,9 +362,10 @@ public synchronized void addConnector(Connector connector) { } // Make sure we have a Container to send requests to - if (engines.length < 1) + if (engines.length < 1) { throw new IllegalStateException (rb.getString(LogFacade.NO_ENGINES_DEFINED)); + } /* * Add the connector. This will set the connector's container to the @@ -375,13 +382,15 @@ public synchronized void addConnector(Connector connector) { */ public synchronized void addEngine(Engine engine) { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Adding engine (" + engine.getInfo() + ")"); + } // Add this Engine to our set of defined Engines Engine results[] = new Engine[engines.length + 1]; - for (int i = 0; i < engines.length; i++) + for (int i = 0; i < engines.length; i++) { results[i] = engines[i]; + } results[engines.length] = engine; engines = results; @@ -524,9 +533,10 @@ public Connector createConnector(String address, int port, */ public Context createContext(String path, String docBase) { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Creating context '" + path + "' with docBase '" + docBase + "'"); + } StandardContext context = new StandardContext(); @@ -537,7 +547,7 @@ public Context createContext(String path, String docBase) { ContextConfig config = new ContextConfig(); config.setCustomAuthenticators(authenticators); config.setDebug(debug); - ((Lifecycle) context).addLifecycleListener(config); + context.addLifecycleListener(config); return (context); @@ -551,8 +561,9 @@ public Context createContext(String path, String docBase) { */ public Engine createEngine() { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Creating engine"); + } StandardEngine engine = new StandardEngine(); @@ -594,9 +605,10 @@ public Engine createEngine() { */ public Host createHost(String name, String appBase) { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Creating host '" + name + "' with appBase '" + appBase + "'"); + } StandardHost host = new StandardHost(); @@ -618,9 +630,10 @@ public Host createHost(String name, String appBase) { */ public Loader createLoader(ClassLoader parent) { - if (log.isLoggable(Level.FINEST)) + if (log.isLoggable(Level.FINEST)) { log.log(Level.FINEST, "Creating Loader with parent class loader '" + parent + "'"); + } WebappLoader loader = new WebappLoader(parent); return (loader); @@ -633,6 +646,7 @@ public Loader createLoader(ClassLoader parent) { * the corresponding version number, in the format * <description>/<version>. */ + @Override public String getInfo() { return (this.info); @@ -649,8 +663,9 @@ public String getInfo() { */ public synchronized void removeContext(Context context) { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Removing context[" + context.getPath() + "]"); + } // Is this Context actually among those that are defined? boolean found = false; @@ -664,18 +679,22 @@ public synchronized void removeContext(Context context) { break; } } - if (found) + if (found) { break; + } } - if (found) + if (found) { break; + } } - if (!found) + if (!found) { return; + } // Remove this Context from the associated Host - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, " Removing this Context"); + } context.getParent().removeChild(context); } @@ -690,8 +709,9 @@ public synchronized void removeContext(Context context) { */ public synchronized void removeEngine(Engine engine) { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Removing engine (" + engine.getInfo() + ")"); + } // Is the specified Engine actually defined? int j = -1; @@ -701,22 +721,25 @@ public synchronized void removeEngine(Engine engine) { break; } } - if (j < 0) + if (j < 0) { return; + } // Remove any Connector that is using this Engine - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, " Removing related Containers"); + } while (true) { int n = -1; for (int i = 0; i < connectors.length; i++) { - if (connectors[i].getContainer() == (Container) engine) { + if (connectors[i].getContainer() == engine) { n = i; break; } } - if (n < 0) + if (n < 0) { break; + } // START SJSAS 6231069 //removeConnector(connectors[n]); try{ @@ -729,8 +752,9 @@ public synchronized void removeEngine(Engine engine) { // Stop this Engine if necessary if (engine instanceof Lifecycle) { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, " Stopping this Engine"); + } try { ((Lifecycle) engine).stop(); } catch (LifecycleException e) { @@ -739,13 +763,15 @@ public synchronized void removeEngine(Engine engine) { } // Remove this Engine from our set of defined Engines - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, " Removing this Engine"); + } int k = 0; Engine results[] = new Engine[engines.length - 1]; for (int i = 0; i < engines.length; i++) { - if (i != j) + if (i != j) { results[k++] = engines[i]; + } } engines = results; @@ -761,8 +787,9 @@ public synchronized void removeEngine(Engine engine) { */ public synchronized void removeHost(Host host) { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Removing host[" + host.getName() + "]"); + } // Is this Host actually among those that are defined? boolean found = false; @@ -775,15 +802,18 @@ public synchronized void removeHost(Host host) { } } - if (found) + if (found) { break; + } } - if (!found) + if (!found) { return; + } // Remove this Host from the associated Engine - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, " Removing this Host"); + } host.getParent().removeChild(host); } @@ -827,6 +857,7 @@ public synchronized void addAuthenticator(Authenticator authenticator, * * @param listener The listener to add */ + @Override public void addLifecycleListener(LifecycleListener listener) { lifecycle.addLifecycleListener(listener); @@ -838,6 +869,7 @@ public void addLifecycleListener(LifecycleListener listener) { * Gets the (possibly empty) list of lifecycle listeners associated * with this Embedded instance. */ + @Override public List findLifecycleListeners() { return lifecycle.findLifecycleListeners(); } @@ -848,6 +880,7 @@ public List findLifecycleListeners() { * * @param listener The listener to remove */ + @Override public void removeLifecycleListener(LifecycleListener listener) { lifecycle.removeLifecycleListener(listener); } @@ -882,9 +915,10 @@ public void start() throws LifecycleException { initNaming(); // Validate and update our current component state - if (started) + if (started) { throw new LifecycleException (rb.getString(LogFacade.SERVICE_BEEN_STARTED_EXCEPTION)); + } lifecycle.fireLifecycleEvent(START_EVENT, null); started = true; initialized = true; @@ -892,14 +926,16 @@ public void start() throws LifecycleException { // Start our defined Connectors first for (int i = 0; i < connectors.length; i++) { connectors[i].initialize(); - if (connectors[i] instanceof Lifecycle) + if (connectors[i] instanceof Lifecycle) { ((Lifecycle) connectors[i]).start(); + } } // Start our defined Engines second for (int i = 0; i < engines.length; i++) { - if (engines[i] instanceof Lifecycle) + if (engines[i] instanceof Lifecycle) { ((Lifecycle) engines[i]).start(); + } } } @@ -915,33 +951,39 @@ public void start() throws LifecycleException { @Override public void stop() throws LifecycleException { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Stopping embedded server"); + } // Validate and update our current component state - if (!started) + if (!started) { throw new LifecycleException (rb.getString(LogFacade.SERVICE_NOT_BEEN_STARTED_EXCEPTION)); + } lifecycle.fireLifecycleEvent(STOP_EVENT, null); started = false; // Stop our defined Connectors first for (int i = 0; i < connectors.length; i++) { - if (connectors[i] instanceof Lifecycle) + if (connectors[i] instanceof Lifecycle) { ((Lifecycle) connectors[i]).stop(); + } } // Stop our defined Engines second for (int i = 0; i < engines.length; i++) { - if (engines[i] instanceof Lifecycle) + if (engines[i] instanceof Lifecycle) { ((Lifecycle) engines[i]).stop(); + } } } @Override public void destroy() throws LifecycleException { - if( started ) stop(); + if( started ) { + stop(); + } if (initialized) { initialized = false; } @@ -965,35 +1007,18 @@ public void destroy() throws LifecycleException { protected void initNaming() { // Setting additional variables if (!useNaming) { - // START SJSAS 5031700 - //log.info( "Catalina naming disabled"); - if (log.isLoggable(Level.FINE)) { - log.log(Level.FINE, "Catalina naming disabled"); - } - // END SJSAS 5031700 - System.setProperty("catalina.useNaming", "false"); + log.log(Level.FINE, "Catalina naming disabled"); + setProperty("catalina.useNaming", "false", true); } else { - System.setProperty("catalina.useNaming", "true"); + setProperty("catalina.useNaming", "true", true); String value = "org.apache.naming"; - String oldValue = - System.getProperty(javax.naming.Context.URL_PKG_PREFIXES); + String oldValue = System.getProperty(URL_PKG_PREFIXES); if (oldValue != null) { value = value + ":" + oldValue; } - System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value); - if (log.isLoggable(Level.FINE)) - log.log(Level.FINE, "Setting naming prefix=" + value); - value = System.getProperty - (javax.naming.Context.INITIAL_CONTEXT_FACTORY); - if (value == null) { - System.setProperty - (javax.naming.Context.INITIAL_CONTEXT_FACTORY, - "org.apache.naming.java.javaURLContextFactory"); - } else { - if (log.isLoggable(Level.FINE)) { - log.log(Level.FINE, "INITIAL_CONTEXT_FACTORY alread set " + value); - } - } + setProperty(URL_PKG_PREFIXES, value, true); + log.log(Level.FINE, "Setting naming prefix={0}", value); + setProperty(INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory", false); } } @@ -1031,12 +1056,11 @@ protected void initDirs() { catalinaHome = home.getAbsolutePath(); } } - System.setProperty("catalina.home", catalinaHome); + setProperty("catalina.home", catalinaHome, true); } if (System.getProperty("catalina.base") == null) { - System.setProperty("catalina.base", - catalinaHome); + setProperty("catalina.base", catalinaHome, true); } else { String catalinaBase = System.getProperty("catalina.base"); File base = new File(catalinaBase); @@ -1047,7 +1071,7 @@ protected void initDirs() { catalinaBase = base.getAbsolutePath(); } } - System.setProperty("catalina.base", catalinaBase); + setProperty("catalina.base", catalinaBase, true); } } diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/startup/Tool.java b/appserver/web/web-core/src/main/java/org/apache/catalina/startup/Tool.java index f0b20b427fe..dc233d2a81f 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/startup/Tool.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/startup/Tool.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2025 Contributors to the Eclipse Foundation. * Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved. * Copyright 2004 The Apache Software Foundation * @@ -27,6 +28,7 @@ import java.util.logging.Logger; import org.apache.catalina.LogFacade; +import org.glassfish.main.jdke.props.SystemProperties; /** @@ -141,18 +143,17 @@ public static void main(String args[]) { usage(); System.exit(1); } - if ("-ant".equals(args[index])) + if ("-ant".equals(args[index])) { ant = true; - else if ("-common".equals(args[index])) + } else if ("-common".equals(args[index])) { common = true; - //else if ("-debug".equals(args[index])) - // debug = true; - else if ("-server".equals(args[index])) + } else if ("-server".equals(args[index])) { server = true; - else if ("-shared".equals(args[index])) + } else if ("-shared".equals(args[index])) { shared = true; - else + } else { break; + } index++; } if (index > args.length) { @@ -161,8 +162,9 @@ else if ("-shared".equals(args[index])) } // Set "ant.home" if requested - if (ant) - System.setProperty("ant.home", catalinaHome); + if (ant) { + SystemProperties.setProperty("ant.home", catalinaHome, true); + } // Construct the class loader we will be using ClassLoader classLoader = null; @@ -208,8 +210,9 @@ else if ("-shared".equals(args[index])) Class clazz = null; String className = args[index++]; try { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Loading application class " + className); + } clazz = classLoader.loadClass(className); } catch (Throwable t) { String msg = MessageFormat.format(rb.getString(LogFacade.CREATING_INSTANCE_EXCEPTION), @@ -223,8 +226,9 @@ else if ("-shared".equals(args[index])) String params[] = new String[args.length - index]; System.arraycopy(args, index, params, 0, params.length); try { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Identifying main() method"); + } String methodName = "main"; Class paramTypes[] = new Class[1]; paramTypes[0] = params.getClass(); @@ -236,8 +240,9 @@ else if ("-shared".equals(args[index])) // Invoke the main method of the application class try { - if (log.isLoggable(Level.FINE)) + if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Calling main() method"); + } Object paramValues[] = new Object[1]; paramValues[0] = params; method.invoke(null, paramValues); diff --git a/appserver/web/web-naming/src/main/java/org/apache/naming/NamingService.java b/appserver/web/web-naming/src/main/java/org/apache/naming/NamingService.java index ae6b0732ec3..c2b8dc57750 100644 --- a/appserver/web/web-naming/src/main/java/org/apache/naming/NamingService.java +++ b/appserver/web/web-naming/src/main/java/org/apache/naming/NamingService.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2025 Contributors to the Eclipse Foundation. * Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved. * Copyright 2004 The Apache Software Foundation * @@ -28,13 +29,14 @@ import javax.management.ObjectName; import javax.naming.Context; +import org.glassfish.main.jdke.props.SystemProperties; + /** * Implementation of the NamingService JMX MBean. * * @author Remy Maucherat * @version $Revision: 1.3 $ */ - public final class NamingService extends NotificationBroadcasterSupport implements NamingServiceMBean, MBeanRegistration { @@ -66,23 +68,28 @@ public final class NamingService // ---------------------------------------------- MBeanRegistration Methods + @Override public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { return new ObjectName(OBJECT_NAME); } + @Override public void postRegister(Boolean registrationDone) { - if (!registrationDone.booleanValue()) + if (!registrationDone.booleanValue()) { destroy(); + } } + @Override public void preDeregister() throws Exception { } + @Override public void postDeregister() { destroy(); } @@ -94,6 +101,7 @@ public void postDeregister() { /** * Retruns the Catalina component name. */ + @Override public String getName() { return NAME; } @@ -102,6 +110,7 @@ public String getName() { /** * Returns the state. */ + @Override public State getState() { return state; } @@ -112,41 +121,38 @@ public State getState() { /** * Start the servlet container. */ + @Override public void start() throws Exception { Notification notification = null; - if (state != State.STOPPED) + if (state != State.STOPPED) { return; + } state = State.STARTING; // Notifying the MBEan server that we're starting - - notification = new AttributeChangeNotification - (this, sequenceNumber++, System.currentTimeMillis(), - "Starting " + NAME, "State", "org.apache.naming.NamingServiceMBean$State", - State.STOPPED, State.STARTING); + notification = new AttributeChangeNotification(this, sequenceNumber++, System.currentTimeMillis(), + "Starting " + NAME, "State", "org.apache.naming.NamingServiceMBean$State", State.STOPPED, State.STARTING); sendNotification(notification); try { - String value = "org.apache.naming"; String oldValue = System.getProperty(Context.URL_PKG_PREFIXES); if (oldValue != null) { oldUrlValue = oldValue; value = oldValue + ":" + value; } - System.setProperty(Context.URL_PKG_PREFIXES, value); + SystemProperties.setProperty(Context.URL_PKG_PREFIXES, value, true); oldValue = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); if (oldValue != null) { oldIcValue = oldValue; } else { - System.setProperty(Context.INITIAL_CONTEXT_FACTORY, - Constants.Package - + ".java.javaURLContextFactory"); + SystemProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, + Constants.Package + ".java.javaURLContextFactory", true); } } catch (Throwable t) { @@ -171,12 +177,14 @@ public void start() /** * Stop the servlet container. */ + @Override public void stop() { Notification notification = null; - if (state != State.STARTED) + if (state != State.STARTED) { return; + } state = State.STOPPING; @@ -187,8 +195,8 @@ public void stop() { sendNotification(notification); try { - System.setProperty(Context.URL_PKG_PREFIXES, oldUrlValue); - System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldIcValue); + SystemProperties.setProperty(Context.URL_PKG_PREFIXES, oldUrlValue, true); + SystemProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldIcValue, true); } catch (Throwable t) { log.log(Level.WARNING, LogFacade.UNABLE_TO_RESTORE_ORIGINAL_SYS_PROPERTIES, t); } @@ -207,10 +215,12 @@ public void stop() { /** * Destroy servlet container (if any is running). */ + @Override public void destroy() { - if (getState() != State.STOPPED) + if (getState() != State.STOPPED) { stop(); + } } diff --git a/appserver/web/web-naming/src/main/java/org/apache/naming/resources/DirContextURLStreamHandler.java b/appserver/web/web-naming/src/main/java/org/apache/naming/resources/DirContextURLStreamHandler.java index bbc8bd83828..10f6c1dc700 100644 --- a/appserver/web/web-naming/src/main/java/org/apache/naming/resources/DirContextURLStreamHandler.java +++ b/appserver/web/web-naming/src/main/java/org/apache/naming/resources/DirContextURLStreamHandler.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2025 Contributors to the Eclipse Foundation. * Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved. * Copyright 2004 The Apache Software Foundation * @@ -25,6 +26,8 @@ import javax.naming.directory.DirContext; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; + /** * Stream handler to a JNDI directory context. * @@ -83,11 +86,13 @@ public DirContextURLStreamHandler(DirContext context) { * Opens a connection to the object referenced by the URL * argument. */ + @Override protected URLConnection openConnection(URL u) throws IOException { DirContext currentContext = this.context; - if (currentContext == null) + if (currentContext == null) { currentContext = get(); + } return new DirContextURLConnection(currentContext, u); } @@ -102,10 +107,10 @@ public static void setProtocolHandler() { String value = System.getProperty(Constants.PROTOCOL_HANDLER_VARIABLE); if (value == null) { value = Constants.Package; - System.setProperty(Constants.PROTOCOL_HANDLER_VARIABLE, value); + setProperty(Constants.PROTOCOL_HANDLER_VARIABLE, value, true); } else if (value.indexOf(Constants.Package) == -1) { value += "|" + Constants.Package; - System.setProperty(Constants.PROTOCOL_HANDLER_VARIABLE, value); + setProperty(Constants.PROTOCOL_HANDLER_VARIABLE, value, true); } } @@ -125,10 +130,10 @@ public static boolean isBound() { * Binds a directory context to a class loader. */ public static void bind(DirContext dirContext) { - ClassLoader currentCL = - Thread.currentThread().getContextClassLoader(); - if (currentCL != null) + ClassLoader currentCL = Thread.currentThread().getContextClassLoader(); + if (currentCL != null) { clBindings.put(currentCL, dirContext); + } } @@ -138,8 +143,9 @@ public static void bind(DirContext dirContext) { public static void unbind() { ClassLoader currentCL = Thread.currentThread().getContextClassLoader(); - if (currentCL != null) + if (currentCL != null) { clBindings.remove(currentCL); + } } @@ -171,8 +177,9 @@ public static DirContext get() { // Checking CL binding result = clBindings.get(currentCL); - if (result != null) + if (result != null) { return result; + } // Checking thread biding result = threadBindings.get(currentThread); @@ -181,13 +188,15 @@ public static DirContext get() { currentCL = currentCL.getParent(); while (currentCL != null) { result = clBindings.get(currentCL); - if (result != null) + if (result != null) { return result; + } currentCL = currentCL.getParent(); } - if (result == null) + if (result == null) { throw new IllegalStateException("Illegal class loader binding"); + } return result; @@ -238,6 +247,7 @@ public static DirContext get(Thread thread) { * @param u the URL. * @return a string representation of the URL argument. */ + @Override protected String toExternalForm(URL u) { // pre-compute length of StringBuilder @@ -248,8 +258,9 @@ protected String toExternalForm(URL u) { if (u.getQuery() != null) { len += 1 + u.getQuery().length(); } - if (u.getRef() != null) + if (u.getRef() != null) { len += 1 + u.getRef().length(); + } StringBuilder result = new StringBuilder(len); result.append(u.getProtocol()); diff --git a/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/monitoring/WebServiceTesterServlet.java b/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/monitoring/WebServiceTesterServlet.java index 9c16b5d436c..d10730ccc21 100644 --- a/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/monitoring/WebServiceTesterServlet.java +++ b/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/monitoring/WebServiceTesterServlet.java @@ -58,6 +58,7 @@ import org.glassfish.jaxb.runtime.api.JAXBRIContext; import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; +import org.glassfish.main.jdke.props.SystemProperties; import org.glassfish.webservices.LogUtils; import org.glassfish.webservices.WebServiceContractImpl; @@ -597,7 +598,7 @@ private String wsImport(URL wsdlLocation) throws IOException { } // Metro uses the System.getProperty(java.class.path) to pass on to javac during wsimport - String oldCP = System.getProperty("java.class.path"); + final String oldCP = System.getProperty("java.class.path"); try { WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance(); ModulesRegistry modulesRegistry = wscImpl.getModulesRegistry(); @@ -607,7 +608,7 @@ private String wsImport(URL wsdlLocation) throws IOException { ModuleDefinition md = m.getModuleDefinition(); classpath1+=(File.pathSeparator + new File(md.getLocations()[0]).getAbsolutePath()); } - System.setProperty("java.class.path", classpath1); + SystemProperties.setProperty("java.class.path", classpath1, true); String[] wsimportArgs = new String[7]; wsimportArgs[0] = "-d"; @@ -629,12 +630,7 @@ private String wsImport(URL wsdlLocation) throws IOException { } } finally { - //reset property value - if (oldCP == null) { - System.clearProperty("java.class.path"); - } else { - System.setProperty("java.class.path", oldCP); - } + SystemProperties.setProperty("java.class.path", oldCP, true); } return classesDir.getAbsolutePath(); } diff --git a/nucleus/admin/cli/src/main/java/com/sun/enterprise/admin/cli/AdminMain.java b/nucleus/admin/cli/src/main/java/com/sun/enterprise/admin/cli/AdminMain.java index abca8dfe224..d1ec5777bf8 100644 --- a/nucleus/admin/cli/src/main/java/com/sun/enterprise/admin/cli/AdminMain.java +++ b/nucleus/admin/cli/src/main/java/com/sun/enterprise/admin/cli/AdminMain.java @@ -66,6 +66,7 @@ import static org.glassfish.embeddable.GlassFishVariable.CONFIG_ROOT; import static org.glassfish.embeddable.GlassFishVariable.INSTALL_ROOT; import static org.glassfish.embeddable.GlassFishVariable.PRODUCT_ROOT; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * The admin main program (nadmin). @@ -92,7 +93,7 @@ public class AdminMain { for (String prop : SYS_PROPERTIES_TO_SET_FROM_ASENV) { String val = systemProps.get(prop); if (isNotEmpty(val)) { - System.setProperty(prop, val); + setProperty(prop, val, true); } } } @@ -190,7 +191,7 @@ protected final int doMain(String[] args) { return ERROR; } - System.setProperty(WALL_CLOCK_START_PROP, Instant.now().toString()); + setProperty(WALL_CLOCK_START_PROP, Instant.now().toString(), true); final LoggingProperties logging = new LoggingProperties(); logging.setProperty("handlers", BlockingExternallyManagedLogHandler.class.getName()); if (isClassAndMethodDetectionRequired()) { diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartDomainCommand.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartDomainCommand.java index c1a03a8f8df..41ab90a57ea 100644 --- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartDomainCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartDomainCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -52,6 +52,7 @@ import static com.sun.enterprise.admin.cli.CLIConstants.WALL_CLOCK_START_PROP; import static java.util.logging.Level.FINER; import static org.glassfish.api.admin.RuntimeType.DAS; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * The start-domain command. @@ -178,7 +179,7 @@ protected int executeCommand() throws CommandException { } if (env.debug()) { - System.setProperty(WALL_CLOCK_START_PROP, "" + System.currentTimeMillis()); + setProperty(WALL_CLOCK_START_PROP, Long.toString(System.currentTimeMillis()), true); } glassFishLauncher.relaunch(); diff --git a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/NativeRemoteCommandsBase.java b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/NativeRemoteCommandsBase.java index ee74ffcccdb..a1936454716 100644 --- a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/NativeRemoteCommandsBase.java +++ b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/NativeRemoteCommandsBase.java @@ -38,6 +38,7 @@ import org.glassfish.internal.api.RelativePathResolver; import static org.glassfish.embeddable.GlassFishVariable.INSTANCE_ROOT; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * Base class for SSH provisioning commands. @@ -188,8 +189,8 @@ String expandPasswordAlias(String host, String alias, boolean verifyConn) { // get the list of domains File[] files = domainsDirFile.listFiles(File::isDirectory); for (File f : files) { - //the following property is required for initializing the password helper - System.setProperty(INSTANCE_ROOT.getSystemPropertyName(), f.getAbsolutePath()); + // the following property is required for initializing the password helper + setProperty(INSTANCE_ROOT.getSystemPropertyName(), f.getAbsolutePath(), true); try { final PasswordAdapter pa = new PasswordAdapter(null); final boolean exists = pa.aliasExists(alias); diff --git a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/StartLocalInstanceCommand.java b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/StartLocalInstanceCommand.java index 9f73bdd9761..037b767f676 100644 --- a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/StartLocalInstanceCommand.java +++ b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/StartLocalInstanceCommand.java @@ -43,6 +43,7 @@ import static com.sun.enterprise.admin.cli.CLIConstants.RESTART_DEBUG_OFF; import static com.sun.enterprise.admin.cli.CLIConstants.RESTART_DEBUG_ON; import static com.sun.enterprise.admin.cli.CLIConstants.RESTART_NORMAL; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * Start a local server instance. @@ -164,8 +165,7 @@ protected int executeCommand() throws CommandException { } if (env.debug()) { - System.setProperty(CLIConstants.WALL_CLOCK_START_PROP, - "" + System.currentTimeMillis()); + setProperty(CLIConstants.WALL_CLOCK_START_PROP, Long.toString(System.currentTimeMillis()), true); } getLauncher().relaunch(); } diff --git a/nucleus/common/amx-core/src/test/java/org/glassfish/admin/amx/test/AmxTestExtension.java b/nucleus/common/amx-core/src/test/java/org/glassfish/admin/amx/test/AmxTestExtension.java index 3fa17a955d3..428495298e3 100644 --- a/nucleus/common/amx-core/src/test/java/org/glassfish/admin/amx/test/AmxTestExtension.java +++ b/nucleus/common/amx-core/src/test/java/org/glassfish/admin/amx/test/AmxTestExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation. + * Copyright (c) 2021, 2025 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 @@ -22,6 +22,7 @@ import org.junit.jupiter.api.extension.ExtensionContext; import static org.glassfish.embeddable.GlassFishVariable.INSTANCE_ROOT; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; public final class AmxTestExtension implements BeforeAllCallback, AfterAllCallback { @@ -29,13 +30,13 @@ public final class AmxTestExtension implements BeforeAllCallback, AfterAllCallba @Override public void beforeAll(ExtensionContext context) { checkAssertsOn(); - System.setProperty(INSTANCE_ROOT.getSystemPropertyName(), "/tmp/amx-test"); + setProperty(INSTANCE_ROOT.getSystemPropertyName(), "/tmp/amx-test", true); } @Override public void afterAll(ExtensionContext context) { - System.clearProperty(INSTANCE_ROOT.getSystemPropertyName()); + setProperty(INSTANCE_ROOT.getSystemPropertyName(), null, true); } diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/GFSystem.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/GFSystem.java deleted file mode 100644 index f3a720e30c2..00000000000 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/GFSystem.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2008, 2018 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 - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package com.sun.enterprise.universal.glassfish; - -import java.util.Map; - -/** - * A replacement for System Properties - * An InheritableThreadLocal is used to store the "impl". This means that the - * initial thread that uses this class -- and all its sub-threads will get the - * same System Properties. - * Make sure that you don't create it from the main Thread -- otherwise all instances - * will get the same props. - * E.g. - * main thread creates instance1-thread and instance2-thread - * The 2 created threads should each call init() -- but the main thread should not. - * In the usual case where there is just one instance in the JVM -- this class is also - * perfectly usable. Just call any method when you need something. - * - * @author bnevins - */ -public final class GFSystem { - public final static void init() { - // forces creation - getProperty("java.lang.separator"); - } - - /** - * Get the GFSystem Properties - * @return a snapshot copy of the dcurrent Properties - */ - public final static Map getProperties() - { - return gfsi.get().getProperties(); - } - - /** - * Get a GF System Property - * @param key the name of the property - * @return the value of the property - */ - public final static String getProperty(String key) - { - return gfsi.get().getProperty(key); - } - - /** - * Set a GF System Property, null is acceptable for the name and/or value. - * @param key the name of the property - * @param value the value of the property - */ - public final static void setProperty(String key, String value) - { - gfsi.get().setProperty(key, value); - } - - private static final InheritableThreadLocal gfsi = - new InheritableThreadLocal() { - @Override - protected GFSystemImpl initialValue() { - return new GFSystemImpl(); - } - }; -} diff --git a/nucleus/common/common-util/src/main/java/org/glassfish/server/ServerEnvironmentImpl.java b/nucleus/common/common-util/src/main/java/org/glassfish/server/ServerEnvironmentImpl.java index ebcd594fa3b..993ab9ec567 100644 --- a/nucleus/common/common-util/src/main/java/org/glassfish/server/ServerEnvironmentImpl.java +++ b/nucleus/common/common-util/src/main/java/org/glassfish/server/ServerEnvironmentImpl.java @@ -31,6 +31,7 @@ import org.glassfish.api.admin.RuntimeType; import org.glassfish.api.admin.ServerEnvironment; +import org.glassfish.main.jdke.props.SystemProperties; import org.jvnet.hk2.annotations.Service; import static org.glassfish.embeddable.GlassFishVariable.INSTALL_ROOT; @@ -148,7 +149,7 @@ public void postConstruct() { if (entry.getValue() == null) { continue; } - System.setProperty(entry.getKey(), entry.getValue()); + SystemProperties.setProperty(entry.getKey(), entry.getValue(), true); } Properties args = startupContext.getArguments(); @@ -165,15 +166,10 @@ public void postConstruct() { domainName = s; s = args.getProperty("-instancename"); + instanceName = isNotEmpty(s) ? s : "server"; - if (!isNotEmpty(s)) { - instanceName = "server"; - } else { - instanceName = s; - } - // bnevins IT 10209 asenv.getProps().put(SystemPropertyConstants.SERVER_NAME, instanceName); - System.setProperty(SystemPropertyConstants.SERVER_NAME, instanceName); + SystemProperties.setProperty(SystemPropertyConstants.SERVER_NAME, instanceName, true); // bnevins Apr 2010 adding clustering support... String typeString = args.getProperty("-type"); @@ -340,6 +336,7 @@ public void setStatus(Status status) { this.status = status; } + @Override public boolean isEmbedded() { return serverType == RuntimeType.EMBEDDED; } diff --git a/nucleus/common/common-util/src/test/java/com/sun/enterprise/universal/glassfish/GFSystemTest.java b/nucleus/common/common-util/src/test/java/com/sun/enterprise/universal/glassfish/GFSystemTest.java deleted file mode 100644 index 3628ba5ec11..00000000000 --- a/nucleus/common/common-util/src/test/java/com/sun/enterprise/universal/glassfish/GFSystemTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2021 Contributors to the Eclipse Foundation - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package com.sun.enterprise.universal.glassfish; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertFalse; - -/** - * - * @author bnevins - */ -public class GFSystemTest { - - public static volatile boolean failed = false; - - /** - * Test of GFSystem for the case where there are multiple instances in a JVM - */ - @Test - public void threadTest() { - try { - Thread t1 = new ParentThread("xxx"); - Thread t2 = new ParentThread("yyy"); - Thread t3 = new ParentThread("zzz"); - t1.start(); - t2.start(); - t3.start(); - t1.join(); - t2.join(); - t3.join(); - } catch (InterruptedException ex) { - Logger.getLogger(GFSystemTest.class.getName()).log(Level.SEVERE, null, ex); - } - assertFalse(failed); - } - public static synchronized void setFailure() { - failed = true; - } -} - -class ParentThread extends Thread { - ParentThread(String name) { - super(name); - } - @Override - public void run() { - try { - GFSystem.setProperty("foo", getName()); - Thread t = new ChildThread(getName(), getName() + "__child"); - t.start(); - String result = GFSystem.getProperty("foo"); - - if (result.equals(getName())) { - } else { - GFSystemTest.setFailure(); - } - t.join(); - } catch (InterruptedException ex) { - } - } -} - - -class ChildThread extends Thread { - String parentName; - ChildThread(String parentName, String name) { - super(name); - this.parentName = parentName; - } - @Override - public void run() { - try { - Thread t = new GrandChildThread(parentName, getName() + "__grandchild"); - t.start(); - String result = GFSystem.getProperty("foo"); - - if (result.equals(parentName)) { - } else { - GFSystemTest.setFailure(); - } - t.join(); - } catch (InterruptedException ex) { - Logger.getLogger(ChildThread.class.getName()).log(Level.SEVERE, null, ex); - } - } -} - -class GrandChildThread extends Thread { - String grandParentName; - GrandChildThread(String grandParentName, String name) { - super(name); - this.grandParentName = grandParentName; - } - @Override - public void run() { - String result = GFSystem.getProperty("foo"); - - if(!result.equals(grandParentName)) { - GFSystemTest.setFailure(); - } - } -} diff --git a/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/props/SystemProperties.java b/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/props/SystemProperties.java new file mode 100644 index 00000000000..941f32a8b79 --- /dev/null +++ b/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/props/SystemProperties.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ +package org.glassfish.main.jdke.props; + +import java.lang.System.Logger; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.TRACE; +import static java.lang.System.Logger.Level.WARNING; + +/** + * Extension for {@link System#setProperties(java.util.Properties)} and methods around. + */ +public final class SystemProperties { + private static final Logger LOG = System.getLogger(SystemProperties.class.getName()); + + private SystemProperties() { + // hidden + } + + + /** + * Sets a system property, logging the action. + * + * @param key must not be null. + * @param value if null, will remove the property + * @param force if false, will not override an existing property with the same key + * @return the old value of the property, or null if it was not set before + */ + public static String setProperty(String key, String value, boolean force) { + final String oldValue = executePrivilegedAction(() -> System.getProperty(key)); + if (oldValue == null) { + LOG.log(DEBUG, "Setting property {0} to {1}", key, value); + } else { + if (oldValue.equals(value)) { + LOG.log(TRACE, "Property {0} already set to the same value {1}", key, oldValue); + return oldValue; + } + if (force) { + LOG.log(WARNING, "Property {0} already set to {1}, overriding with {2}", key, oldValue, value); + } else { + LOG.log(WARNING, "Property {0} already set to {1}, not overriding with {2}", key, oldValue, value); + return oldValue; + } + } + executePrivilegedAction(value == null ? () -> System.clearProperty(key) : () -> System.setProperty(key, value)); + return oldValue; + } + + + private static String executePrivilegedAction(PrivilegedAction action) { + return AccessController.doPrivileged(action); + } +} diff --git a/nucleus/common/mbeanserver/src/main/java/org/glassfish/admin/mbeanserver/RMIConnectorStarter.java b/nucleus/common/mbeanserver/src/main/java/org/glassfish/admin/mbeanserver/RMIConnectorStarter.java index c080db408a5..03fb7203051 100644 --- a/nucleus/common/mbeanserver/src/main/java/org/glassfish/admin/mbeanserver/RMIConnectorStarter.java +++ b/nucleus/common/mbeanserver/src/main/java/org/glassfish/admin/mbeanserver/RMIConnectorStarter.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2023, 2025 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2023 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -58,6 +58,8 @@ import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.logging.annotation.LogMessageInfo; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; + /** * This class configures and starts the JMX RMI connector server using rmi_jrmp protocol. * SSL support for connections to the JMX connector are supported. This is achieved @@ -172,15 +174,15 @@ private static InetAddress getAddress(final String addrSpec) } static String setupRMIHostname(final String host) { - return System.setProperty(RMI_HOSTNAME_PROP, host); + return setProperty(RMI_HOSTNAME_PROP, host, true); } private static void restoreRMIHostname(final String saved, final String expectedValue) { if (saved == null) { - System.clearProperty(RMI_HOSTNAME_PROP); + setProperty(RMI_HOSTNAME_PROP, null, true); } else { - final String temp = System.setProperty(RMI_HOSTNAME_PROP, saved); + final String temp = setProperty(RMI_HOSTNAME_PROP, saved, true); // check that it didn't change since the last setup if (!temp.equals(expectedValue)) { throw new IllegalStateException("Something changed " + RMI_HOSTNAME_PROP + " to " + temp); @@ -188,10 +190,6 @@ private static void restoreRMIHostname(final String saved, } } - private static void debug(final Object o) { - System.out.println("" + o); - } - /** * Starts the RMI Registry , where the RMIServer would be exported. If this * is a multihomed machine then the Registry is bound to a specific IP address @@ -230,13 +228,12 @@ private Registry startRegistry(final String addr, final int port) { private Registry _startRegistry(final int port) { // Ensure cryptographically strong random number generator used // to choose the object number - see java.rmi.server.ObjID - System.setProperty("java.rmi.server.randomIDs", "true"); + setProperty("java.rmi.server.randomIDs", "true", true); try { if (isSecurityEnabled()) { return LocateRegistry.createRegistry(port, sslCsf, sslServerSocketFactory); - } else { - return LocateRegistry.createRegistry(port, null, mServerSocketFactory); } + return LocateRegistry.createRegistry(port, null, mServerSocketFactory); } catch (final Exception e) { throw new RuntimeException("Port " + port + " is not available for the internal rmi registry. " + "This means that a call was made with the same port, without closing earlier " + @@ -318,8 +315,6 @@ public void stopAndUnexport() { } UnicastRemoteObject.unexportObject(mRegistry, true); } catch (RemoteException ex) { - - Util.getLogger().log(Level.SEVERE, ERROR_STOPPING, ex); } catch (NotBoundException ex) { Util.getLogger().log(Level.SEVERE, ERROR_STOPPING, ex); @@ -346,20 +341,20 @@ private SslRMIClientSocketFactory getClientSocketFactory(Ssl sslConfig) { String enabledProtocols = sslCC.getEnabledProtocolsAsString(); if (enabledProtocols != null) { - System.setProperty("javax.rmi.ssl.client.enabledProtocols", enabledProtocols); + setProperty("javax.rmi.ssl.client.enabledProtocols", enabledProtocols, true); } String enabledCipherSuites = sslCC.getEnabledCipherSuitesAsString(); if (enabledCipherSuites != null) { - System.setProperty("javax.rmi.ssl.client.enabledCipherSuites", enabledCipherSuites); + setProperty("javax.rmi.ssl.client.enabledCipherSuites", enabledCipherSuites, true); } // The keystore and truststore locations are already available as System properties // Hence we just add the passwords - System.setProperty("javax.net.ssl.keyStorePassword", - sslParams.getKeyStorePassword() == null ? "changeit" : sslParams.getKeyStorePassword()); - System.setProperty("javax.net.ssl.trustStorePassword", - sslParams.getTrustStorePassword() == null ? "changeit" : sslParams.getTrustStorePassword()); + setProperty("javax.net.ssl.keyStorePassword", + sslParams.getKeyStorePassword() == null ? "changeit" : sslParams.getKeyStorePassword(), true); + setProperty("javax.net.ssl.trustStorePassword", + sslParams.getTrustStorePassword() == null ? "changeit" : sslParams.getTrustStorePassword(), true); SslRMIClientSocketFactory sslRMICsf = new SslRMIClientSocketFactory(); return sslRMICsf; diff --git a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishVariable.java b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishVariable.java index 53ab82e77a9..d98c2bfe69b 100644 --- a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishVariable.java +++ b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishVariable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Contributors to the Eclipse Foundation. + * Copyright (c) 2024, 2025 Contributors to the Eclipse Foundation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -102,6 +102,12 @@ public String getSystemPropertyName() { } + /** + * The map contains pairs of {@link #getEnvName()} and {@link #getSystemPropertyName()}. + * When the {@link #getEnvName()} returns null, the mapping is not included. + * + * @return a mapping of environment variable names to system property names. + */ public static Map getEnvToSystemPropertyMapping() { return Arrays.stream(GlassFishVariable.values()) .filter(m -> m.getEnvName() != null && m.getSystemPropertyName() != null) diff --git a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntime.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntime.java index 75e1e912ab3..c2c28b13105 100644 --- a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntime.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2025 Contributors to the Eclipse Foundation * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -53,6 +53,7 @@ import static java.util.logging.Level.WARNING; import static org.glassfish.embeddable.GlassFishVariable.INSTALL_ROOT; import static org.glassfish.embeddable.GlassFishVariable.INSTANCE_ROOT; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * The {@link GlassFishRuntime} implementation for non-OSGi environments. @@ -137,8 +138,8 @@ private void setEnv(GlassFishProperties gfProps) throws Exception { } File instanceRoot = new File(instanceRootValue); - System.setProperty(INSTANCE_ROOT.getSystemPropertyName(), instanceRoot.getAbsolutePath()); - System.setProperty(BootstrapKeys.INSTANCE_ROOT_URI_PROP_NAME, instanceRoot.toURI().toString()); + setProperty(INSTANCE_ROOT.getSystemPropertyName(), instanceRoot.getAbsolutePath(), true); + setProperty(BootstrapKeys.INSTANCE_ROOT_URI_PROP_NAME, instanceRoot.toURI().toString(), true); String installRootValue = System.getProperty("org.glassfish.embeddable.installRoot"); if (installRootValue == null) { @@ -152,8 +153,8 @@ private void setEnv(GlassFishProperties gfProps) throws Exception { // Some legacy code might depend on setting installRoot as system property. // Ideally everyone should depend only on StartupContext. - System.setProperty(INSTALL_ROOT.getSystemPropertyName(), installRoot.getAbsolutePath()); - System.setProperty(BootstrapKeys.INSTALL_ROOT_URI_PROP_NAME, installRoot.toURI().toString()); + setProperty(INSTALL_ROOT.getSystemPropertyName(), installRoot.getAbsolutePath(), true); + setProperty(BootstrapKeys.INSTALL_ROOT_URI_PROP_NAME, installRoot.toURI().toString(), true); // StartupContext requires the installRoot to be set in the GlassFishProperties. gfProps.setProperty(INSTALL_ROOT.getPropertyName(), installRoot.getAbsolutePath()); diff --git a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntimeBuilder.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntimeBuilder.java index 5c05977d94d..d4406f6064e 100644 --- a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntimeBuilder.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntimeBuilder.java @@ -40,6 +40,7 @@ import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; import static org.glassfish.embeddable.GlassFishVariable.OSGI_PLATFORM; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * @author bhavanishankar@dev.java.net @@ -75,7 +76,7 @@ public GlassFishRuntime build(BootstrapProperties bsProps, ClassLoader cl) throw private GlassFishRuntime build(BootstrapProperties bsProps, ClassLoader cl, String installRoot) { if (installRoot != null) { - System.setProperty("org.glassfish.embeddable.installRoot", installRoot); + setProperty("org.glassfish.embeddable.installRoot", installRoot, true); } SingleHK2Factory.initialize(cl); ModulesRegistry modulesRegistry = AbstractFactory.getInstance().createModulesRegistry(); diff --git a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/JarUtil.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/JarUtil.java index e3dda055b75..da87547982b 100644 --- a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/JarUtil.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/JarUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -28,6 +28,7 @@ import java.util.logging.Logger; import org.glassfish.main.boot.log.LogFacade; +import org.glassfish.main.jdke.props.SystemProperties; import static org.glassfish.embeddable.GlassFishVariable.IMQ_LIB; @@ -100,7 +101,7 @@ public static boolean extractRars(String installDir) { public static void setEnv(String installDir) { String location = getSystemModuleLocation(installDir, DEFAULT_JMS_ADAPTER); String imqLib = System.getProperty(IMQ_LIB.getSystemPropertyName(), location); - System.setProperty(IMQ_LIB.getSystemPropertyName(), imqLib); + SystemProperties.setProperty(IMQ_LIB.getSystemPropertyName(), imqLib, true); } private static boolean extractRar(String installDir, String rarName) { diff --git a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntime.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntime.java index a3c29d86e03..b93b943b583 100644 --- a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntime.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntime.java @@ -68,6 +68,7 @@ import static org.glassfish.embeddable.GlassFishVariable.INSTANCE_ROOT; import static org.glassfish.embeddable.GlassFishVariable.JAVA_ROOT; import static org.glassfish.embeddable.GlassFishVariable.NODES_ROOT; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * Implementation of GlassFishRuntime in an OSGi environment. @@ -244,16 +245,16 @@ private void setEnv(Properties bootstrapProperties) { File installRoot = new File(installRootValue); new EnvToPropsConverter(installRoot.toPath()).convert(pairs).entrySet() - .forEach(e -> System.setProperty(e.getKey(), e.getValue().getPath())); - System.setProperty(INSTALL_ROOT.getSystemPropertyName(), installRootValue); - System.setProperty(INSTALL_ROOT_URI_PROP_NAME, installRoot.toURI().toString()); + .forEach(e -> setProperty(e.getKey(), e.getValue().getPath(), true)); + setProperty(INSTALL_ROOT.getSystemPropertyName(), installRootValue, true); + setProperty(INSTALL_ROOT_URI_PROP_NAME, installRoot.toURI().toString(), true); } final String instanceRootValue = bootstrapProperties.getProperty(INSTANCE_ROOT.getPropertyName()); if (instanceRootValue != null && !instanceRootValue.isEmpty()) { File instanceRoot = new File(instanceRootValue); - System.setProperty(INSTANCE_ROOT.getSystemPropertyName(), instanceRootValue); - System.setProperty(INSTANCE_ROOT_URI_PROP_NAME, instanceRoot.toURI().toString()); + setProperty(INSTANCE_ROOT.getSystemPropertyName(), instanceRootValue, true); + setProperty(INSTANCE_ROOT_URI_PROP_NAME, instanceRoot.toURI().toString(), true); } } diff --git a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java index cd448b658f8..48565dcb066 100644 --- a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java @@ -30,6 +30,7 @@ import org.osgi.framework.BundleReference; import static org.glassfish.embeddable.GlassFishVariable.OSGI_PLATFORM; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * This {@link org.glassfish.embeddable.spi.RuntimeBuilder} is responsible for setting up a {@link GlassFishRuntime} @@ -66,9 +67,7 @@ public GlassFishRuntime build(BootstrapProperties bsProps, ClassLoader classload } private void configureBundles(BootstrapProperties bsProps) { - if (System.getProperty(OSGI_PLATFORM.getSystemPropertyName()) == null) { - System.setProperty(OSGI_PLATFORM.getSystemPropertyName(), OsgiPlatform.Embedded.name()); - } + setProperty(OSGI_PLATFORM.getSystemPropertyName(), OsgiPlatform.Embedded.name(), false); } private void provisionBundles(BootstrapProperties bsProps, ClassLoader classloader) { diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java index 9461c40faa6..8c73d10186a 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java @@ -38,6 +38,7 @@ import static java.util.logging.Level.SEVERE; import static org.glassfish.embeddable.GlassFishVariable.DOMAINS_ROOT; import static org.glassfish.embeddable.GlassFishVariable.OSGI_PLATFORM; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * @author Sanjeeb.Sahoo@Sun.COM @@ -54,7 +55,7 @@ public static void main(final String[] args) { final String platformName = whichPlatform(); // Set the system property to allow downstream code to know the platform on which GlassFish runs. - System.setProperty(OSGI_PLATFORM.getPropertyName(), platformName); + setProperty(OSGI_PLATFORM.getPropertyName(), platformName, true); final OsgiPlatform platform = OsgiPlatform.valueOf(platformName); STDOUT.println("Launching GlassFish on " + platform + " platform"); diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/listener/CombinedJavaConfigSystemPropertyListener.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/listener/CombinedJavaConfigSystemPropertyListener.java index 43eb3a69bd3..ab872718122 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/listener/CombinedJavaConfigSystemPropertyListener.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/listener/CombinedJavaConfigSystemPropertyListener.java @@ -56,6 +56,8 @@ import org.jvnet.hk2.config.UnprocessedChangeEvents; import org.jvnet.hk2.config.types.Property; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; + /** * Listens for the changes to the configuration of JVM and Java system * properties (including the Java VM options). Most of the effort involves the jvm-options @@ -339,7 +341,7 @@ private List getNotProcessed( final String name = nv[0]; if (possiblyDynamicallyReconfigurable(removed)) { - System.clearProperty(stripPrefix(name)); + setProperty(stripPrefix(name), null, true); } else { // detect a removal/addition which is really a change @@ -369,7 +371,7 @@ private List getNotProcessed( final String newValue = nv[1]; if (possiblyDynamicallyReconfigurable(added)) { - System.setProperty( stripPrefix(name), newValue ); + setProperty(stripPrefix(name), newValue, true); } else { reasons.add( "Addition of: '" + added + "' cannot take effect without server restart" ); @@ -401,8 +403,9 @@ private static String toString( final List items ) { */ private boolean possiblyDynamicallyReconfigurable(String s) { if (s.startsWith(DPREFIX) && !s.startsWith("-Djava.") - && !s.startsWith("-Djavax.")) + && !s.startsWith("-Djavax.")) { return true; + } return false; } @@ -414,8 +417,9 @@ private boolean possiblyDynamicallyReconfigurable(String s) { static private boolean referencesProperty(String pname, Collection values) { String ref = "${" + pname + "}"; for (String v : values) { - if ((v != null) && (v.contains(ref))) + if ((v != null) && (v.contains(ref))) { return true; + } } return false; } @@ -427,30 +431,36 @@ static private boolean referencesProperty(String pname, Collection value */ private NotProcessed removeFromServer(SystemProperty sp) { SystemProperty sysProp = getServerSystemProperty(sp.getName()); - if (sysProp == null) + if (sysProp == null) { sysProp = getClusterSystemProperty(sp.getName()); - if (sysProp == null) + } + if (sysProp == null) { sysProp = getConfigSystemProperty(sp.getName()); - if (sysProp == null) + } + if (sysProp == null) { sysProp = getDomainSystemProperty(sp.getName()); + } if (sysProp == null) { - System.clearProperty(sp.getName()); + setProperty(sp.getName(), null, true); } else { - System.setProperty(sysProp.getName(), sysProp.getValue()); + setProperty(sysProp.getName(), sysProp.getValue(), true); } return null; //processed } private NotProcessed removeFromCluster(SystemProperty sp) { SystemProperty sysProp = getConfigSystemProperty(sp.getName()); - if (sysProp == null) + if (sysProp == null) { sysProp = getDomainSystemProperty(sp.getName()); + } if (sysProp == null) { - if (!serverHas(sp)) - System.clearProperty(sp.getName()); //if server overrides it anyway, this should be a noop + if (!serverHas(sp)) { + setProperty(sp.getName(), null, true); //if server overrides it anyway, this should be a noop + } } else { - if (!serverHas(sp)) - System.setProperty(sysProp.getName(), sysProp.getValue()); + if (!serverHas(sp)) { + setProperty(sysProp.getName(), sysProp.getValue(), true); + } } return null; //processed } @@ -458,41 +468,47 @@ private NotProcessed removeFromCluster(SystemProperty sp) { private NotProcessed removeFromConfig(SystemProperty sp) { SystemProperty sysProp = getDomainSystemProperty(sp.getName()); if (sysProp == null) { - if (!serverHas(sp) && !clusterHas(sp)) - System.clearProperty(sp.getName()); //if server overrides it anyway, this should be a noop + if (!serverHas(sp) && !clusterHas(sp)) { + setProperty(sp.getName(), null, true); //if server overrides it anyway, this should be a noop + } } else { - if (!serverHas(sp) && !clusterHas(sp)) - System.setProperty(sysProp.getName(), sysProp.getValue()); + if (!serverHas(sp) && !clusterHas(sp)) { + setProperty(sysProp.getName(), sysProp.getValue(), true); + } } return null; //processed } private NotProcessed removeFromDomain(SystemProperty sp) { - if(!serverHas(sp)&& !clusterHas(sp) && !configHas(sp)) - System.clearProperty(sp.getName()); //if server, cluster, or config overrides it anyway, this should be a noop + if(!serverHas(sp)&& !clusterHas(sp) && !configHas(sp)) { + setProperty(sp.getName(), null, true); //if server, cluster, or config overrides it anyway, this should be a noop + } return null; //processed } private NotProcessed addToServer(SystemProperty sp) { - System.setProperty(sp.getName(), sp.getValue()); + setProperty(sp.getName(), sp.getValue(), true); return null; //processed } private NotProcessed addToCluster(SystemProperty sp) { - if (!serverHas(sp)) - System.setProperty(sp.getName(), sp.getValue()); //if server overrides it anyway, this should be a noop + if (!serverHas(sp)) { + setProperty(sp.getName(), sp.getValue(), true); //if server overrides it anyway, this should be a noop + } return null; //processed } private NotProcessed addToConfig(SystemProperty sp) { - if (!serverHas(sp) && !clusterHas(sp)) - System.setProperty(sp.getName(), sp.getValue()); //if server or cluster overrides it anyway, this should be a noop + if (!serverHas(sp) && !clusterHas(sp)) { + setProperty(sp.getName(), sp.getValue(), true); //if server or cluster overrides it anyway, this should be a noop + } return null; //processed } private NotProcessed addToDomain(SystemProperty sp) { - if (!serverHas(sp) && !clusterHas(sp) && !configHas(sp)) - System.setProperty(sp.getName(), sp.getValue()); //if server, cluster, or config overrides it anyway, this should be a noop + if (!serverHas(sp) && !clusterHas(sp) && !configHas(sp)) { + setProperty(sp.getName(), sp.getValue(), true); //if server, cluster, or config overrides it anyway, this should be a noop + } return null; //processed } diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java index 8096682d3b2..fda62a3cdb6 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -50,9 +50,11 @@ import org.jvnet.hk2.annotations.Optional; import org.jvnet.hk2.annotations.Service; +import static java.util.logging.Level.INFO; import static org.glassfish.embeddable.GlassFishVariable.HOST_NAME; import static org.glassfish.embeddable.GlassFishVariable.JAVA_HOME; import static org.glassfish.embeddable.GlassFishVariable.JAVA_ROOT; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * Init run level service to take care of vm related tasks. @@ -90,9 +92,10 @@ public void postConstruct() { setSystemPropertiesFromEnv(); setSystemPropertiesFromDomainXml(); resolveJavaConfig(); - LOG.log(Level.FINE, "SystemTasks: loaded server named: {0}", server.getName()); + LOG.log(INFO, "Loaded server named: {0}", server.getName()); } + @Override public void writePidFile() { File pidFile = null; @@ -108,12 +111,12 @@ public void writePidFile() { } private void setVersion() { - System.setProperty("glassfish.version", Version.getProductIdInfo()); + setProperty("glassfish.version", Version.getProductIdInfo(), true); } private void setSystemPropertiesFromEnv() { // adding our version of some system properties. - System.setProperty(JAVA_ROOT.getSystemPropertyName(), System.getProperty(JAVA_HOME.getSystemPropertyName())); + setProperty(JAVA_ROOT.getSystemPropertyName(), System.getProperty(JAVA_HOME.getSystemPropertyName()), true); String hostname = "localhost"; try { // canonical name checks to make sure host is proper @@ -122,7 +125,7 @@ private void setSystemPropertiesFromEnv() { LOG.log(Level.SEVERE, KernelLoggerInfo.exceptionHostname, ex); } if (hostname != null) { - System.setProperty(HOST_NAME.getSystemPropertyName(), hostname); + setProperty(HOST_NAME.getSystemPropertyName(), hostname, false); } } @@ -179,8 +182,7 @@ private void resolveJavaConfig() { if (m.matches()) { String name = m.group(1); String value = TranslatedConfigView.expandValue(m.group(2)); - LOG.log(Level.FINEST, "Setting {0}={1}", new Object[] {name, value}); - System.setProperty(name, value); + setProperty(name, value, true); } } } @@ -192,7 +194,7 @@ private void setSystemProperties(List spList) { String value = sp.getValue(); if (ok(name)) { - System.setProperty(name, value); + setProperty(name, value, true); } } } diff --git a/nucleus/grizzly/config/src/test/java/org/glassfish/grizzly/config/GrizzlyConfigTest.java b/nucleus/grizzly/config/src/test/java/org/glassfish/grizzly/config/GrizzlyConfigTest.java index c7c1659af6e..a6d78b39a11 100644 --- a/nucleus/grizzly/config/src/test/java/org/glassfish/grizzly/config/GrizzlyConfigTest.java +++ b/nucleus/grizzly/config/src/test/java/org/glassfish/grizzly/config/GrizzlyConfigTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -41,6 +41,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotSame; @@ -251,12 +252,10 @@ public void ssl() throws URISyntaxException, IOException { private void configure() throws URISyntaxException { ClassLoader cl = getClass().getClassLoader(); - System.setProperty("javax.net.ssl.trustStore", - new File(cl.getResource("cacerts.jks").toURI()).getAbsolutePath()); - System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); - System.setProperty("javax.net.ssl.keyStore", - new File(cl.getResource("keystore.jks").toURI()).getAbsolutePath()); - System.setProperty("javax.net.ssl.keyStorePassword", "changeit"); + setProperty("javax.net.ssl.trustStore", new File(cl.getResource("cacerts.jks").toURI()).getAbsolutePath(), true); + setProperty("javax.net.ssl.trustStorePassword", "changeit", true); + setProperty("javax.net.ssl.keyStore", new File(cl.getResource("keystore.jks").toURI()).getAbsolutePath(), true); + setProperty("javax.net.ssl.keyStorePassword", "changeit", true); } @Test diff --git a/nucleus/osgi-platforms/osgi-cli-interactive/src/main/java/org/glassfish/osgi/cli/interactive/LocalOSGiShellCommand.java b/nucleus/osgi-platforms/osgi-cli-interactive/src/main/java/org/glassfish/osgi/cli/interactive/LocalOSGiShellCommand.java index 24029925027..fa82bbf1469 100644 --- a/nucleus/osgi-platforms/osgi-cli-interactive/src/main/java/org/glassfish/osgi/cli/interactive/LocalOSGiShellCommand.java +++ b/nucleus/osgi-platforms/osgi-cli-interactive/src/main/java/org/glassfish/osgi/cli/interactive/LocalOSGiShellCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation. + * Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation. * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -54,6 +54,7 @@ import org.glassfish.hk2.api.PerLookup; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.main.jdke.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.props.SystemProperties; import org.jline.reader.Completer; import org.jline.reader.EndOfFileException; import org.jline.reader.LineReader; @@ -166,7 +167,7 @@ protected int executeCommand() throws CommandException { // restore echo flag, saved in validate if (encoding != null) { // see Configuration.getEncoding()... - System.setProperty("input.encoding", encoding); + SystemProperties.setProperty("input.encoding", encoding, true); } final String[] args = enhanceForTarget(new String[] {REMOTE_COMMAND, "asadmin-osgi-shell"}); logger.log(Level.FINEST, "executeCommand: args {0}", Arrays.toString(args)); diff --git a/nucleus/security/core/src/main/java/com/sun/enterprise/security/LoginContext.java b/nucleus/security/core/src/main/java/com/sun/enterprise/security/LoginContext.java index d317ae65396..12056e796d7 100644 --- a/nucleus/security/core/src/main/java/com/sun/enterprise/security/LoginContext.java +++ b/nucleus/security/core/src/main/java/com/sun/enterprise/security/LoginContext.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2025 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 @@ -19,11 +20,11 @@ import com.sun.enterprise.security.auth.login.ClientPasswordLoginModule; import com.sun.enterprise.security.auth.login.LoginContextDriver; import com.sun.enterprise.security.auth.login.common.LoginException; -import com.sun.enterprise.security.common.AppservAccessController; import com.sun.enterprise.security.common.SecurityConstants; -import java.security.PrivilegedAction; -import java.util.logging.Logger; +import javax.security.auth.callback.CallbackHandler; + +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * This class is kept for CTS. Ideally we should move away from it. The login can be done via the following call: @@ -36,8 +37,7 @@ * } catch (LoginException le) { * le.printStackTrace(); * } - * - * + * * * Ideally the login should be done with the system property -Dj2eelogin.name and -Dj2eelogin.password * @@ -46,40 +46,25 @@ public final class LoginContext { - private static Logger _logger = null; - static { - _logger = SecurityLoggerInfo.getLogger(); - } - - private boolean guiAuth = false; - // declaring this different from the Appcontainer as // this will be called from standalone clients. - public javax.security.auth.callback.CallbackHandler handler = null; + private final CallbackHandler handler; /** * Creates the LoginContext with the defauly callback handler */ public LoginContext() { - handler = new com.sun.enterprise.security.auth.login.LoginCallbackHandler(guiAuth); + this.handler = new com.sun.enterprise.security.auth.login.LoginCallbackHandler(false); } /** * Login method to login username and password + * @deprecated Sets password as a system property */ + @Deprecated(forRemoval = true, since = "7.1.0") public void login(String user, String pass) throws LoginException { - final String username = user; - final String password = pass; - AppservAccessController.doPrivileged(new PrivilegedAction() { - @Override - public java.lang.Object run() { - - System.setProperty(ClientPasswordLoginModule.LOGIN_NAME, username); - System.setProperty(ClientPasswordLoginModule.LOGIN_PASSWORD, password); - - return null; - } - }); + setProperty(ClientPasswordLoginModule.LOGIN_NAME, user, false); + setProperty(ClientPasswordLoginModule.LOGIN_PASSWORD, pass, false); // Since this is a private api and the user is not supposed to use // this. We use the default the LoginCallbackHandler. LoginContextDriver.doClientLogin(SecurityConstants.USERNAME_PASSWORD, handler); @@ -89,8 +74,6 @@ public java.lang.Object run() { * This method has been provided to satisfy the CTS Porting Package requirement for logging in a certificate */ public void login(String username, byte[] authData) throws LoginException { - // do nothing } - } diff --git a/nucleus/security/core/src/main/java/com/sun/enterprise/security/PolicyLoader.java b/nucleus/security/core/src/main/java/com/sun/enterprise/security/PolicyLoader.java index 47ed830583e..0443296c961 100644 --- a/nucleus/security/core/src/main/java/com/sun/enterprise/security/PolicyLoader.java +++ b/nucleus/security/core/src/main/java/com/sun/enterprise/security/PolicyLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation. + * Copyright (c) 2022, 2025 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 @@ -56,6 +56,7 @@ import static java.util.logging.Level.SEVERE; import static java.util.logging.Level.WARNING; import static javassist.Modifier.PUBLIC; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * Loads the Default Policy File into the system. @@ -113,10 +114,8 @@ public void loadPolicy() { javaPolicyClassName = authorizationModule.getPolicyProvider(); } - if (System.getProperty("simple.jacc.provider.JACCRoleMapper.class") == null) { - System.setProperty("simple.jacc.provider.JACCRoleMapper.class", - "com.sun.enterprise.security.ee.web.integration.GlassfishRoleMapper"); - } + setProperty("simple.jacc.provider.JACCRoleMapper.class", + "com.sun.enterprise.security.ee.web.integration.GlassfishRoleMapper", false); // Now install the policy provider if one was identified if (javaPolicyClassName != null) { @@ -310,16 +309,14 @@ private void setPolicyConfigurationFactory(JaccProvider authorizationModule) { // Handle Jakarta Authorization-specified property for factory String factoryFromSystemProperty = System.getProperty(POLICY_CONF_FACTORY); if (factoryFromSystemProperty != null) { - // warn user of override LOGGER.log(WARNING, policyFactoryOverride, new String[] { POLICY_CONF_FACTORY, factoryFromSystemProperty }); - } else { // use domain.xml value by setting the property to it String factoryFromDomain = authorizationModule.getPolicyConfigurationFactoryProvider(); if (factoryFromDomain == null) { LOGGER.log(WARNING, policyConfigFactoryNotDefined); } else { - System.setProperty(POLICY_CONF_FACTORY, factoryFromDomain); + setProperty(POLICY_CONF_FACTORY, factoryFromDomain, true); } } @@ -328,9 +325,7 @@ private void setPolicyConfigurationFactory(JaccProvider authorizationModule) { for (Property authorizationModuleProperty : authorizationModuleProperties) { String name = POLICY_PROP_PREFIX + authorizationModuleProperty.getName(); String value = authorizationModuleProperty.getValue(); - LOGGER.finest("PolicyLoader set [" + name + "] to [" + value + "]"); - - System.setProperty(name, value); + setProperty(name, value, true); } } } diff --git a/nucleus/security/core/src/main/java/com/sun/enterprise/security/SecurityLifecycle.java b/nucleus/security/core/src/main/java/com/sun/enterprise/security/SecurityLifecycle.java index 1b4ffc0be4b..bac0cf78078 100644 --- a/nucleus/security/core/src/main/java/com/sun/enterprise/security/SecurityLifecycle.java +++ b/nucleus/security/core/src/main/java/com/sun/enterprise/security/SecurityLifecycle.java @@ -20,7 +20,6 @@ import com.sun.enterprise.security.audit.AuditManager; import com.sun.enterprise.security.auth.realm.RealmsManager; import com.sun.enterprise.security.common.Util; -import com.sun.enterprise.security.ssl.SSLUtils; import jakarta.inject.Inject; import jakarta.inject.Singleton; @@ -33,13 +32,15 @@ import org.glassfish.hk2.api.PostConstruct; import org.glassfish.hk2.api.PreDestroy; import org.glassfish.hk2.api.ServiceLocator; -import org.glassfish.internal.api.ServerContext; import org.jvnet.hk2.annotations.Optional; import org.jvnet.hk2.annotations.Service; +import static com.sun.enterprise.security.SecurityLoggerInfo.secMgrDisabled; +import static com.sun.enterprise.security.SecurityLoggerInfo.secMgrEnabled; import static com.sun.enterprise.security.common.Util.writeConfigFileToTempDir; import static java.util.logging.Level.INFO; import static org.glassfish.api.event.EventTypes.SERVER_SHUTDOWN; +import static org.glassfish.main.jdke.props.SystemProperties.setProperty; /** * This class extends default implementation of ServerLifecycle interface. It provides security initialization and setup @@ -56,24 +57,12 @@ public class SecurityLifecycle implements PostConstruct, PreDestroy { private static final String SYS_PROP_LOGIN_CONF = "java.security.auth.login.config"; private static final String SYS_PROP_JAVA_SEC_POLICY = "java.security.policy"; - @Inject - private ServerContext serverContext; - @Inject private PolicyLoader policyLoader; @Inject private SecurityServicesUtil securityServicesUtil; - @Inject - private Util util; - - @Inject - private SSLUtils sslUtils; - - @Inject - private SecurityConfigListener configListener; - @Inject private ServiceLocator serviceLocator; @@ -91,24 +80,13 @@ public SecurityLifecycle() { try { if (Util.isEmbeddedServer()) { // If the user-defined login.conf/server.policy are set as system properties, then they are given priority - if (System.getProperty(SYS_PROP_LOGIN_CONF) == null) { - System.setProperty(SYS_PROP_LOGIN_CONF, writeConfigFileToTempDir("login.conf").toURI().toURL().toExternalForm()); - } - if (System.getProperty(SYS_PROP_JAVA_SEC_POLICY) == null) { - System.setProperty(SYS_PROP_JAVA_SEC_POLICY, writeConfigFileToTempDir("server.policy").getAbsolutePath()); - } + setProperty(SYS_PROP_LOGIN_CONF, writeConfigFileToTempDir("login.conf").toURI().toURL().toExternalForm(), false); + setProperty(SYS_PROP_JAVA_SEC_POLICY, writeConfigFileToTempDir("server.policy").getAbsolutePath(), false); } // security manager is set here so that it can be accessed from // other lifecycles, like PEWebContainer - java.lang.SecurityManager secMgr = System.getSecurityManager(); - if (_logger.isLoggable(INFO)) { - if (secMgr != null) { - _logger.info(SecurityLoggerInfo.secMgrEnabled); - } else { - _logger.info(SecurityLoggerInfo.secMgrDisabled); - } - } + _logger.info(System.getSecurityManager() == null ? secMgrDisabled : secMgrEnabled); } catch (Exception ex) { _logger.log(Level.SEVERE, "java_security.init_securitylifecycle_fail", ex); throw new RuntimeException(ex.toString(), ex); @@ -120,10 +98,6 @@ public void onInitialization() { try { _logger.log(INFO, SecurityLoggerInfo.secServiceStartupEnter); - // TODO:V3 LoginContextDriver has a static variable dependency on BaseAuditManager - // And since LoginContextDriver has too many static methods that use BaseAuditManager - // we have to make this workaround here. - // Init Jakarta Authorization policyLoader.loadPolicy(); @@ -136,14 +110,7 @@ public void onInitialization() { // Audit the server started event auditManager.serverStarted(); - // initRoleMapperFactory is in J2EEServer.java and not moved to here - // this is because a DummyRoleMapperFactory is register due - // to invocation of ConnectorRuntime.createActiveResourceAdapter - // initRoleMapperFactory is called after it - // initRoleMapperFactory(); - _logger.log(INFO, SecurityLoggerInfo.secServiceStartupExit); - } catch (Exception ex) { throw new SecurityLifecycleException(ex); } diff --git a/nucleus/security/core/src/main/java/com/sun/enterprise/security/auth/realm/ldap/LDAPRealm.java b/nucleus/security/core/src/main/java/com/sun/enterprise/security/auth/realm/ldap/LDAPRealm.java index fb9a8384687..ccd95dcd3bf 100644 --- a/nucleus/security/core/src/main/java/com/sun/enterprise/security/auth/realm/ldap/LDAPRealm.java +++ b/nucleus/security/core/src/main/java/com/sun/enterprise/security/auth/realm/ldap/LDAPRealm.java @@ -48,6 +48,7 @@ import javax.security.auth.login.LoginException; import org.glassfish.internal.api.RelativePathResolver; +import org.glassfish.main.jdke.props.SystemProperties; import org.jvnet.hk2.annotations.Service; import static com.sun.enterprise.util.Utility.isAnyNull; @@ -262,9 +263,7 @@ public synchronized void init(Properties props) throws BadRealmException, NoSuch if (propName.startsWith("java.naming.") || propName.startsWith("javax.security.") || propName.startsWith("com.sun.jndi.ldap.")) { ldapBindProps.setProperty(propName, props.getProperty(propName)); } else if (propName.startsWith(SUN_JNDI_POOL_) && !SUN_JNDI_POOL_MAXSIZE.equals(propName)) { - if (System.getProperty(propName) == null) { - System.setProperty(propName, props.getProperty(propName)); - } + SystemProperties.setProperty(propName, props.getProperty(propName), false); } } @@ -277,9 +276,7 @@ public synchronized void init(Properties props) throws BadRealmException, NoSuch } catch (Exception ex) { sunPoolSizeStr = poolSize; } - if (System.getProperty(SUN_JNDI_POOL_MAXSIZE) == null) { - System.setProperty(SUN_JNDI_POOL_MAXSIZE, sunPoolSizeStr); - } + SystemProperties.setProperty(SUN_JNDI_POOL_MAXSIZE, sunPoolSizeStr, false); setProperty(PARAM_POOLSIZE, sunPoolSizeStr); String usePool = props.getProperty(SUN_JNDI_POOL, "true"); @@ -287,9 +284,7 @@ public synchronized void init(Properties props) throws BadRealmException, NoSuch if (url.startsWith(LDAPS_URL)) { ldapBindProps.setProperty(LDAP_SOCKET_FACTORY, DEFAULT_SSL_LDAP_SOCKET_FACTORY); - if (System.getProperty(SUN_JNDI_POOL_PROTOCOL) == null) { - System.setProperty(SUN_JNDI_POOL_PROTOCOL, DEFAULT_POOL_PROTOCOL); - } + SystemProperties.setProperty(SUN_JNDI_POOL_PROTOCOL, DEFAULT_POOL_PROTOCOL, false); _logger.log(FINE, "LDAPRealm : Using custom socket factory for SSL with pooling"); }