示例#1
0
 public static boolean checkSecurity() {
   SecurityManager security = System.getSecurityManager();
   if (security != null) {
     try {
       security.checkPropertyAccess("user.dir");
       security.checkPropertyAccess("file.separator");
     } catch (SecurityException e) {
       System.out.println("SecurityManager restricts session recording.");
       return false;
     }
   }
   return true;
 }
示例#2
0
  /**
   * Gets the system property indicated by the specified key.
   *
   * <p>First, if there is a security manager, its <code>checkPropertyAccess</code> method is called
   * with the <code>key</code> as its argument.
   *
   * <p>If there is no current set of system properties, a set of system properties is first created
   * and initialized in the same manner as for the <code>getProperties</code> method.
   *
   * @param key the name of the system property.
   * @param def a default value.
   * @return the string value of the system property, or the default value if there is no property
   *     with that key.
   * @exception SecurityException if a security manager exists and its <code>checkPropertyAccess
   *     </code> method doesn't allow access to the specified system property.
   * @exception NullPointerException if <code>key</code> is <code>null</code>.
   * @exception IllegalArgumentException if <code>key</code> is empty.
   * @see #setProperty
   * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
   * @see java.lang.System#getProperties()
   */
  public static String getProperty(String key, String def) {
    checkKey(key);
    SecurityManager sm = getSecurityManager();
    if (sm != null) {
      sm.checkPropertyAccess(key);
    }

    return props.getProperty(key, def);
  }