@Test public void returnsThePermissionsOfTheRoles() throws Exception { String rolePermissions = "[" + "{\n" + "\t\"roleName\": \"USER\",\n" + "\t\"permissions\": [\"REMOVE_DATASET\"]\n" + "},\n" + "{\n" + "\t\"roleName\": \"ADMIN\",\n" + "\t\"permissions\": [\"IMPORT_DATA\"]\n" + "},\n" + "{\n" + "\t\"roleName\": \"OTHER_ROLE\",\n" + "\t\"permissions\": [\"EDIT_COLLECTION_METADATA\"]\n" + "}" + "]"; ByteArrayInputStream configuration = new ByteArrayInputStream(rolePermissions.getBytes()); JsonPermissionConfiguration instance = new JsonPermissionConfiguration(configuration); Set<Permission> permissions = instance.getPermissionsForRoles(Lists.newArrayList("USER", "ADMIN")); assertThat(permissions, containsInAnyOrder(Permission.REMOVE_DATASET, Permission.IMPORT_DATA)); }
@Override public Set<Permission> getPermissionsForRoles(Collection<String> roles) { return rolePermissions.stream() .filter(rolePerm -> roles.contains(rolePerm.roleName)) .flatMap(rolePerm -> rolePerm.permissions.stream()) .collect(Collectors.toSet()); }
JsonPermissionConfiguration implements PermissionConfiguration { @Override public Set<Permission> getPermissionsForRoles(Collection<String> roles) { return rolePermissions.stream() .filter(rolePerm -> roles.contains(rolePerm.roleName)) .flatMap(rolePerm -> rolePerm.permissions.stream()) .collect(Collectors.toSet()); } }
JsonPermissionConfiguration implements PermissionConfiguration { @Override public Set<Permission> getPermissionsForRoles(Collection<String> roles) { return rolePermissions.stream() .filter(rolePerm -> roles.contains(rolePerm.roleName)) .flatMap(rolePerm -> rolePerm.permissions.stream()) .collect(Collectors.toSet()); } JsonPermissionConfiguration(InputStream permissionConfig); }
JsonPermissionConfiguration implements PermissionConfiguration { @Override public Set<Permission> getPermissionsForRoles(Collection<String> roles) { return rolePermissions.stream() .filter(rolePerm -> roles.contains(rolePerm.roleName)) .flatMap(rolePerm -> rolePerm.permissions.stream()) .collect(Collectors.toSet()); } JsonPermissionConfiguration(InputStream permissionConfig); @Override Set<Permission> getPermissionsForRoles(Collection<String> roles); }
JsonPermissionConfiguration implements PermissionConfiguration { @Override public Set<Permission> getPermissionsForRoles(Collection<String> roles) { return rolePermissions.stream() .filter(rolePerm -> roles.contains(rolePerm.roleName)) .flatMap(rolePerm -> rolePerm.permissions.stream()) .collect(Collectors.toSet()); } JsonPermissionConfiguration(InputStream permissionConfig); @Override Set<Permission> getPermissionsForRoles(Collection<String> roles);  }