HHH-15656 use privileged action when invoking ScheduledExecutorService.shutdown

Signed-off-by: Scott Marlow <smarlow@redhat.com>
This commit is contained in:
Scott Marlow 2022-11-01 10:23:46 -04:00 committed by Christian Beikov
parent 8f2325ed4a
commit a40fea29c0
1 changed files with 19 additions and 1 deletions

View File

@ -6,6 +6,8 @@
*/
package org.hibernate.engine.jdbc.connections.internal;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
@ -28,6 +30,7 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Database;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.internal.util.securitymanager.SystemSecurityManager;
import org.hibernate.service.UnknownUnwrapTypeException;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.ServiceException;
@ -605,7 +608,22 @@ public class DriverManagerConnectionProviderImpl
CONNECTIONS_MESSAGE_LOGGER.cleaningUpConnectionPool( pool.getUrl() );
active = false;
if ( executorService != null ) {
executorService.shutdown();
PrivilegedAction delegateToPrivilegedAction =
new PrivilegedAction() {
@Override
public Object run() {
executorService.shutdown();
return null;
}
};
if ( SystemSecurityManager.isSecurityManagerEnabled() ) {
AccessController.doPrivileged(
delegateToPrivilegedAction );
}
else {
delegateToPrivilegedAction.run();
}
}
executorService = null;
try {