org.jgroups.util.SecurityActions Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including
all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and
JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
package org.jgroups.util;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* Privileged actions for the package
*
* Do not move. Do not change class and method visibility to avoid being called from other
* {@link java.security.CodeSource}s, thus granting privilege escalation to external code.
*
* @author [email protected]
* @since 4.2
*/
final class SecurityActions {
interface SysProps {
SysProps NON_PRIVILEGED = new SysProps() {
@Override
public String getProperty(final String name, final String defaultValue) {
return System.getProperty(name, defaultValue);
}
@Override
public String getProperty(final String name) {
return System.getProperty(name);
}
@Override
public String getEnv(String name) {
return System.getenv(name);
}
};
SysProps PRIVILEGED = new SysProps() {
@Override
public String getProperty(final String name, final String defaultValue) {
return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(name, defaultValue));
}
@Override
public String getProperty(final String name) {
return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(name));
}
@Override
public String getEnv(String name) {
return AccessController.doPrivileged((PrivilegedAction) () -> System.getenv(name));
}
};
String getProperty(String name, String defaultValue);
String getProperty(String name);
String getEnv(String name);
}
public static String getProperty(String name, String defaultValue) {
if (System.getSecurityManager() == null)
return SysProps.NON_PRIVILEGED.getProperty(name, defaultValue);
return SysProps.PRIVILEGED.getProperty(name, defaultValue);
}
public static String getProperty(String name) {
if (System.getSecurityManager() == null)
return SysProps.NON_PRIVILEGED.getProperty(name);
return SysProps.PRIVILEGED.getProperty(name);
}
public static String getEnv(String name) {
if (System.getSecurityManager() == null)
return SysProps.NON_PRIVILEGED.getEnv(name);
return SysProps.PRIVILEGED.getEnv(name);
}
}