Package org.jboss.security.acl

Examples of org.jboss.security.acl.ACLImpl


      assertEquals("Invalid number of entries", entriesNumber - 1, acl.getEntries().size());

      // assert that update fails for an ACL not managed by the strategy.
      Collection<ACLEntry> entries = new ArrayList<ACLEntry>();
      entries.add(new ACLEntryImpl(BasicACLPermission.UPDATE, IdentityFactory.createIdentity("Another Identity")));
      ACL otherACL = new ACLImpl(this.resources[1], entries);
      assertFalse(this.strategy.updateACL(otherACL));
   }
View Full Code Here


    * @throws Exception if an error occurs when running the test.
    */
   public void testIsGranted() throws Exception
   {
      // build the tested ACL.
      ACL acl = new ACLImpl(new TestResource(10), Arrays.asList(this.entries));
      assertEquals("Invalid number of entries", ACL_SIZE, acl.getEntries().size());

      // test the identity associated with a basic permission.
      assertTrue(acl.isGranted(BasicACLPermission.READ, this.identities[0]));
      assertFalse(acl.isGranted(BasicACLPermission.DELETE, this.identities[0]));
      assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.CREATE, BasicACLPermission.UPDATE),
            this.identities[0]));

      // assert the empty permission is always granted.
      ACLPermission emptyPermission = new CompositeACLPermission();
      for (int i = 0; i < ACL_SIZE; i++)
         assertTrue(acl.isGranted(emptyPermission, this.identities[i]));

      // assert that identities[1] is only granted the empty permission.
      for (BasicACLPermission permission : BasicACLPermission.values())
         assertFalse(acl.isGranted(permission, this.identities[1]));
      assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.values()), this.identities[1]));

      // test the identities associated to composite permissions.
      assertTrue(acl.isGranted(BasicACLPermission.READ, this.identities[2]));
      assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.READ, BasicACLPermission.UPDATE),
            this.identities[2]));
      assertFalse(acl.isGranted(BasicACLPermission.CREATE, this.identities[2]));
      assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.UPDATE, BasicACLPermission.DELETE),
            this.identities[2]));

      assertTrue(acl.isGranted(BasicACLPermission.CREATE, this.identities[3]));
      assertTrue(acl.isGranted(BasicACLPermission.UPDATE, this.identities[3]));
      assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.CREATE, BasicACLPermission.DELETE),
            this.identities[3]));
      assertFalse(acl.isGranted(BasicACLPermission.READ, this.identities[3]));
      assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.READ, BasicACLPermission.UPDATE),
            this.identities[3]));

      for (BasicACLPermission permission : BasicACLPermission.values())
         assertTrue(acl.isGranted(permission, this.identities[4]));
      assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.READ), this.identities[4]));
      assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.CREATE, BasicACLPermission.DELETE),
            this.identities[4]));
      assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.CREATE, BasicACLPermission.UPDATE,
            BasicACLPermission.DELETE), this.identities[4]));
      assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.values()), this.identities[4]));
   }
View Full Code Here

            BasicACLPermission.READ), IdentityFactory.createIdentity("Identity-2")));
      this.persistedEntries.add(new ACLEntryImpl(new CompositeACLPermission(BasicACLPermission.values()),
            IdentityFactory.createIdentity("Identity-3")));

      // create the test acls.
      this.persistedACLs.add(new ACLImpl(new TestResource(100, "Resource-1")));
      this.persistedACLs.add(new ACLImpl(new TestResource(200, "Resource-2"), new ArrayList<ACLEntry>(
            this.persistedEntries)));

      // persist everything.
      for (ACL acl : this.persistedACLs)
         this.persistEntity(acl);
