/** * Create an instance of the SecuredGraph * * @param securityEvaluator The security evaluator to use * @param graphIRI The IRI for the graph. * @param graph The graph that we are wrapping. * @return the secured graph */ public static SecuredGraph getInstance( final SecurityEvaluator securityEvaluator, final String graphIRI, final Graph graph) { final ItemHolder<Graph, SecuredGraphImpl> holder = new ItemHolder<Graph, SecuredGraphImpl>(graph); final SecuredGraphImpl checker = new SecuredGraphImpl(securityEvaluator, graphIRI, holder) {}; // If we going to create a duplicate proxy return this one. if (graph instanceof SecuredGraphImpl) { if (checker.isEquivalent((SecuredGraphImpl) graph)) { return (SecuredGraph) graph; } } return holder.setSecuredItem(new SecuredItemInvoker(graph.getClass(), checker)); }
/** * 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, SecuredPrefixMapping>(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)); }
/** * Create an instance of the SecuredBulkUpdateHandler * * @param graph The SecuredGraph that created the handler * @param handler The unsecured handler from the base graph. * @return SecuredBulkUpdateHandler. */ static SecuredBulkUpdateHandler getInstance( final SecuredGraphImpl graph, final Graph baseGraph, final BulkUpdateHandler handler) { final ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler> holder = new ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler>(handler); final SecuredBulkUpdateHandlerImpl checker = new SecuredBulkUpdateHandlerImpl(graph, baseGraph, holder); // if we are going to create a duplicate proxy, just return this // one. if (handler instanceof SecuredBulkUpdateHandler) { if (checker.isEquivalent((SecuredBulkUpdateHandler) handler)) { return (SecuredBulkUpdateHandler) handler; } } return holder.setSecuredItem(new SecuredItemInvoker(handler.getClass(), checker)); }
@Override public SecuredPrefixMapping withDefaultMappings(final PrefixMapping map) { // 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(); }
@Override public SecuredPrefixMapping setNsPrefix(final String prefix, final String uri) { checkUpdate(); holder.getBaseItem().setNsPrefix(prefix, uri); return holder.getSecuredItem(); }
@Override public boolean samePrefixMappingAs(final PrefixMapping other) { checkRead(); return holder.getBaseItem().samePrefixMappingAs(other); }
@Override public SecuredPrefixMapping removeNsPrefix(final String prefix) { checkUpdate(); holder.getBaseItem().removeNsPrefix(prefix); return holder.getSecuredItem(); }
@Override public String qnameFor(final String uri) { checkRead(); return holder.getBaseItem().qnameFor(uri); }
@Override public SecuredPrefixMapping lock() { checkUpdate(); holder.getBaseItem().lock(); return holder.getSecuredItem(); }
@Override public String getNsURIPrefix(final String uri) { checkRead(); return holder.getBaseItem().getNsURIPrefix(uri); }
@Override public String getNsPrefixURI(final String prefix) { checkRead(); return holder.getBaseItem().getNsPrefixURI(prefix); }
@Override public Map<String, String> getNsPrefixMap() { checkRead(); return holder.getBaseItem().getNsPrefixMap(); }
@Override public String expandPrefix(final String prefixed) { checkRead(); return holder.getBaseItem().expandPrefix(prefixed); }
@Override public String shortForm(final String uri) { checkRead(); return holder.getBaseItem().shortForm(uri); }
@Override public SecuredPrefixMapping setNsPrefixes(final PrefixMapping other) { checkUpdate(); holder.getBaseItem().setNsPrefixes(other); return holder.getSecuredItem(); }
@Override public SecuredPrefixMapping setNsPrefixes(final Map<String, String> map) { checkUpdate(); holder.getBaseItem().setNsPrefixes(map); return holder.getSecuredItem(); }