From ff5b508a2044ac506a7c8c96ff68a66a0ab39fe1 Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Tue, 4 Oct 2022 17:42:51 +0100 Subject: [PATCH] Add the ability to the API consumers to load the API implementations by using a different protection domain when using with security manager enabled --- .../jakarta/activation/MailcapCommandMap.java | 18 ++++++++++++++---- .../activation/MimetypesFileTypeMap.java | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/jakarta/activation/MailcapCommandMap.java b/api/src/main/java/jakarta/activation/MailcapCommandMap.java index 6ded677..03e9c4d 100644 --- a/api/src/main/java/jakarta/activation/MailcapCommandMap.java +++ b/api/src/main/java/jakarta/activation/MailcapCommandMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 2022 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -693,9 +693,19 @@ public synchronized String[] getNativeCommands(String mimeType) { } private MailcapRegistryProvider getImplementation() { - return FactoryFinder.find(MailcapRegistryProvider.class, - "com.sun.activation.registries.MailcapRegistryProviderImpl", - false); + if (System.getSecurityManager() != null) { + return AccessController.doPrivileged(new PrivilegedAction() { + public MailcapRegistryProvider run() { + return FactoryFinder.find(MailcapRegistryProvider.class, + "com.sun.activation.registries.MailcapRegistryProviderImpl", + false); + } + }); + } else { + return FactoryFinder.find(MailcapRegistryProvider.class, + "com.sun.activation.registries.MailcapRegistryProviderImpl", + false); + } } /* diff --git a/api/src/main/java/jakarta/activation/MimetypesFileTypeMap.java b/api/src/main/java/jakarta/activation/MimetypesFileTypeMap.java index 9e12c28..0c1c36d 100644 --- a/api/src/main/java/jakarta/activation/MimetypesFileTypeMap.java +++ b/api/src/main/java/jakarta/activation/MimetypesFileTypeMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021, 2022 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -10,7 +10,6 @@ package jakarta.activation; -import jakarta.activation.spi.MailcapRegistryProvider; import jakarta.activation.spi.MimeTypeRegistryProvider; import java.io.*; @@ -386,9 +385,19 @@ public synchronized String getContentType(String filename) { } private MimeTypeRegistryProvider getImplementation() { - return FactoryFinder.find(MimeTypeRegistryProvider.class, - "com.sun.activation.registries.MimeTypeRegistryProviderImpl", - false); + if (System.getSecurityManager() != null) { + return AccessController.doPrivileged(new PrivilegedAction() { + public MimeTypeRegistryProvider run() { + return FactoryFinder.find(MimeTypeRegistryProvider.class, + "com.sun.activation.registries.MimeTypeRegistryProviderImpl", + false); + } + }); + } else { + return FactoryFinder.find(MimeTypeRegistryProvider.class, + "com.sun.activation.registries.MimeTypeRegistryProviderImpl", + false); + } } /*