Package org.apache.shiro.authz

Examples of org.apache.shiro.authz.Permission


    assertFalse(REQUEST_SERVER1_URI2.implies(ROLE_SERVER_SERVER1_URI_URI2));
    assertFalse(REQUEST_SERVER1_URI1.implies(ROLE_SERVER_SERVER1_URI_URI2));
  };
  @Test
  public void testUnexpected() throws Exception {
    Permission p = new Permission() {
      @Override
      public boolean implies(Permission p) {
        return false;
      }
    };
View Full Code Here


  private static final String ALL = SearchConstants.ALL;

  @Test
  public void testSimpleNoAction() throws Exception {
    Permission collection1 = create(new KeyValue("collection", "coll1"));
    Permission collection2 = create(new KeyValue("collection", "coll2"));
    Permission collection1Case = create(new KeyValue("colleCtIon", "coLl1"));

    assertTrue(collection1.implies(collection1));
    assertTrue(collection2.implies(collection2));
    assertTrue(collection1.implies(collection1Case));
    assertTrue(collection1Case.implies(collection1));

    assertFalse(collection1.implies(collection2));
    assertFalse(collection1Case.implies(collection2));
    assertFalse(collection2.implies(collection1));
    assertFalse(collection2.implies(collection1Case));
  }
View Full Code Here

    assertFalse(collection2.implies(collection1Case));
  }

  @Test
  public void testSimpleAction() throws Exception {
    Permission query =
      create(new KeyValue("collection", "coll1"), new KeyValue("action", "query"));
    Permission update =
      create(new KeyValue("collection", "coll1"), new KeyValue("action", "update"));
    Permission queryCase =
      create(new KeyValue("colleCtIon", "coLl1"), new KeyValue("AcTiOn", "QuERy"));

    assertTrue(query.implies(query));
    assertTrue(update.implies(update));
    assertTrue(query.implies(queryCase));
    assertTrue(queryCase.implies(query));

    assertFalse(query.implies(update));
    assertFalse(queryCase.implies(update));
    assertFalse(update.implies(query));
    assertFalse(update.implies(queryCase));
  }
View Full Code Here

    assertFalse(update.implies(queryCase));
  }

  @Test
  public void testRoleShorterThanRequest() throws Exception {
    Permission collection1 = create(new KeyValue("collection", "coll1"));
    Permission query =
      create(new KeyValue("collection", "coll1"), new KeyValue("action", "query"));
    Permission update =
      create(new KeyValue("collection", "coll1"), new KeyValue("action", "update"));
    Permission all =
      create(new KeyValue("collection", "coll1"), new KeyValue("action", ALL));

    assertTrue(collection1.implies(query));
    assertTrue(collection1.implies(update));
    assertTrue(collection1.implies(all));

    assertFalse(query.implies(collection1));
    assertFalse(update.implies(collection1));
    assertTrue(all.implies(collection1));
  }
View Full Code Here

    assertTrue(all.implies(collection1));
  }

  @Test
  public void testCollectionAll() throws Exception {
    Permission collectionAll = create(new KeyValue("collection", ALL));
    Permission collection1 = create(new KeyValue("collection", "coll1"));
    assertTrue(collectionAll.implies(collection1));
    assertTrue(collection1.implies(collectionAll));

    Permission allUpdate =
      create(new KeyValue("collection", ALL), new KeyValue("action", "update"));
    Permission allQuery =
      create(new KeyValue("collection", ALL), new KeyValue("action", "query"));
    Permission coll1Update =
      create(new KeyValue("collection", "coll1"), new KeyValue("action", "update"));
    Permission coll1Query =
      create(new KeyValue("collection", "coll1"), new KeyValue("action", "query"));
    assertTrue(allUpdate.implies(coll1Update));
    assertTrue(allQuery.implies(coll1Query));
    assertTrue(coll1Update.implies(allUpdate));
    assertTrue(coll1Query.implies(allQuery));
    assertFalse(allUpdate.implies(coll1Query));
    assertFalse(coll1Update.implies(coll1Query));
    assertFalse(allQuery.implies(coll1Update));
    assertFalse(coll1Query.implies(allUpdate));
    assertFalse(allUpdate.implies(allQuery));
    assertFalse(allQuery.implies(allUpdate));
    assertFalse(coll1Update.implies(coll1Query));
    assertFalse(coll1Query.implies(coll1Update));

    // test different length paths
    assertTrue(collectionAll.implies(allUpdate));
    assertTrue(collectionAll.implies(allQuery));
    assertTrue(collectionAll.implies(coll1Update));
    assertTrue(collectionAll.implies(coll1Query));
    assertFalse(allUpdate.implies(collectionAll));
    assertFalse(allQuery.implies(collectionAll));
    assertFalse(coll1Update.implies(collectionAll));
    assertFalse(coll1Query.implies(collectionAll));
  }
View Full Code Here

    assertFalse(coll1Query.implies(collectionAll));
  }

  @Test
  public void testActionAll() throws Exception {
    Permission coll1All =
       create(new KeyValue("collection", "coll1"), new KeyValue("action", ALL));
    Permission coll1Update =
      create(new KeyValue("collection", "coll1"), new KeyValue("action", "update"));
    Permission coll1Query =
      create(new KeyValue("collection", "coll1"), new KeyValue("action", "query"));
    assertTrue(coll1All.implies(coll1All));
    assertTrue(coll1All.implies(coll1Update));
    assertTrue(coll1All.implies(coll1Query));
    assertFalse(coll1Update.implies(coll1All));
    assertFalse(coll1Query.implies(coll1All));

    // test different lengths
    Permission coll1 =
       create(new KeyValue("collection", "coll1"));
    assertTrue(coll1All.implies(coll1));
    assertTrue(coll1.implies(coll1All));
  }
View Full Code Here

    assertTrue(coll1.implies(coll1All));
  }

  @Test
  public void testUnexpected() throws Exception {
    Permission p = new Permission() {
      @Override
      public boolean implies(Permission p) {
        return false;
      }
    };
    Permission collection1 = create(new KeyValue("collection", "coll1"));
    assertFalse(collection1.implies(null));
    assertFalse(collection1.implies(p));
    assertFalse(collection1.equals(null));
    assertFalse(collection1.equals(p));
  }
View Full Code Here

        Collection<Permission> perms = Collections.emptySet();
        PermissionResolver resolver = getPermissionResolver();
        if (resolver != null && !CollectionUtils.isEmpty(stringPerms)) {
            perms = new LinkedHashSet<Permission>(stringPerms.size());
            for (String strPermission : stringPerms) {
                Permission permission = getPermissionResolver().resolvePermission(strPermission);
                perms.add(permission);
            }
        }
        return perms;
    }
View Full Code Here

        }
        return perms;
    }

    public boolean isPermitted(PrincipalCollection principals, String permission) {
        Permission p = getPermissionResolver().resolvePermission(permission);
        return isPermitted(principals, p);
    }
View Full Code Here

        }
        return true;
    }

    public void checkPermission(PrincipalCollection subjectIdentifier, String permission) throws AuthorizationException {
        Permission p = getPermissionResolver().resolvePermission(permission);
        checkPermission(subjectIdentifier, p);
    }
View Full Code Here

TOP

Related Classes of org.apache.shiro.authz.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.