Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot

...

Code Block
bgColor#FFcccc
class SensitiveHash {
  Hashtable&lt;Integer,String&gt;Hashtable<Integer,String> ht = new Hashtable&lt;Integer,String&gt;Hashtable<Integer,String>();
  
  public void removeEntry(Object key) {
    ht.remove(key);
  }
}

...

Code Block
bgColor#ccccff
class SensitiveHash {
  Hashtable&lt;Integer,String&gt;Hashtable<Integer,String> ht = new Hashtable&lt;Integer,String&gt;Hashtable<Integer,String>();

  void removeEntry(Object key) {
    check(&quot;removeKeyPermission&quot;"removeKeyPermission");
    ht.remove(key);    
  }

  private void check(String directive) {
    SecurityManager sm = System.getSecurityManager();
      if (sm != null) {
        sm.checkSecurityAccess(directive);
      }
  }
}

...

Code Block
bgColor#FFcccc
SecurityManager sm = System.getSecurityManager();

if(sm != null) {  //check if file can be read
  sm.checkRead(&quot;"/local/schema.dtd&quot;");
} 

Compliant Solution

Two methods, checkPermission(Permission perm) and checkPermission(Permission perm, Object context) were added to the SecurityManager class in J2SE 1.2. The motivations for this change were manifold:

...

Code Block
bgColor#ccccff
SecurityManager sm = System.getSecurityManager();
  
if(sm != null) {  //check if file can be read
  DTDPermission perm = new DTDPermission(&quot;"/local/&quot;",  &quot;readDTD&quot;"readDTD");
  sm.checkPermission(perm);
}

...

Wiki Markup
\[[API 06|AA. Java References#API 06]\] 

...

FIO36SEC35-J. Do not create multiple buffered wrappers on an InputStream&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;09. Input Output (FIO)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;09. Input Output (FIObase security checks on untrusted sources      02. Platform Security (SEC)      03. Declarations and Initialization (DCL)