title: How to provide java security for white listed packages using java security manager?
body: <p><strong>Problem:</strong>
  I am trying to provide restriction (blacklisting ) all and allow only what I provided when we execute groovy using <strong>GroovyClassLoader</strong></p>
  
  <p>I am able to execute custom policy using with limited permission for <strong>GroovyClassLoader</strong> only.</p>
  
  <p>Now I am trying to provide package restriction going to use as part of groovy execution. Let say If I  allowed <strong>com.x.y</strong> this package if any package other then this used in groovy should throw <strong>SecurityException</strong></p>
  
  <p>I have tried to achieve the same  with custom security manager and overriding the <code>checkPackageAccess</code> but didn't get success.</p>
  
  <pre><code>    public TestSecurityManager extends SecurityManager{
  
      List&lt;String&gt; whiteListedPkgList;
  
       public void checkPackageAccess(String pkg){
           if(!pkg.startWith(any of given white list pkg)){
             throw new SecurityException("Access Denied");
             }
          //If package not belong to whilelisted package list throw security exception
         }
      }
  </code></pre>
  
  <p>When I tried using above approach we need to provide all packages for execution <strong>like com, java</strong> etc instead of <strong>java.nio.file</strong>. in whitelist list</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>If we try to allow package like <strong>com.x.y</strong> using white list comparison using start with check access pkg, it will allow that package but later on it will <strong>throw security exception</strong> for <strong>com</strong> package.</p>
  
  <p>Could any one help for the same how we can achieve it ?</p>
  
  <p>Thanks in advance</p>