gpt4 book ai didi

org.geoserver.security.WorkspaceAccessLimits类的使用及代码示例

转载 作者:知者 更新时间:2024-03-22 16:07:05 27 4
gpt4 key购买 nike

本文整理了Java中org.geoserver.security.WorkspaceAccessLimits类的一些代码示例,展示了WorkspaceAccessLimits类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WorkspaceAccessLimits类的具体详情如下:
包路径:org.geoserver.security.WorkspaceAccessLimits
类名称:WorkspaceAccessLimits

WorkspaceAccessLimits介绍

[英]Access limits to a workspace (the write flag controls also direct access to data stores, though normally only configuration code should be playing directy with stores)
[中]对工作区的访问限制(write标志还控制对数据存储的直接访问,尽管通常只有配置代码才应该直接与存储区打交道)

代码示例

代码示例来源:origin: geoserver/geoserver

protected WorkspaceAccessLimits intersection(WorkspaceAccessLimits a, WorkspaceAccessLimits b) {
  CatalogMode mode = intersection(a.getMode(), b.getMode());
  return new WorkspaceAccessLimits(
      mode,
      a.isReadable() && b.isReadable(),
      a.isWritable() && b.isWritable(),
      a.isAdminable() && b.isAdminable());
}

代码示例来源:origin: geoserver/geoserver

public WorkspaceAccessLimits(CatalogMode mode, boolean readable, boolean writable) {
  this(mode, readable, writable, isAuthenticatedAsAdmin());
}

代码示例来源:origin: org.geoserver.community/gs-geofence

public void IGNOREtestCiteWorkspaceAccess() {
  if (!IS_GEOFENCE_AVAILABLE) {
    return;
  }
  UsernamePasswordAuthenticationToken user =
      new UsernamePasswordAuthenticationToken("cite", "cite");
  // check workspace access on cite
  WorkspaceInfo citeWS = catalog.getWorkspaceByName(MockData.CITE_PREFIX);
  WorkspaceAccessLimits wl = accessManager.getAccessLimits(user, citeWS);
  assertTrue(wl.isReadable());
  assertTrue(wl.isWritable());
  // check workspace access on any other but not cite and sf (should fail)
  WorkspaceInfo cdfWS = catalog.getWorkspaceByName(MockData.CDF_PREFIX);
  wl = accessManager.getAccessLimits(user, cdfWS);
  assertFalse(wl.isReadable());
  assertFalse(wl.isWritable());
  // check workspace access on sf (should work, we can do at least a getmap)
  WorkspaceInfo sfWS = catalog.getWorkspaceByName(MockData.SF_PREFIX);
  wl = accessManager.getAccessLimits(user, sfWS);
  assertTrue(wl.isReadable());
  assertTrue(wl.isWritable());
}

代码示例来源:origin: geoserver/geoserver

