Search in sources :

Example 1 with SecuredPrefixMapping

use of org.apache.jena.permissions.graph.SecuredPrefixMapping in project jena by apache.

the class SecuredPrefixMappingTest method runTests.

public static void runTests(final SecurityEvaluator securityEvaluator, final PrefixMapping prefixMapping) throws Exception {
    final PrefixMapping pm = prefixMapping;
    Assert.assertNotNull("PrefixMapping may not be null", pm);
    Assert.assertTrue("PrefixMapping should be secured", pm instanceof SecuredPrefixMapping);
    final SecuredPrefixMappingTest pmTest = new SecuredPrefixMappingTest(securityEvaluator) {

        @Override
        public void setup() {
            this.securedMapping = (SecuredPrefixMapping) pm;
        }
    };
    Method lockTest = null;
    for (final Method m : pmTest.getClass().getMethods()) {
        if (m.isAnnotationPresent(Test.class)) {
            // lock test must come last
            if (m.getName().equals("testLock")) {
                lockTest = m;
            } else {
                pmTest.setup();
                m.invoke(pmTest);
            }
        }
    }
    Assert.assertNotNull("Did not find 'testLock' method", lockTest);
    pmTest.setup();
    lockTest.invoke(pmTest);
}
Also used : PrefixMapping(org.apache.jena.shared.PrefixMapping) SecuredPrefixMapping(org.apache.jena.permissions.graph.SecuredPrefixMapping) SecuredPrefixMapping(org.apache.jena.permissions.graph.SecuredPrefixMapping) Method(java.lang.reflect.Method)

Example 2 with SecuredPrefixMapping

use of org.apache.jena.permissions.graph.SecuredPrefixMapping in project jena by apache.

the class SecuredPrefixMappingImpl method withDefaultMappings.

@Override
public SecuredPrefixMapping withDefaultMappings(final PrefixMapping map) throws UpdateDeniedException, AuthenticationRequiredException {
    // mapping only updates if there are map entries to add. Since this gets
    // called
    // when we are doing deep triple checks while writing we need to attempt
    // the
    // update only if there are new updates to add.
    PrefixMapping m = holder.getBaseItem();
    PrefixMappingImpl pm = new PrefixMappingImpl();
    for (Entry<String, String> e : map.getNsPrefixMap().entrySet()) {
        if (m.getNsPrefixURI(e.getKey()) == null && m.getNsURIPrefix(e.getValue()) == null) {
            pm.setNsPrefix(e.getKey(), e.getValue());
        }
    }
    if (!pm.getNsPrefixMap().isEmpty()) {
        checkUpdate();
        holder.getBaseItem().withDefaultMappings(pm);
    }
    return holder.getSecuredItem();
}
Also used : SecuredPrefixMapping(org.apache.jena.permissions.graph.SecuredPrefixMapping) PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl)

Example 3 with SecuredPrefixMapping

use of org.apache.jena.permissions.graph.SecuredPrefixMapping in project jena by apache.

the class Factory method getInstance.

/**
 * Create an instance of SecuredPrefixMapping
 *
 * @param graph         The SecuredGraph that contains the prefixmapping.
 * @param prefixMapping The prefixmapping returned from the base graph.
 * @return The SecuredPrefixMapping.
 */
static SecuredPrefixMapping getInstance(final SecuredGraphImpl graph, final PrefixMapping prefixMapping) {
    final ItemHolder<PrefixMapping, SecuredPrefixMapping> holder = new ItemHolder<>(prefixMapping);
    final SecuredPrefixMappingImpl checker = new SecuredPrefixMappingImpl(graph, holder);
    // if we are going to create a duplicate proxy just return this one.
    if (prefixMapping instanceof SecuredPrefixMapping) {
        if (checker.isEquivalent((SecuredPrefixMapping) prefixMapping)) {
            return (SecuredPrefixMapping) prefixMapping;
        }
    }
    return holder.setSecuredItem(new SecuredItemInvoker(prefixMapping.getClass(), checker));
}
Also used : SecuredPrefixMapping(org.apache.jena.permissions.graph.SecuredPrefixMapping) PrefixMapping(org.apache.jena.shared.PrefixMapping) ItemHolder(org.apache.jena.permissions.impl.ItemHolder) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) SecuredPrefixMapping(org.apache.jena.permissions.graph.SecuredPrefixMapping)

Aggregations

SecuredPrefixMapping (org.apache.jena.permissions.graph.SecuredPrefixMapping)3 PrefixMapping (org.apache.jena.shared.PrefixMapping)3 Method (java.lang.reflect.Method)1 ItemHolder (org.apache.jena.permissions.impl.ItemHolder)1 SecuredItemInvoker (org.apache.jena.permissions.impl.SecuredItemInvoker)1 PrefixMappingImpl (org.apache.jena.shared.impl.PrefixMappingImpl)1