View Full Code Here

   {
      // remove the persisted entities - removing the acl also removes the entries.
      for (ACLImpl acl : this.persistedACLs)
      {
         // re-attach the acl before removing.
         ACLImpl attachedACL = this.entityManager.find(ACLImpl.class, acl.getACLId());
         this.removeEntity(attachedACL);
      }

      // assert the acls have been removed.
      for (ACLImpl acl : this.persistedACLs)
View Full Code Here

   {
      // clear the entity manager's cache.
      this.entityManager.clear();

      // load the ACLs from the database using their primary key and validate them.
      ACLImpl loadedACL1 = this.entityManager.find(ACLImpl.class, this.persistedACLs.get(0).getACLId());
      assertNotNull("ACL1 could not be retrieved", loadedACL1);
      assertEquals("Loaded ACL contains unexpected number of entries", 0, loadedACL1.getEntries().size());
      assertNull(loadedACL1.getResource());

      ACLImpl loadedACL2 = this.entityManager.find(ACLImpl.class, this.persistedACLs.get(1).getACLId());
      assertNotNull("ACL2 could not be retrieved", loadedACL2);
      assertEquals("Loaded ACL contains unexpected number of entries", 3, loadedACL2.getEntries().size());
      assertTrue(loadedACL2.getEntries().contains(this.persistedEntries.get(0)));
      assertTrue(loadedACL2.getEntries().contains(this.persistedEntries.get(1)));
      assertTrue(loadedACL2.getEntries().contains(this.persistedEntries.get(2)));
      assertNull(loadedACL2.getResource());

      // find the ACLs using the resource and validate the result.
      ACLImpl acl = this.persistedACLs.get(0);
      ACLImpl queryResult = (ACLImpl) this.entityManager.createQuery(
            "SELECT a FROM ACLImpl a WHERE a.resourceAsString LIKE '" + Util.getResourceAsString(acl.getResource())
                  + "'").getSingleResult();
      assertNotNull("ACL1 could not be retrieved by it's resource", queryResult);
      assertEquals("Queried ACL id does not match the expected id", acl.getACLId(), queryResult.getACLId());
      assertEquals("Queried ACL contains unexpected number of entries", 0, queryResult.getEntries().size());

      acl = this.persistedACLs.get(1);
      queryResult = (ACLImpl) this.entityManager.createQuery(
            "SELECT a FROM ACLImpl a WHERE a.resourceAsString LIKE '" + Util.getResourceAsString(acl.getResource())
                  + "'").getSingleResult();
      assertNotNull("ACL2 could not be retrieved by it's resource", queryResult);
      assertEquals("Queried ACL id does not match the expected id", acl.getACLId(), queryResult.getACLId());
      assertEquals("Queried ACL contains unexpected number of entries", 3, queryResult.getEntries().size());
      assertTrue(queryResult.getEntries().contains(this.persistedEntries.get(0)));
      assertTrue(queryResult.getEntries().contains(this.persistedEntries.get(1)));
      assertTrue(queryResult.getEntries().contains(this.persistedEntries.get(2)));

   }
View Full Code Here

      ACLEntryImpl entry5 = new ACLEntryImpl(new CompositeACLPermission(BasicACLPermission.CREATE,
            BasicACLPermission.DELETE), IdentityFactory.createIdentity("Identity-5"));
      ACLEntryImpl entry6 = new ACLEntryImpl(new CompositeACLPermission(BasicACLPermission.values()), IdentityFactory
            .createIdentity("Identity-6"));

      ACLImpl acl1 = null;
      ACLImpl acl2 = null;
      EntityTransaction transaction = this.entityManager.getTransaction();
      transaction.begin();
      try
      {
         acl1 = this.entityManager.merge(this.persistedACLs.get(0));
         acl1.addEntry(entry4);
         acl1.addEntry(entry5);

         acl2 = this.entityManager.merge(this.persistedACLs.get(1));
         acl2.addEntry(entry6);
         acl2.removeEntry(this.persistedEntries.get(0));
         transaction.commit();
      }
      catch (RuntimeException re)
      {
         re.printStackTrace();
         transaction.rollback();
      }

      // add the new entries to the persisted entries collection.
      this.persistedEntries.add(entry4);
      this.persistedEntries.add(entry5);
      this.persistedEntries.add(entry6);

      // clear the entity manager's cache.
      this.entityManager.clear();

      // load the ACLs again and validate the changes.
      ACLImpl loadedACL1 = this.entityManager.find(ACLImpl.class, acl1.getACLId());
      assertNotNull("ACL1 could not be retrieved", loadedACL1);
      assertEquals("Loaded ACL contains unexpected number of entries", 2, loadedACL1.getEntries().size());
      assertTrue(loadedACL1.getEntries().contains(entry4));
      assertTrue(loadedACL1.getEntries().contains(entry5));

      ACLImpl loadedACL2 = this.entityManager.find(ACLImpl.class, acl2.getACLId());
      assertNotNull("ACL2 could not be retrieved", loadedACL2);
      assertEquals("Loaded AC2 contains unexpected number of entries", 3, loadedACL2.getEntries().size());
      assertFalse(loadedACL2.getEntries().contains(this.persistedEntries.get(0)));
      assertTrue(loadedACL2.getEntries().contains(this.persistedEntries.get(1)));
      assertTrue(loadedACL2.getEntries().contains(this.persistedEntries.get(2)));
      assertTrue(loadedACL2.getEntries().contains(entry6));
   }
View Full Code Here

TOP

Related Classes of org.jboss.security.acl.ACLImpl

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.