Search in sources :

Example 1 with SecuredBag

use of org.apache.jena.permissions.model.SecuredBag in project jena by apache.

the class SecuredBagImpl method getInstance.

/**
	 * Get an instance of SecuredBag
	 * 
	 * @param securedModel
	 *            The Secured Model to use.
	 * @param bag
	 *            The bag to secure
	 * @return The SecuredBag
	 */
public static SecuredBag getInstance(final SecuredModel securedModel, final Bag bag) {
    if (securedModel == null) {
        throw new IllegalArgumentException("Secured securedModel may not be null");
    }
    if (bag == null) {
        throw new IllegalArgumentException("Bag may not be null");
    }
    final ItemHolder<Bag, SecuredBag> holder = new ItemHolder<>(bag);
    final SecuredBagImpl checker = new SecuredBagImpl(securedModel, holder);
    // one.
    if (bag instanceof SecuredBag) {
        if (checker.isEquivalent((SecuredBag) bag)) {
            return (SecuredBag) bag;
        }
    }
    return holder.setSecuredItem(new SecuredItemInvoker(bag.getClass(), checker));
}
Also used : ItemHolder(org.apache.jena.permissions.impl.ItemHolder) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) SecuredBag(org.apache.jena.permissions.model.SecuredBag) SecuredBag(org.apache.jena.permissions.model.SecuredBag) Bag(org.apache.jena.rdf.model.Bag)

Example 2 with SecuredBag

use of org.apache.jena.permissions.model.SecuredBag in project jena by apache.

the class SecuredSeqTest method testGetBag.

@Test
public void testGetBag() {
    try {
        final Bag a = getSecuredSeq().getBag(1);
        Assert.assertTrue("Should be a secured Bag", a instanceof SecuredBag);
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : ReadDeniedException(org.apache.jena.shared.ReadDeniedException) SecuredBag(org.apache.jena.permissions.model.SecuredBag) Bag(org.apache.jena.rdf.model.Bag) SecuredBag(org.apache.jena.permissions.model.SecuredBag) Test(org.junit.Test)

Aggregations

SecuredBag (org.apache.jena.permissions.model.SecuredBag)2 Bag (org.apache.jena.rdf.model.Bag)2 ItemHolder (org.apache.jena.permissions.impl.ItemHolder)1 SecuredItemInvoker (org.apache.jena.permissions.impl.SecuredItemInvoker)1 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)1 Test (org.junit.Test)1