List of usage examples for java.lang SecurityManager checkPropertiesAccess
public void checkPropertiesAccess()
SecurityException
if the calling thread is not allowed to access or modify the system properties. From source file:Main.java
public static void main(String[] args) { System.setProperty("java.security.policy", "file:/C:/java.policy"); SecurityManager sm = new Main(); System.setSecurityManager(sm); sm.checkPropertiesAccess(); System.out.println("Allowed!"); }
From source file:org.apache.camel.management.DefaultManagementAgent.java
protected void createMBeanServer() { String hostName;/*from w w w . jav a 2 s.c o m*/ boolean canAccessSystemProps = true; try { // we'll do it this way mostly to determine if we should lookup the hostName SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPropertiesAccess(); } } catch (SecurityException se) { canAccessSystemProps = false; } if (canAccessSystemProps) { try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException uhe) { LOG.info("Cannot determine localhost name. Using default: " + DEFAULT_REGISTRY_PORT, uhe); hostName = DEFAULT_HOST; } } else { hostName = DEFAULT_HOST; } server = findOrCreateMBeanServer(); try { // Create the connector if we need if (createConnector) { createJmxConnector(hostName); } } catch (IOException ioe) { LOG.warn("Could not create and start JMX connector.", ioe); } }