|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.polaris.authz.api; |
| 20 | + |
| 21 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
| 22 | +import com.fasterxml.jackson.annotation.JsonInclude; |
| 23 | +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
| 24 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| 25 | +import com.google.errorprone.annotations.CanIgnoreReturnValue; |
| 26 | +import jakarta.annotation.Nonnull; |
| 27 | +import java.util.Collection; |
| 28 | +import org.apache.polaris.immutables.PolarisImmutable; |
| 29 | +import org.immutables.value.Value; |
| 30 | + |
| 31 | +/** |
| 32 | + * An {@link Acl ACL} entry holds the {@linkplain PrivilegeSet sets} of <em>granted</em> and |
| 33 | + * <em>restricted</em> ("separation of duties") {@linkplain Privilege privileges}. |
| 34 | + */ |
| 35 | +@PolarisImmutable |
| 36 | +@JsonSerialize(as = ImmutableAclEntry.class) |
| 37 | +@JsonDeserialize(as = ImmutableAclEntry.class) |
| 38 | +public interface AclEntry { |
| 39 | + @Value.Parameter(order = 1) |
| 40 | + @Value.Default |
| 41 | + // The 'CUSTOM/valueFilter' combination is there to only include non-empty privilege sets |
| 42 | + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = PrivilegeSetJsonFilter.class) |
| 43 | + default PrivilegeSet granted() { |
| 44 | + return PrivilegeSet.emptyPrivilegeSet(); |
| 45 | + } |
| 46 | + |
| 47 | + @Value.Parameter(order = 2) |
| 48 | + @Value.Default |
| 49 | + // The 'CUSTOM/valueFilter' combination is there to only include non-empty privilege sets |
| 50 | + @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = PrivilegeSetJsonFilter.class) |
| 51 | + default PrivilegeSet restricted() { |
| 52 | + return PrivilegeSet.emptyPrivilegeSet(); |
| 53 | + } |
| 54 | + |
| 55 | + @Value.NonAttribute |
| 56 | + @JsonIgnore |
| 57 | + default boolean isEmpty() { |
| 58 | + return granted().isEmpty() && restricted().isEmpty(); |
| 59 | + } |
| 60 | + |
| 61 | + interface AclEntryBuilder { |
| 62 | + @CanIgnoreReturnValue |
| 63 | + AclEntryBuilder grant(@Nonnull Collection<? extends Privilege> privileges); |
| 64 | + |
| 65 | + @CanIgnoreReturnValue |
| 66 | + AclEntryBuilder grant(@Nonnull Privilege... privileges); |
| 67 | + |
| 68 | + @CanIgnoreReturnValue |
| 69 | + AclEntryBuilder grant(@Nonnull Privilege privilege); |
| 70 | + |
| 71 | + @CanIgnoreReturnValue |
| 72 | + AclEntryBuilder grant(@Nonnull PrivilegeSet privileges); |
| 73 | + |
| 74 | + @CanIgnoreReturnValue |
| 75 | + AclEntryBuilder revoke(@Nonnull Collection<? extends Privilege> privileges); |
| 76 | + |
| 77 | + @CanIgnoreReturnValue |
| 78 | + AclEntryBuilder revoke(@Nonnull Privilege... privileges); |
| 79 | + |
| 80 | + @CanIgnoreReturnValue |
| 81 | + AclEntryBuilder revoke(@Nonnull Privilege privilege); |
| 82 | + |
| 83 | + @CanIgnoreReturnValue |
| 84 | + AclEntryBuilder revoke(@Nonnull PrivilegeSet privileges); |
| 85 | + |
| 86 | + @CanIgnoreReturnValue |
| 87 | + AclEntryBuilder restrict(@Nonnull Collection<? extends Privilege> privileges); |
| 88 | + |
| 89 | + @CanIgnoreReturnValue |
| 90 | + AclEntryBuilder restrict(@Nonnull Privilege... privileges); |
| 91 | + |
| 92 | + @CanIgnoreReturnValue |
| 93 | + AclEntryBuilder restrict(@Nonnull Privilege privilege); |
| 94 | + |
| 95 | + @CanIgnoreReturnValue |
| 96 | + AclEntryBuilder restrict(@Nonnull PrivilegeSet privileges); |
| 97 | + |
| 98 | + @CanIgnoreReturnValue |
| 99 | + AclEntryBuilder unrestrict(@Nonnull Collection<? extends Privilege> privileges); |
| 100 | + |
| 101 | + @CanIgnoreReturnValue |
| 102 | + AclEntryBuilder unrestrict(@Nonnull Privilege... privileges); |
| 103 | + |
| 104 | + @CanIgnoreReturnValue |
| 105 | + AclEntryBuilder unrestrict(@Nonnull Privilege privilege); |
| 106 | + |
| 107 | + @CanIgnoreReturnValue |
| 108 | + AclEntryBuilder unrestrict(@Nonnull PrivilegeSet privileges); |
| 109 | + |
| 110 | + AclEntry build(); |
| 111 | + } |
| 112 | +} |
0 commit comments