Skip to content
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

JDK12 setSecurityManager according to java.security.manager special tokens #4738

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1305,3 +1305,6 @@ K0900="Create a new Reference, since a Reference cannot be cloned."
#java.lang.invoke.MethodHandle
K0A00="Failed to resolve Constant Dynamic entry with j9class: {0}, name: {1}, descriptor: {2}, bsmData: {3}"
K0A01="Constant_Dynamic references bootstrap method '{0}' does not have java.lang.invoke.MethodHandles.Lookup as first parameter."

#java.lang.System
K0B00="`-Djava.security.manager=disallow` has been specified."
12 changes: 9 additions & 3 deletions jcl/src/java.base/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,18 @@ static final void initializeClassLoaders() {
/*[ENDIF]*/
jdk.internal.misc.VM.initLevel(2);
String javaSecurityManager = System.internalGetProperties().getProperty("java.security.manager"); //$NON-NLS-1$
if (null != javaSecurityManager) {
if (javaSecurityManager.isEmpty() || "default".equals(javaSecurityManager)) {
if ((javaSecurityManager != null)
/*[IF Java12]*/
/* See the SecurityManager javadoc for details about special tokens. */
&& !javaSecurityManager.equals("disallow") //$NON-NLS-1$ /* special token to disallow SecurityManager */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment to refer to the SecurityManager javadoc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JDK 12 doc is still an early access, added a comment More details are at JDK 12 javadoc jdk12/docs/api/java.base/java/lang/SecurityManager.html instead.

Please have another look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to include a direct link. In fact, I don't think the path is desired either. I'm fine with a comment at says "See the SecurityManager javadoc for details."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, the comment is updated.

&& !javaSecurityManager.equals("allow") //$NON-NLS-1$ /* special token to allow SecurityManager */
/*[ENDIF] Java12 */
) {
if (javaSecurityManager.isEmpty() || "default".equals(javaSecurityManager)) { //$NON-NLS-1$
System.setSecurityManager(new SecurityManager());
} else {
try {
System.setSecurityManager((SecurityManager)Class.forName(javaSecurityManager, true, applicationClassLoader).newInstance());
System.setSecurityManager((SecurityManager)Class.forName(javaSecurityManager, true, applicationClassLoader).getDeclaredConstructor().newInstance());
} catch (Throwable e) {
/*[MSG "K0631", "JVM can't set custom SecurityManager due to {0}"]*/
throw new Error(com.ibm.oti.util.Msg.getString("K0631", e.toString()), e); //$NON-NLS-1$
Expand Down
12 changes: 11 additions & 1 deletion jcl/src/java.base/share/classes/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,23 @@ public static void setProperties(Properties p) {
*
* @param s the new security manager
*
* @throws SecurityException if the security manager has already been set.
* @throws SecurityException if the security manager has already been set and its checkPermission method doesn't allow it to be replaced.
/*[IF Java12]
* @throws UnsupportedOperationException if s is non-null and a special token "disallow" has been set for system property "java.security.manager"
* which indicates that a security manager is not allowed to be set dynamically.
/*[ENDIF] Java12
*/
public static void setSecurityManager(final SecurityManager s) {
/*[PR 113606] security field could be modified by another Thread */
final SecurityManager currentSecurity = security;

if (s != null) {
/*[IF Java12]*/
if ("disallow".equals(systemProperties.getProperty("java.security.manager"))) { //$NON-NLS-1$ //$NON-NLS-2$
/*[MSG "K0B00", "`-Djava.security.manager=disallow` has been specified"]*/
throw new UnsupportedOperationException(com.ibm.oti.util.Msg.getString("K0B00")); //$NON-NLS-1$
}
/*[ENDIF] Java12 */
if (currentSecurity == null) {
// only preload classes when current security manager is null
// not adding an extra static field to preload only once
Expand Down