Search in sources :

Example 1 with SecuredAlt

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

the class SecuredAltImpl method getInstance.

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

Example 2 with SecuredAlt

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

the class SecuredSeqTest method testGetAlt.

@Test
public void testGetAlt() {
    try {
        final Alt a = getSecuredSeq().getAlt(1);
        Assert.assertTrue("Should be a secured Alt", a instanceof SecuredAlt);
        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) SecuredAlt(org.apache.jena.permissions.model.SecuredAlt) Alt(org.apache.jena.rdf.model.Alt) SecuredAlt(org.apache.jena.permissions.model.SecuredAlt) Test(org.junit.Test)

Aggregations

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