Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@
import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_READ_PROPERTIES;
import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_WRITE_PROPERTIES;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -155,7 +157,8 @@
public class PolarisAuthorizerImpl implements PolarisAuthorizer {
private static final Logger LOGGER = LoggerFactory.getLogger(PolarisAuthorizerImpl.class);

private static final SetMultimap<PolarisPrivilege, PolarisPrivilege> SUPER_PRIVILEGES =
@VisibleForTesting
static final SetMultimap<PolarisPrivilege, PolarisPrivilege> SUPER_PRIVILEGES =
HashMultimap.create();

static {
Expand Down Expand Up @@ -725,6 +728,16 @@ public class PolarisAuthorizerImpl implements PolarisAuthorizer {
List.of(TABLE_DETACH_POLICY, CATALOG_MANAGE_METADATA, CATALOG_MANAGE_CONTENT));
}

/**
* Returns all the privileges that subsume the given privilege. Note that the returned set always
* includes the given privilege itself.
*/
public static Set<PolarisPrivilege> subsumingPrivilegesOf(PolarisPrivilege privilege) {
return SUPER_PRIVILEGES.containsKey(privilege)
? SUPER_PRIVILEGES.get(privilege)
: EnumSet.of(privilege);
}

private final RealmConfig realmConfig;

public PolarisAuthorizerImpl(RealmConfig realmConfig) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.polaris.core.auth;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.EnumSet;
import java.util.Set;
import org.apache.polaris.core.entity.PolarisPrivilege;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

public class PolarisAuthorizerImplTest {

@ParameterizedTest
@EnumSource(PolarisPrivilege.class)
void subsumingPrivilegesOf(PolarisPrivilege privilege) {
Set<PolarisPrivilege> actual = PolarisAuthorizerImpl.subsumingPrivilegesOf(privilege);
assertThat(actual).isNotEmpty().contains(privilege);
Set<PolarisPrivilege> expected =
PolarisAuthorizerImpl.SUPER_PRIVILEGES.containsKey(privilege)
? PolarisAuthorizerImpl.SUPER_PRIVILEGES.get(privilege)
: EnumSet.of(privilege);
assertThat(actual).isEqualTo(expected);
}
}
3 changes: 3 additions & 0 deletions runtime/service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ dependencies {

runtimeOnly(project(":polaris-async-vertx"))

testCompileOnly(project(":polaris-immutables"))
testAnnotationProcessor(project(":polaris-immutables", configuration = "processor"))

testFixturesApi(project(":polaris-tests")) {
// exclude all spark dependencies
exclude(group = "org.apache.iceberg", module = "iceberg-spark-3.5_2.12")
Expand Down
Loading