Skip to content

Commit

Permalink
handling for jvmversion 21, setting security manager now in ServerSid…
Browse files Browse the repository at this point in the history
…eUtils
  • Loading branch information
dvayanu committed Jan 24, 2024
1 parent 9d8e455 commit c24d1b7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.distributeme.core.AbstractCallContext;
import org.distributeme.core.routing.Constants;

import java.security.Permission;
import java.util.Map;

/**
Expand Down Expand Up @@ -59,4 +60,28 @@ private static final boolean _isBlacklisted(Map transportableCallContext){
Boolean blacklistedFlag = (Boolean)transportableCallContext.get(Constants.ATT_BLACKLISTED);
return blacklistedFlag != null && blacklistedFlag;
}

public static void setSecurityManagerIfRequired(){
if (shouldSecurityManagerBeSet()){
if (System.getSecurityManager()==null)
// We allow all operations.
System.setSecurityManager(new SecurityManager(){
public void checkPermission(Permission perm) { }
});
}
}

/* TEST VISIBILITY */ static boolean shouldSecurityManagerBeSet(String jvmVersionString){
if (jvmVersionString == null)
return false;
if (jvmVersionString.contains(".")){
return Integer.parseInt(jvmVersionString.substring(0, jvmVersionString.indexOf('.')))<17;
}
return false;

}

private static final boolean shouldSecurityManagerBeSet(){
return shouldSecurityManagerBeSet(System.getProperty("java.version"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.distributeme.core.util;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ServerSideUtilsTest {
@Test
public void testShouldSecurityManagerBeSet() {
assertEquals(true, ServerSideUtils.shouldSecurityManagerBeSet("1.8.0_311"));
assertEquals(false, ServerSideUtils.shouldSecurityManagerBeSet("21"));
assertEquals(false, ServerSideUtils.shouldSecurityManagerBeSet("21.0.1"));
assertEquals(false, ServerSideUtils.shouldSecurityManagerBeSet("21.0.1-LTE-ea"));
}
}

0 comments on commit c24d1b7

Please sign in to comment.