-
Notifications
You must be signed in to change notification settings - Fork 41
[#286] disable SecurityManager starting with Java 21 #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bmarwell
wants to merge
2
commits into
groovy:master
Choose a base branch
from
bmarwell:#286_disable_security_manager_java21
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/org/codehaus/gmavenplus/util/AbstractSecurityManagerSetter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.codehaus.gmavenplus.util; | ||
|
|
||
| import org.apache.maven.plugin.logging.Log; | ||
|
|
||
| public abstract class AbstractSecurityManagerSetter implements SecurityManagerSetter{ | ||
|
|
||
| private final boolean allowSystemExits; | ||
|
|
||
| private final Log log; | ||
|
|
||
| public AbstractSecurityManagerSetter(final Log log, final boolean allowSystemExits) { | ||
| this.log = log; | ||
| this.allowSystemExits = allowSystemExits; | ||
| } | ||
|
|
||
| protected boolean getAllowSystemExits() { | ||
| return allowSystemExits; | ||
| } | ||
|
|
||
| protected Log getLog() { | ||
| return log; | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
src/main/java/org/codehaus/gmavenplus/util/DefaultSecurityManagerSetter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package org.codehaus.gmavenplus.util; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import org.apache.maven.plugin.logging.Log; | ||
|
|
||
| public class DefaultSecurityManagerSetter extends AbstractSecurityManagerSetter { | ||
|
|
||
| private final AtomicReference<SecurityManager> previousSecurityManager = new AtomicReference<>(); | ||
|
|
||
| public DefaultSecurityManagerSetter(Log log, final boolean allowSystemExits) { | ||
| super(log, allowSystemExits); | ||
| } | ||
|
|
||
| @Override | ||
| public void setNoExitSecurityManager() { | ||
| if (this.getAllowSystemExits()) { | ||
| return; | ||
| } | ||
|
|
||
| this.previousSecurityManager.set(System.getSecurityManager()); | ||
|
|
||
| getLog().warn("Setting a security manager is deprecated. Running this build with Java 21 or newer might result in different behaviour."); | ||
| System.setSecurityManager(new NoExitSecurityManager()); | ||
| } | ||
|
|
||
| @Override | ||
| public void revertToPreviousSecurityManager() { | ||
| if (this.getAllowSystemExits()) { | ||
| return; | ||
| } | ||
|
|
||
| this.getPreviousSecurityManager().getAndUpdate((previousSecurityManager -> { | ||
| if (previousSecurityManager == null) { | ||
| return null; | ||
| } | ||
|
|
||
| System.setSecurityManager(previousSecurityManager); | ||
|
|
||
| return null; | ||
| })); | ||
| } | ||
|
|
||
| protected AtomicReference<SecurityManager> getPreviousSecurityManager() { | ||
| return previousSecurityManager; | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/codehaus/gmavenplus/util/SecurityManagerSetter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package org.codehaus.gmavenplus.util; | ||
|
|
||
| /** | ||
| * Sets a custom security manager and returns the previous instance. | ||
| * Can also revert to the previous security Manager. | ||
| * <p> | ||
| * Implementation notice: For Java 21 and above, | ||
| * the implementation must be a no-op and issue a warning. | ||
| * | ||
| */ | ||
| public interface SecurityManagerSetter { | ||
|
|
||
| /** | ||
| * For Java until 20, this method should set the given Security manager if property {@code allowSystemExits} is set. | ||
| */ | ||
| void setNoExitSecurityManager(); | ||
|
|
||
| void revertToPreviousSecurityManager(); | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/main/java21/org/codehaus/gmavenplus/util/DefaultSecurityManagerSetter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.codehaus.gmavenplus.util; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import org.apache.maven.plugin.logging.Log; | ||
|
|
||
| public class DefaultSecurityManagerSetter extends AbstractSecurityManagerSetter { | ||
|
|
||
| public DefaultSecurityManagerSetter(Log log, final boolean allowSystemExits) { | ||
| super(log, allowSystemExits); | ||
| } | ||
|
|
||
| @Override | ||
| public void setNoExitSecurityManager() { | ||
| if (this.getAllowSystemExits()) { | ||
| return; | ||
| } | ||
|
|
||
| getLog().warn("Setting a security manager is not supported starting with Java 21."); | ||
| } | ||
|
|
||
| @Override | ||
| public void revertToPreviousSecurityManager() { | ||
| if (this.getAllowSystemExits()) { | ||
| return; | ||
| } | ||
|
|
||
| getLog().warn("Setting a security manager is not supported starting with Java 21."); | ||
|
|
||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.