Skip to content

Commit

Permalink
Add the ability to the API consumers to load the API implementations …
Browse files Browse the repository at this point in the history
…by using a different protection domain when using with security manager enabled
  • Loading branch information
yersan committed Oct 4, 2022
1 parent 2270d5e commit ff5b508
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
18 changes: 14 additions & 4 deletions api/src/main/java/jakarta/activation/MailcapCommandMap.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<MailcapRegistryProvider>() {
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);
}
}

/*
Expand Down
19 changes: 14 additions & 5 deletions api/src/main/java/jakarta/activation/MimetypesFileTypeMap.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,7 +10,6 @@

package jakarta.activation;

import jakarta.activation.spi.MailcapRegistryProvider;
import jakarta.activation.spi.MimeTypeRegistryProvider;

import java.io.*;
Expand Down Expand Up @@ -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<MimeTypeRegistryProvider>() {
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);
}
}

/*
Expand Down

0 comments on commit ff5b508

Please sign in to comment.