Package gabriel

Examples of gabriel.Permission


  public void addPermission(Principal principal, List permissions) {
    AclEntry entry = new AclEntry(principal);

    Iterator iterator = permissions.iterator();
    while (iterator.hasNext()) {
      Permission permission = (Permission) iterator.next();
      entry.addPermission(permission);
    }
    addEntry(entry);
  }
View Full Code Here


      Set permissions = (Set) methodMap.get(methodName);
      Iterator iterator = permissions.iterator();
      boolean hasPermission = false;

      while (iterator.hasNext()) {
        Permission permission = (Permission) iterator.next();
        hasPermission = hasPermission || accessManager.checkPermission(principals, permission);
      }
      return hasPermission;
    } else {
      // If the method is not in the map, execution is allowed
View Full Code Here

   *
   * @param input String with method mapping
   * @return Method map
   */
  private Map parse(String input) {
    Permission permission = null;
    String method = null;

    int METHODS = 1;
    int PERMISSIONS = 2;
    int state = PERMISSIONS;

    Map methodMap = new HashMap();

    for (StringTokenizer stringTokenizer = new StringTokenizer(input, " \n{}", true);
         stringTokenizer.hasMoreTokens();) {

      String t = stringTokenizer.nextToken();

      if (" ".equals(t) || "\n".equals(t)) {
        // do nothing
      } else if ("{".equals(t)) {
        state = METHODS;
      } else if ("}".equals(t)) {
        state = PERMISSIONS;
      } else if (state == PERMISSIONS) {
        permission = new Permission(t);
      } else if (state == METHODS) {
        if (null != permission) {
          method = t;
          Set permissions;
          if (methodMap.containsKey(method)) {
View Full Code Here

        state = PRINCIPAL;

        AclEntry entry = new AclEntry(principal);
        Iterator iterator = permissions.iterator();
        while (iterator.hasNext()) {
          Permission permission = (Permission) iterator.next();
          entry.addPermission(permission);
        }
        if (negative) {
          entry.setNegativePermissions();
          negative = false;
        }
        acl.addEntry(owner, entry);
        permissions = new ArrayList();
        principal = null;
      } else if (state == PRINCIPAL) {
        if (t.startsWith("-")) {
          negative = true;
          t = t.substring(1);
        }
        // handle "- principal" and "-principal"
        if (!"".equals(t)) {
          principal = new Principal(t);
        }
      } else if (state == PERMISSIONS) {
        permissions.add(new Permission(t));
      }
    }
    return acl;
  }
View Full Code Here

   */
  public boolean checkPermission(Permission checkPermission) {
    boolean hasPermission = false;
    Iterator iterator = permissions.iterator();
    while (iterator.hasNext()) {
      Permission permission = (Permission) iterator.next();
      if (permission.implies(checkPermission)) {
        hasPermission = true;
      }
    }
    return hasPermission;
  }
View Full Code Here

    });
  }

  public void testCheckPermission() {
    Principal principal = new Principal("TestPrincipal");
    Permission permission = new Permission("TestPermission");
    accessManager.addPermission(principal, permission);
    Set principals = new HashSet();
    principals.add(principal);
    assertTrue("TestPrincipal has TestPermission.",
        accessManager.checkPermission(principals, permission));
View Full Code Here

        (MethodStore) mockMethodStore.proxy());
  }

  public void testCheckPermission() {

    Permission permission = new Permission("TestPermission");
    Principal principal = new Principal("TestPrincipal");
    Set principals = new HashSet();
    principals.add(principal);
    mockAccessManager.expects(once()).method("checkPermission").with(same(principals), same(permission)).will(returnValue(true));
    mockMethodStore.expects(once()).method("getMap").will(returnValue(new HashMap()));
View Full Code Here

    assertTrue("Granted permission to call TestClass.method1.", callManager.checkPermission(principals, "TestClass.method1"));
  }

  public void testAddPermissionsWithList() {
    List permissions = Arrays.asList(new String[]{"TestClass.method1", "TestClass.method2"});
    callManager.addMethods(new Permission("TestPermission"), permissions);
    assertTrue("TestPermission is needed for method1",
        callManager.getPermissions("TestClass.method1").contains(new Permission("TestPermission")));
    assertTrue("TestPermission is needed for method2",
        callManager.getPermissions("TestClass.method2").contains(new Permission("TestPermission")));
  }
View Full Code Here

        callManager.getPermissions("TestClass.method2").contains(new Permission("TestPermission")));
  }

  public void testAddPermissionsWithArray() {
    String[] permissions = new String[]{"TestClass.method1", "TestClass.method2"};
    callManager.addMethods(new Permission("TestPermission"), permissions);
    assertTrue("TestPermission is needed for method1",
        callManager.getPermissions("TestClass.method1").contains(new Permission("TestPermission")));
    assertTrue("TestPermission is needed for method2",
        callManager.getPermissions("TestClass.method2").contains(new Permission("TestPermission")));
  }
View Full Code Here

        "            PP2 { PM1 }";

    Acl acl = manager.parse(owner, name, new StringReader(source));

    assertEquals("PP1 has PM1",
        1, acl.checkPermission(new Principal("PP1"), new Permission("PM1")));
    assertEquals("PP1 has PM2",
        1, acl.checkPermission(new Principal("PP1"), new Permission("PM2")));
    assertEquals("PP1 has PM3",
        1, acl.checkPermission(new Principal("PP1"), new Permission("PM3")));
    assertEquals("PP2 has PM1",
        1, acl.checkPermission(new Principal("PP2"), new Permission("PM1")));
  }
View Full Code Here

TOP

Related Classes of gabriel.Permission

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.