@Test public void getPermissionsDoesNotReturnWritePermissionsForRsImportedDataSet() throws Exception { VreAuthorization vreAuthorization = mock(VreAuthorization.class); List<String> userRoles = Lists.newArrayList("USER"); given(vreAuthorization.getRoles()).willReturn(userRoles); given(permissionConfig.getPermissionsForRoles(userRoles)).willReturn(Sets.newHashSet( Permission.WRITE, Permission.READ )); given(vreAuthorizationCrud.getAuthorization( anyString(), any(User.class)) ).willReturn(Optional.of(vreAuthorization)); ImportInfo importInfo = new ImportInfo("http: given(publishedDataSetMetaData.getImportInfo()) .willReturn(Lists.newArrayList(importInfo)); Set<Permission> permissions = permissionFetcher.getPermissions(mock(User.class), publishedDataSetMetaData); assertThat(permissions, contains(Permission.READ)); }
@Override public Set<Permission> getPermissions(User user, DataSetMetaData dataSetMetadata) throws PermissionFetchingException { String ownerId = dataSetMetadata.getOwnerId(); String dataSetId = dataSetMetadata.getDataSetId(); String vreId = createCombinedId(ownerId, dataSetId); Set<Permission> permissions = new HashSet<>(); if (dataSetMetadata.isPublished()) { permissions.add(Permission.READ); } try { if (user != null) { Optional<VreAuthorization> vreAuthorization = vreAuthorizationCrud.getAuthorization(vreId, user); if (vreAuthorization.isPresent()) { permissions.addAll(permissionConfig.getPermissionsForRoles(vreAuthorization.get().getRoles())); if (isResourceSyncCopy(dataSetMetadata)) { permissions.remove(Permission.WRITE); } } } return permissions; } catch (AuthorizationUnavailableException e) { LOG.error("Authorizations unavailable", e); return permissions; } }
BasicPermissionFetcher implements PermissionFetcher { @Override public Set<Permission> getPermissions(User user, DataSetMetaData dataSetMetadata) throws PermissionFetchingException { String ownerId = dataSetMetadata.getOwnerId(); String dataSetId = dataSetMetadata.getDataSetId(); String vreId = createCombinedId(ownerId, dataSetId); Set<Permission> permissions = new HashSet<>(); if (dataSetMetadata.isPublished()) { permissions.add(Permission.READ); } try { if (user != null) { Optional<VreAuthorization> vreAuthorization = vreAuthorizationCrud.getAuthorization(vreId, user); if (vreAuthorization.isPresent()) { permissions.addAll(permissionConfig.getPermissionsForRoles(vreAuthorization.get().getRoles())); if (isResourceSyncCopy(dataSetMetadata)) { permissions.remove(Permission.WRITE); } } } return permissions; } catch (AuthorizationUnavailableException e) { LOG.error("Authorizations unavailable", e); return permissions; } } }
BasicPermissionFetcher implements PermissionFetcher { @Override public Set<Permission> getPermissions(User user, DataSetMetaData dataSetMetadata) throws PermissionFetchingException { String ownerId = dataSetMetadata.getOwnerId(); String dataSetId = dataSetMetadata.getDataSetId(); String vreId = createCombinedId(ownerId, dataSetId); Set<Permission> permissions = new HashSet<>(); if (dataSetMetadata.isPublished()) { permissions.add(Permission.READ); } try { if (user != null) { Optional<VreAuthorization> vreAuthorization = vreAuthorizationCrud.getAuthorization(vreId, user); if (vreAuthorization.isPresent()) { permissions.addAll(permissionConfig.getPermissionsForRoles(vreAuthorization.get().getRoles())); if (isResourceSyncCopy(dataSetMetadata)) { permissions.remove(Permission.WRITE); } } } return permissions; } catch (AuthorizationUnavailableException e) { LOG.error("Authorizations unavailable", e); return permissions; } } BasicPermissionFetcher(VreAuthorizationCrud vreAuthorizationCrud, PermissionConfiguration permissionConfig); }
BasicPermissionFetcher implements PermissionFetcher { @Override public Set<Permission> getPermissions(User user, DataSetMetaData dataSetMetadata) throws PermissionFetchingException { String ownerId = dataSetMetadata.getOwnerId(); String dataSetId = dataSetMetadata.getDataSetId(); String vreId = createCombinedId(ownerId, dataSetId); Set<Permission> permissions = new HashSet<>(); if (dataSetMetadata.isPublished()) { permissions.add(Permission.READ); } try { if (user != null) { Optional<VreAuthorization> vreAuthorization = vreAuthorizationCrud.getAuthorization(vreId, user); if (vreAuthorization.isPresent()) { permissions.addAll(permissionConfig.getPermissionsForRoles(vreAuthorization.get().getRoles())); if (isResourceSyncCopy(dataSetMetadata)) { permissions.remove(Permission.WRITE); } } } return permissions; } catch (AuthorizationUnavailableException e) { LOG.error("Authorizations unavailable", e); return permissions; } } BasicPermissionFetcher(VreAuthorizationCrud vreAuthorizationCrud, PermissionConfiguration permissionConfig); @Override Set<Permission> getPermissions(User user, DataSetMetaData dataSetMetadata); @Override boolean hasPermission(User user, DataSetMetaData dataSet, Permission permission); @Override @Deprecated Set<Permission> getOldPermissions(User user, String vreId); @Override void initializeOwnerAuthorization(User user, String ownerId, String dataSetId); @Override void removeAuthorizations(String vreId); }
BasicPermissionFetcher implements PermissionFetcher { @Override public Set<Permission> getPermissions(User user, DataSetMetaData dataSetMetadata) throws PermissionFetchingException { String ownerId = dataSetMetadata.getOwnerId(); String dataSetId = dataSetMetadata.getDataSetId(); String vreId = createCombinedId(ownerId, dataSetId); Set<Permission> permissions = new HashSet<>(); if (dataSetMetadata.isPublished()) { permissions.add(Permission.READ); } try { if (user != null) { Optional<VreAuthorization> vreAuthorization = vreAuthorizationCrud.getAuthorization(vreId, user); if (vreAuthorization.isPresent()) { permissions.addAll(permissionConfig.getPermissionsForRoles(vreAuthorization.get().getRoles())); if (isResourceSyncCopy(dataSetMetadata)) { permissions.remove(Permission.WRITE); } } } return permissions; } catch (AuthorizationUnavailableException e) { LOG.error("Authorizations unavailable", e); return permissions; } } BasicPermissionFetcher(VreAuthorizationCrud vreAuthorizationCrud, PermissionConfiguration permissionConfig); @Override Set<Permission> getPermissions(User user, DataSetMetaData dataSetMetadata); @Override boolean hasPermission(User user, DataSetMetaData dataSet, Permission permission); @Override @Deprecated Set<Permission> getOldPermissions(User user, String vreId); @Override void initializeOwnerAuthorization(User user, String ownerId, String dataSetId); @Override void removeAuthorizations(String vreId);  }