Ejemplo n.º 1
0
  public void testReadPermission() throws SAXException, IOException, ParserConfigurationException {
    final InputStream inputStream = this.getClass().getResourceAsStream("policy-def-test.xml");
    final FilePermissionStore permStore = new FilePermissionStore(inputStream);
    final Permissions perms = permStore.loadPermissions(new SimplePrincipal("christian"));
    assertTrue(perms != null);
    final Enumeration<Permission> enumPerms = perms.elements();
    Permission p;
    int count = 0;

    while (enumPerms.hasMoreElements()) {
      p = enumPerms.nextElement();
      count++;
      if (p instanceof FilePermission) {
        final FilePermission fp = (FilePermission) p;
        assertEquals("*.tmp", fp.getName());
        assertTrue(fp.getActions().equals("read"));
      } else {
        if (p instanceof TestcasePermission) {
          final TestcasePermission tcp = (TestcasePermission) p;
          assertEquals("testPerm", tcp.getName());
        } else {
          assertTrue("unknown permission " + p, false);
        }
      }
    }
    assertTrue(count == 2);
  }
 public Enumeration<Permission> elements() {
   return perms.elements();
 }