/** * Checks if the provided store is visible in the current context. * * @param store the store to check, may be NULL * @return the store if visible, otherwise NULL */ private <T extends StoreInfo> T enforceStoreIsolation(T store) { if (store == null) { // nothing to do, the store is already NULL return null; } WorkspaceInfo workspace = store.getWorkspace(); // check if the store workspace is visible in this context return canSeeWorkspace(workspace) ? store : null; }
private void checkLayerGroupResourceIsInWorkspace(LayerInfo layer, WorkspaceInfo ws) { if (layer == null) return; ResourceInfo r = layer.getResource(); if (r.getStore().getWorkspace() != null && !ws.equals(r.getStore().getWorkspace())) { throw new IllegalArgumentException( "Layer group within a workspace (" + ws.getName() + ") can not contain resources from other workspace: " + r.getStore().getWorkspace().getName()); } }
public <T extends StoreInfo> List<T> getStoresByWorkspace( WorkspaceInfo workspace, Class<T> clazz) { // TODO: support ANY_WORKSPACE? WorkspaceInfo ws; if (workspace == null) { ws = getDefaultWorkspace(); } else { ws = workspace; } List<T> matches = stores.list(clazz, s -> ws.equals(s.getWorkspace())); return ModificationProxy.createList(matches, clazz); }
@Deprecated private String path(StoreInfo store) { WorkspaceInfo workspace = store.getWorkspace(); return Paths.path("workspaces", workspace.getName(), store.getName()); }
/** * Retrieve a resource in the the configuration directory of a Store. An empty path will * retrieve the directory itself. * * @param store The store * @return A {@link Resource} */ public @Nonnull Resource get(StoreInfo store, String... path) { Resource r = get(store.getWorkspace(), store.getName(), Paths.path(path)); assert r != null; return r; }
/** * Checks if the provided resource is visible in the current context. * * @param resource the resource to check, may be NULL * @return the resource if visible, otherwise NULL */ private <T extends ResourceInfo> T enforceResourceIsolation(T resource) { if (resource == null) { // nothing to do, the resource is already NULL return null; } // get the resource store StoreInfo store = resource.getStore(); if (store == null) { // since we can't check if the store is visible we let it go return resource; } WorkspaceInfo workspace = store.getWorkspace(); // check if the resource store workspace is visible in this context return canSeeWorkspace(workspace) ? resource : null; }
public void add(StoreInfo store) { if (store.getWorkspace() == null) { store.setWorkspace(getDefaultWorkspace()); } validate(store, true); // TODO: remove synchronized block, need transactions StoreInfo added; synchronized (facade) { added = facade.add(resolve(store)); // if there is no default store use this one as the default if (getDefaultDataStore(store.getWorkspace()) == null && store instanceof DataStoreInfo) { setDefaultDataStore(store.getWorkspace(), (DataStoreInfo) store); } } added(added); }
/** * Given a store and a user, returns it back if the user can access its workspace in read mode, * null otherwise */ protected <T extends StoreInfo> T checkAccess( Authentication user, T store, MixedModeBehavior mixedModeBehavior) { if (store == null) return null; WrapperPolicy policy = buildWrapperPolicy(user, store.getWorkspace(), store.getName(), mixedModeBehavior); // handle the modes that do not require wrapping if (policy.level == AccessLevel.HIDDEN) return null; else if (policy.level == AccessLevel.READ_WRITE || (policy.level == AccessLevel.READ_ONLY && store instanceof CoverageStoreInfo)) return store; // otherwise we are in a mixed case where the user can read but not // write, or // cannot read but is allowed by the operation mode to access the // metadata if (store instanceof DataStoreInfo || store instanceof CoverageStoreInfo || store instanceof WMSStoreInfo || store instanceof WMTSStoreInfo) { return (T) SecuredObjects.secure(store, policy); } else { throw new RuntimeException("Unknown store type " + store.getClass()); } }
public ValidationResult validate(StoreInfo store, boolean isNew) { if (isNull(store.getName())) { throw new IllegalArgumentException("Store name must not be null"); } if (store.getWorkspace() == null) { throw new IllegalArgumentException("Store must be part of a workspace"); } WorkspaceInfo workspace = store.getWorkspace(); StoreInfo existing = getStoreByName(workspace, store.getName(), StoreInfo.class); if (existing != null && (isNew || !existing.getId().equals(store.getId()))) { String msg = "Store '" + store.getName() + "' already exists in workspace '" + workspace.getName() + "'"; throw new IllegalArgumentException(msg); } return postValidate(store, isNew); }
public void remove(StoreInfo store) { if (!getResourcesByStore(store, ResourceInfo.class).isEmpty()) { throw new IllegalArgumentException("Unable to delete non-empty store."); } // TODO: remove synchronized block, need transactions synchronized (facade) { facade.remove(store); WorkspaceInfo workspace = store.getWorkspace(); DataStoreInfo defaultStore = getDefaultDataStore(workspace); if (store.equals(defaultStore) || defaultStore == null) { // TODO: this will fire multiple events, we want to fire only one setDefaultDataStore(workspace, null); // default removed, choose another store to become default if possible List dstores = getStoresByWorkspace(workspace, DataStoreInfo.class); if (!dstores.isEmpty()) { setDefaultDataStore(workspace, (DataStoreInfo) dstores.get(0)); } } } removed(store); }
public <T extends ResourceInfo> T getResourceByStore( StoreInfo store, String name, Class<T> clazz) { T resource = null; NamespaceInfo ns = null; if (store.getWorkspace() != null && store.getWorkspace().getName() != null && (ns = getNamespaceByPrefix(store.getWorkspace().getName())) != null) { resource = resources.findByName(new NameImpl(ns.getId(), name), clazz); if (resource != null && !(store.equals(resource.getStore()))) { return null; } } else { // should not happen, but some broken test code sets up namespaces without equivalent // workspaces // or stores without workspaces resource = resources.findFirst( clazz, r -> name.equals(r.getName()) && store.equals(r.getStore())); } return wrapInModificationProxy(resource, clazz); }
String findUniqueStyleName(ResourceInfo resource) { String styleName = resource.getStore().getWorkspace().getName() + "_" + resource.getName(); StyleInfo style = catalog.getStyleByName(styleName); int i = 1; while (style != null) { styleName = resource.getStore().getWorkspace().getName() + "_" + resource.getName() + i; style = catalog.getStyleByName(styleName); i++; } return styleName; }
public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof StoreInfo)) { return false; } final StoreInfo other = (StoreInfo) obj; if (connectionParameters == null) { if (other.getConnectionParameters() != null) return false; } else if (!connectionParameters.equals(other.getConnectionParameters())) return false; if (description == null) { if (other.getDescription() != null) return false; } else if (!description.equals(other.getDescription())) return false; if (enabled != other.isEnabled()) return false; if (id == null) { if (other.getId() != null) return false; } else if (!id.equals(other.getId())) return false; if (name == null) { if (other.getName() != null) return false; } else if (!name.equals(other.getName())) return false; if (workspace == null) { if (other.getWorkspace() != null) return false; } else if (!workspace.equals(other.getWorkspace())) return false; return true; } }
@Override public String prefixedName() { return this.getResource().getStore().getWorkspace().getName() + ":" + getName(); }
/** * Checks if the provided layer is visible in the current context. * * @param layer the layer to check, may be NULL * @return the layer if visible, otherwise NULL */ private <T extends LayerInfo> T enforceLayerIsolation(T layer) { if (layer == null) { // nothing to do, the layer is already NULL return null; } ResourceInfo resource = layer.getResource(); if (resource == null) { // this should not happen, there is not much we can do return layer; } StoreInfo store = resource.getStore(); if (store == null) { // since we can't check if the store is visible we let it go return layer; } WorkspaceInfo workspace = store.getWorkspace(); // check if the layer resource store workspace is visible in this context return canSeeWorkspace(workspace) ? layer : null; }
public boolean hideResource(ResourceInfo resource) { if (LocalPublished.get() != null) { for (LayerInfo l : resource.getCatalog().getLayers(resource)) { if (hideLayer(l)) { return true; } } } return hideWorkspace(resource.getStore().getWorkspace()); }
<T extends StoreInfo> void initStore( T s, Class<T> clazz, String sId, String name, WorkspaceInfo ws) { expect(s.getId()).andReturn(sId).anyTimes(); expect(s.getName()).andReturn(name).anyTimes(); expect(s.getWorkspace()).andReturn(ws).anyTimes(); expect(s.getCatalog()).andReturn(catalog).anyTimes(); expect(s.isEnabled()).andReturn(true).anyTimes(); expect(catalog.getStore(sId, clazz)).andReturn(s).anyTimes(); expect(catalog.getStore(sId, StoreInfo.class)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(name, clazz)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(name, StoreInfo.class)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(ws.getName(), name, clazz)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(ws.getName(), name, StoreInfo.class)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(ws, name, clazz)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(ws, name, StoreInfo.class)).andReturn(s).anyTimes(); }
template = dd.findSuppWorkspaceFile(resource.getStore().getWorkspace(), path); template = dd.findSuppWorkspacesFile(resource.getStore().getWorkspace(), path);
accessManager, user, ((StoreInfo) info).getWorkspace(), ((StoreInfo) info).getName(), mixedModeBehavior);
ftinfo.setName(name.getLocalPart()); WorkspaceInfo workspace = store.getWorkspace(); NamespaceInfo namespace = catalog.getNamespaceByPrefix(workspace.getName()); if (namespace == null) {