WorkspaceAccessLimits wl = (WorkspaceAccessLimits) limits;
if (wl != null) {
  if (wl.isAdminable()) {
    canRead = canWrite = true;
  } else {
    canRead = wl.isReadable();
    canWrite = wl.isWritable();
  if (wl == null || !wl.isAdminable()) {
    canRead = canWrite = false;
  if (wl != null && !wl.isAdminable()) {
    canRead = false;
  WorkspaceAccessLimits wl = accessManager.getAccessLimits(user, ws);
  if (wl != null) {
    if (!wl.isAdminable()) {
      canRead = false;

代码示例来源:origin: geoserver/geoserver

@Override
public WorkspaceAccessLimits getAccessLimits(Authentication user, WorkspaceInfo workspace) {
  if (hideWorkspace(workspace)) {
    return new WorkspaceAccessLimits(CatalogMode.HIDE, false, false, false);
  } else {
    return super.getAccessLimits(user, workspace);
  }
}

代码示例来源:origin: org.geoserver.web/gs-web-core

/** Check if the current user has any admin privilege on at least one workspace. */
  boolean isWorkspaceAdmin(Authentication authentication) {

    Catalog catalog = getSecurityManager().getCatalog();

    // the secure catalog builds and owns the ResourceAccessManager
    SecureCatalogImpl secureCatalog =
        GeoServerApplication.get().getBeanOfType(SecureCatalogImpl.class);
    ResourceAccessManager manager = secureCatalog.getResourceAccessManager();

    if (manager != null) {
      for (WorkspaceInfo workspace : catalog.getWorkspaces()) {
        WorkspaceAccessLimits accessLimits =
            manager.getAccessLimits(authentication, workspace);
        if (accessLimits != null && accessLimits.isAdminable()) {
          return true;
        }
      }
    }

    return false;
  }
}

代码示例来源:origin: org.geoserver.extension/gs-geofence

@Test
public void testCiteWorkspaceAccess() {
  if (!IS_GEOFENCE_AVAILABLE) {
    return;
  }
  UsernamePasswordAuthenticationToken user =
      new UsernamePasswordAuthenticationToken("cite", "cite");
  // check workspace access on cite
  WorkspaceInfo citeWS = catalog.getWorkspaceByName(MockData.CITE_PREFIX);
  WorkspaceAccessLimits wl = accessManager.getAccessLimits(user, citeWS);
  assertTrue(wl.isReadable());
  assertTrue(wl.isWritable());
  // check workspace access on any other but not cite and sf (should fail)
  WorkspaceInfo cdfWS = catalog.getWorkspaceByName(MockData.CDF_PREFIX);
  wl = accessManager.getAccessLimits(user, cdfWS);
  assertFalse(wl.isReadable());
  assertFalse(wl.isWritable());
  // check workspace access on sf (should work, we can do at least a getmap)
  WorkspaceInfo sfWS = catalog.getWorkspaceByName(MockData.SF_PREFIX);
  wl = accessManager.getAccessLimits(user, sfWS);
  assertTrue(wl.isReadable());
  assertTrue(wl.isWritable());
}

代码示例来源:origin: org.geoserver.security/gs-security-tests

private boolean canAccess(
      ResourceAccessManager manager,
      Authentication user,
      WorkspaceInfo catalogInfo,
      AccessMode mode) {
    WorkspaceAccessLimits limits = manager.getAccessLimits(user, catalogInfo);
    if (limits == null) {
      return true;
    } else if (mode == AccessMode.READ) {
      return limits.isReadable();
    } else if (mode == AccessMode.WRITE) {
      return limits.isWritable();
    } else if (mode == AccessMode.ADMIN) {
      return limits.isAdminable();
    } else {
      throw new RuntimeException("Unknown access mode " + mode);
    }
  }
}

代码示例来源:origin: geoserver/geoserver

public WorkspaceAccessLimits getAccessLimits(Authentication user, WorkspaceInfo workspace) {
  boolean readable = canAccess(user, workspace, AccessMode.READ);
  boolean writable = canAccess(user, workspace, AccessMode.WRITE);
  boolean adminable = canAccess(user, workspace, AccessMode.ADMIN);
  CatalogMode mode = getMode();
  if (readable && writable) {
    if (AdminRequest.get() == null) {
      // not admin request, read+write means full acesss
      return null;
    }
  }
  return new WorkspaceAccessLimits(mode, readable, writable, adminable);
}

代码示例来源:origin: org.geoserver.community/gs-geofence

@Test
public void testCiteCannotWriteOnWorkspace() {
  if (!IS_GEOFENCE_AVAILABLE) {
    return;
  }
  configManager.getConfiguration().setGrantWriteToWorkspacesToAuthenticatedUsers(false);
  UsernamePasswordAuthenticationToken user =
      new UsernamePasswordAuthenticationToken(
          "cite",
          "cite",
          Arrays.asList(
              new GrantedAuthority[] {
                new SimpleGrantedAuthority("ROLE_AUTHENTICATED")
              }));
  // check workspace access
  WorkspaceInfo citeWS = catalog.getWorkspaceByName(MockData.CITE_PREFIX);
  WorkspaceAccessLimits wl = accessManager.getAccessLimits(user, citeWS);
  assertTrue(wl.isReadable());
  assertFalse(wl.isWritable());
}

代码示例来源:origin: geoserver/geoserver

public WorkspaceAccessLimits getAccessLimits(Authentication user, WorkspaceInfo workspace) {
  boolean readable = delegate.canAccess(user, workspace, AccessMode.READ);
  boolean writable = delegate.canAccess(user, workspace, AccessMode.WRITE);
  boolean adminable = delegate.canAccess(user, workspace, AccessMode.ADMIN);
  CatalogMode mode = delegate.getMode();
  if (readable && writable) {
    if (AdminRequest.get() == null) {
      // not admin request, read+write means full acesss
      return null;
    }
  }
  return new WorkspaceAccessLimits(mode, readable, writable, adminable);
}

代码示例来源:origin: org.geoserver.extension/gs-geofence

@Test
public void testCiteCannotWriteOnWorkspace() {
  if (!IS_GEOFENCE_AVAILABLE) {
    return;
  }
  configManager.getConfiguration().setGrantWriteToWorkspacesToAuthenticatedUsers(false);
  UsernamePasswordAuthenticationToken user =
      new UsernamePasswordAuthenticationToken(
          "cite",
          "cite",
          Arrays.asList(
              new GrantedAuthority[] {
                new SimpleGrantedAuthority("ROLE_AUTHENTICATED")
              }));
  // check workspace access
  WorkspaceInfo citeWS = catalog.getWorkspaceByName(MockData.CITE_PREFIX);
  WorkspaceAccessLimits wl = accessManager.getAccessLimits(user, citeWS);
  assertTrue(wl.isReadable());
  assertFalse(wl.isWritable());
}

代码示例来源:origin: org.geoserver.security/gs-security-tests

public void testSerializeWorkspaceAccessLimits() throws Exception {
  WorkspaceAccessLimits limits =
      new WorkspaceAccessLimits(CatalogMode.HIDE, true, true, true);
  testObjectSerialization(limits);
}

代码示例来源:origin: org.geoserver.community/gs-geofence

@Test
public void testCiteCanWriteOnWorkspace() {
  if (!IS_GEOFENCE_AVAILABLE) {
    return;
  }
  configManager.getConfiguration().setGrantWriteToWorkspacesToAuthenticatedUsers(true);
  UsernamePasswordAuthenticationToken user =
      new UsernamePasswordAuthenticationToken(
          "cite",
          "cite",
          Arrays.asList(
              new GrantedAuthority[] {
                new SimpleGrantedAuthority("ROLE_AUTHENTICATED")
              }));
  // check workspace access
  WorkspaceInfo citeWS = catalog.getWorkspaceByName(MockData.CITE_PREFIX);
  WorkspaceAccessLimits wl = accessManager.getAccessLimits(user, citeWS);
  assertTrue(wl.isReadable());
  assertTrue(wl.isWritable());
  configManager.getConfiguration().setGrantWriteToWorkspacesToAuthenticatedUsers(false);
}

代码示例来源:origin: org.geoserver.community/gs-geofence

@Override
public WorkspaceAccessLimits getAccessLimits(Authentication user, WorkspaceInfo workspace) {
  LOGGER.log(Level.FINE, "Getting access limits for workspace {0}", workspace.getName());
  if ((user != null) && !(user instanceof AnonymousAuthenticationToken)) {
    // shortcut, if the user is the admin, he can do everything
    if (isAdmin(user)) {
      LOGGER.log(
          Level.FINE,
          "Admin level access, returning " + "full rights for workspace {0}",
          workspace.getName());
      return new WorkspaceAccessLimits(DEFAULT_CATALOG_MODE, true, true);
    }
    boolean canWrite =
        configurationManager
            .getConfiguration()
            .isGrantWriteToWorkspacesToAuthenticatedUsers();
    boolean canAdmin = isWorkspaceAdmin(user, workspace.getName());
    return new WorkspaceAccessLimits(DEFAULT_CATALOG_MODE, true, canWrite, canAdmin);
  }
  // further logic disabled because of https://github.com/geosolutions-it/geofence/issues/6
  return new WorkspaceAccessLimits(DEFAULT_CATALOG_MODE, true, false);
}

代码示例来源:origin: org.geoserver.extension/gs-geofence

@Test
public void testCiteCanWriteOnWorkspace() {
  if (!IS_GEOFENCE_AVAILABLE) {
    return;
  }
  configManager.getConfiguration().setGrantWriteToWorkspacesToAuthenticatedUsers(true);
  UsernamePasswordAuthenticationToken user =
      new UsernamePasswordAuthenticationToken(
          "cite",
          "cite",
          Arrays.asList(
              new GrantedAuthority[] {
                new SimpleGrantedAuthority("ROLE_AUTHENTICATED")
              }));
  // check workspace access
  WorkspaceInfo citeWS = catalog.getWorkspaceByName(MockData.CITE_PREFIX);
  WorkspaceAccessLimits wl = accessManager.getAccessLimits(user, citeWS);
  assertTrue(wl.isReadable());
  assertTrue(wl.isWritable());
  configManager.getConfiguration().setGrantWriteToWorkspacesToAuthenticatedUsers(false);
}

代码示例来源:origin: org.geoserver.extension/gs-geofence

@Override
public WorkspaceAccessLimits getAccessLimits(Authentication user, WorkspaceInfo workspace) {
  LOGGER.log(Level.FINE, "Getting access limits for workspace {0}", workspace.getName());
  if ((user != null) && !(user instanceof AnonymousAuthenticationToken)) {
    // shortcut, if the user is the admin, he can do everything
    if (isAdmin(user)) {
      LOGGER.log(
          Level.FINE,
          "Admin level access, returning " + "full rights for workspace {0}",
          workspace.getName());
      return new WorkspaceAccessLimits(DEFAULT_CATALOG_MODE, true, true);
    }
    boolean canWrite =
        configurationManager
            .getConfiguration()
            .isGrantWriteToWorkspacesToAuthenticatedUsers();
    boolean canAdmin = isWorkspaceAdmin(user, workspace.getName());
    return new WorkspaceAccessLimits(DEFAULT_CATALOG_MODE, true, canWrite, canAdmin);
  }
  // further logic disabled because of https://github.com/geosolutions-it/geofence/issues/6
  return new WorkspaceAccessLimits(DEFAULT_CATALOG_MODE, true, false);
}

代码示例来源:origin: org.geoserver.community/gs-geofence

@Test
public void testAdmin() {
  if (!IS_GEOFENCE_AVAILABLE) {
    return;
  }
  UsernamePasswordAuthenticationToken user =
      new UsernamePasswordAuthenticationToken(
          "admin",
          "geoserver",
          Arrays.asList(
              new GrantedAuthority[] {
                new SimpleGrantedAuthority("ROLE_ADMINISTRATOR")
              }));
  // check workspace access
  WorkspaceInfo citeWS = catalog.getWorkspaceByName(MockData.CITE_PREFIX);
  WorkspaceAccessLimits wl = accessManager.getAccessLimits(user, citeWS);
  assertTrue(wl.isReadable());
  assertTrue(wl.isWritable());
  // check layer access
  LayerInfo layer = catalog.getLayerByName(getLayerId(MockData.BASIC_POLYGONS));
  VectorAccessLimits vl = (VectorAccessLimits) accessManager.getAccessLimits(user, layer);
  assertEquals(Filter.INCLUDE, vl.getReadFilter());
  assertEquals(Filter.INCLUDE, vl.getWriteFilter());
  assertNull(vl.getReadAttributes());
  assertNull(vl.getWriteAttributes());
}

代码示例来源:origin: org.geoserver.security/gs-security-tests

@Test
public void testReadOnlySource() throws Exception {
  ReadOnlyDataStore ro =
      new ReadOnlyDataStore(
          ds,
          WrapperPolicy.readOnlyHide(
              new WorkspaceAccessLimits(CatalogMode.HIDE, true, false, false)));
  SimpleFeatureSource fs = ro.getFeatureSource("blah");
  // used to go boom here
  SimpleFeatureCollection fc = fs.getFeatures(Query.ALL);
  assertEquals(0, fc.size());
}

代码示例来源:origin: org.geoserver.extension/gs-geofence

@Test
public void testAdmin() {
  if (!IS_GEOFENCE_AVAILABLE) {
    return;
  }
  assertTrue(geofenceAdminService.getCountAll() > 0);
  RuleFilter ruleFilter = new RuleFilter();
  ShortRule adminRule = geofenceAdminService.getRule(ruleFilter);
  UsernamePasswordAuthenticationToken user =
      new UsernamePasswordAuthenticationToken(
          "admin",
          "geoserver",
          Arrays.asList(
              new GrantedAuthority[] {
                new SimpleGrantedAuthority("ROLE_ADMINISTRATOR")
              }));
  // check workspace access
  WorkspaceInfo citeWS = catalog.getWorkspaceByName(MockData.CITE_PREFIX);
  WorkspaceAccessLimits wl = accessManager.getAccessLimits(user, citeWS);
  assertTrue(wl.isReadable());
  assertTrue(wl.isWritable());
  // check layer access
  LayerInfo layer = catalog.getLayerByName(getLayerId(MockData.BASIC_POLYGONS));
  VectorAccessLimits vl = (VectorAccessLimits) accessManager.getAccessLimits(user, layer);
  assertEquals(Filter.INCLUDE, vl.getReadFilter());
  assertEquals(Filter.INCLUDE, vl.getWriteFilter());
  assertNull(vl.getReadAttributes());
  assertNull(vl.getWriteAttributes());
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com