/[classpath]/classpath/gnu/java/security/PolicyFile.java
ViewVC logotype

Diff of /classpath/gnu/java/security/PolicyFile.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by mark, Sat Jul 2 20:32:14 2005 UTC revision 1.5 by rsdio, Mon Aug 8 07:18:42 2005 UTC
# Line 37  exception statement from your version. * Line 37  exception statement from your version. *
37    
38  package gnu.java.security;  package gnu.java.security;
39    
40    import gnu.classpath.SystemProperties;
41    import gnu.classpath.debug.Component;
42    import gnu.classpath.debug.SystemLogger;
43    
44  import java.io.File;  import java.io.File;
45  import java.io.IOException;  import java.io.IOException;
46  import java.io.InputStreamReader;  import java.io.InputStreamReader;
# Line 66  import java.util.LinkedList; Line 70  import java.util.LinkedList;
70  import java.util.List;  import java.util.List;
71  import java.util.Map;  import java.util.Map;
72  import java.util.StringTokenizer;  import java.util.StringTokenizer;
73    import java.util.logging.Logger;
74    
75  /**  /**
76   * An implementation of a {@link java.security.Policy} object whose   * An implementation of a {@link java.security.Policy} object whose
# Line 143  public final class PolicyFile extends Po Line 148  public final class PolicyFile extends Po
148    // Constants and fields.    // Constants and fields.
149    // -------------------------------------------------------------------------    // -------------------------------------------------------------------------
150    
151    private static final boolean DEBUG = true;    private static final Logger logger = SystemLogger.SYSTEM;
   // Package-private to avoid a trampoline.  
   static void debug(String msg)  
   {  
     System.err.print(">> PolicyFile: ");  
     System.err.println(msg);  
   }  
   
   private static void debug(Throwable t)  
   {  
     System.err.println(">> PolicyFile");  
     t.printStackTrace(System.err);  
   }  
152    
153    private static final String DEFAULT_POLICY = System.getProperty("java.home")    private static final String DEFAULT_POLICY =
154      + System.getProperty("file.separator") + "lib"      SystemProperties.getProperty("java.home")
155      + System.getProperty("file.separator") + "security"      + SystemProperties.getProperty("file.separator") + "lib"
156      + System.getProperty("file.separator") + "java.policy";      + SystemProperties.getProperty("file.separator") + "security"
157        + SystemProperties.getProperty("file.separator") + "java.policy";
158      private static final String DEFAULT_USER_POLICY =
159        SystemProperties.getProperty ("user.home") +
160        SystemProperties.getProperty ("file.separator") + ".java.policy";
161    
162    private final Map cs2pc;    private final Map cs2pc;
163    
# Line 185  public final class PolicyFile extends Po Line 182  public final class PolicyFile extends Po
182          CodeSource cs = (CodeSource) e.getKey();          CodeSource cs = (CodeSource) e.getKey();
183          if (cs.implies(codeSource))          if (cs.implies(codeSource))
184            {            {
185              if (DEBUG) debug(cs+" -> "+codeSource);              logger.log (Component.POLICY, "{0} -> {1}", new Object[]
186                  { cs, codeSource });
187              PermissionCollection pc = (PermissionCollection) e.getValue();              PermissionCollection pc = (PermissionCollection) e.getValue();
188              for (Enumeration ee = pc.elements(); ee.hasMoreElements(); )              for (Enumeration ee = pc.elements(); ee.hasMoreElements(); )
189                {                {
# Line 193  public final class PolicyFile extends Po Line 191  public final class PolicyFile extends Po
191                }                }
192            }            }
193          else          else
194            if (DEBUG) debug(cs+" !-> "+codeSource);            logger.log (Component.POLICY, "{0} !-> {1}", new Object[]
195                { cs, codeSource });
196        }        }
197      if (DEBUG) debug ("returning permissions " + perms + " for " + codeSource);      logger.log (Component.POLICY, "returning permissions {0} for {1}",
198                    new Object[] { perms, codeSource });
199      return perms;      return perms;
200    }    }
201    
202    public void refresh()    public void refresh()
203    {    {
204      cs2pc.clear();      cs2pc.clear();
205      List policyFiles = new LinkedList();      final List policyFiles = new LinkedList();
206      try      try
207        {        {
208          policyFiles.add(new File(DEFAULT_POLICY).toURL());          policyFiles.add (new File (DEFAULT_POLICY).toURL());
209          if (DEBUG) debug ("defualt policy is " + DEFAULT_POLICY);          policyFiles.add (new File (DEFAULT_USER_POLICY).toURL ());
210          policyFiles.addAll((List) AccessController.doPrivileged(  
211            AccessController.doPrivileged(
212            new PrivilegedExceptionAction()            new PrivilegedExceptionAction()
213            {            {
214              public Object run() throws Exception              public Object run() throws Exception
215              {              {
216                LinkedList l = new LinkedList();                String allow = Security.getProperty ("policy.allowSystemProperty");
217                  if (allow == null || Boolean.getBoolean (allow))
218                    {
219                      String s = SystemProperties.getProperty ("java.security.policy");
220                      logger.log (Component.POLICY, "java.security.policy={0}", s);
221                      if (s != null)
222                        {
223                          boolean only;
224                          if (only = s.startsWith ("="))
225                            s = s.substring (1);
226                          policyFiles.clear ();
227                          policyFiles.add (new URL (s));
228                          if (only)
229                            return null;
230                        }
231                    }
232                for (int i = 1; ; i++)                for (int i = 1; ; i++)
233                  {                  {
234                    String s = Security.getProperty("policy.file."+i);                    String pname = "policy.url." + i;
235                    if (DEBUG) debug("policy.file."+i+"="+s);                    String s = Security.getProperty (pname);
236                      logger.log (Component.POLICY, "{0}={1}", new Object []
237                        { pname, s });
238                    if (s == null)                    if (s == null)
239                      break;                      break;
240                    l.add(new URL(s));                    policyFiles.add (new URL (s));
241                  }                  }
242                String s = System.getProperty("java.security.policy");                return null;
               if (DEBUG) debug("java.security.policy="+s);  
               if (s != null)  
                 l.add(new URL(s));  
               return l;  
243              }              }
244            }));            });
245        }        }
246      catch (PrivilegedActionException pae)      catch (PrivilegedActionException pae)
247        {        {
248          if (DEBUG) debug(pae);          logger.log (Component.POLICY, "reading policy properties", pae);
249        }        }
250      catch (MalformedURLException mue)      catch (MalformedURLException mue)
251        {        {
252          if (DEBUG) debug(mue);          logger.log (Component.POLICY, "setting default policies", mue);
253        }        }
254    
255        logger.log (Component.POLICY, "building policy from URLs {0}",
256                    policyFiles);
257      for (Iterator it = policyFiles.iterator(); it.hasNext(); )      for (Iterator it = policyFiles.iterator(); it.hasNext(); )
258        {        {
259          try          try
# Line 246  public final class PolicyFile extends Po Line 263  public final class PolicyFile extends Po
263            }            }
264          catch (IOException ioe)          catch (IOException ioe)
265            {            {
266              if (DEBUG) debug(ioe);              logger.log (Component.POLICY, "reading policy", ioe);
267            }            }
268        }        }
269    }    }
# Line 273  public final class PolicyFile extends Po Line 290  public final class PolicyFile extends Po
290     */     */
291    private void parse(final URL url) throws IOException    private void parse(final URL url) throws IOException
292    {    {
293      if (DEBUG) debug ("reading policy file from " + url);      logger.log (Component.POLICY, "reading policy file from {0}", url);
294      final StreamTokenizer in = new StreamTokenizer(new InputStreamReader(url.openStream()));      final StreamTokenizer in = new StreamTokenizer(new InputStreamReader(url.openStream()));
295      in.resetSyntax();      in.resetSyntax();
296      in.slashSlashComments(true);      in.slashSlashComments(true);

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26