-
Notifications
You must be signed in to change notification settings - Fork 352
Refactor Authenticator and PolarisPrincipal #2307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 0 additions & 63 deletions
63
polaris-core/src/main/java/org/apache/polaris/core/auth/AuthenticatedPolarisPrincipal.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisPrincipal.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * 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 java.security.Principal; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import org.apache.polaris.core.entity.PrincipalEntity; | ||
| import org.apache.polaris.immutables.PolarisImmutable; | ||
|
|
||
| /** Represents a {@link Principal} in the Polaris system. */ | ||
| @PolarisImmutable | ||
| public interface PolarisPrincipal extends Principal { | ||
|
|
||
| /** | ||
| * Creates a new instance of {@link PolarisPrincipal} from the given {@link PrincipalEntity} and | ||
| * roles. | ||
| * | ||
| * <p>The created principal will have the same ID and name as the {@link PrincipalEntity}, and its | ||
| * properties will be derived from the internal properties of the entity. | ||
| * | ||
| * @param principalEntity the principal entity representing the user or service | ||
| * @param roles the set of roles associated with the principal | ||
| */ | ||
| static PolarisPrincipal of(PrincipalEntity principalEntity, Set<String> roles) { | ||
| return of( | ||
| principalEntity.getId(), | ||
| principalEntity.getName(), | ||
| principalEntity.getInternalPropertiesAsMap(), | ||
| roles); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new instance of {@link PolarisPrincipal} with the specified ID, name, roles, and | ||
| * properties. | ||
| * | ||
| * @param id the unique identifier of the principal | ||
| * @param name the name of the principal | ||
| * @param properties additional properties associated with the principal | ||
| * @param roles the set of roles associated with the principal | ||
| */ | ||
| static PolarisPrincipal of( | ||
| long id, String name, Map<String, String> properties, Set<String> roles) { | ||
| return ImmutablePolarisPrincipal.builder() | ||
| .id(id) | ||
| .name(name) | ||
| .properties(properties) | ||
| .roles(roles) | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the unique identifier of the principal. | ||
| * | ||
| * <p>This identifier is used to uniquely identify the principal within a Polaris realm. | ||
| */ | ||
| long getId(); | ||
|
|
||
| /** | ||
| * Returns the set of activated principal role names. Activated role names are the roles that were | ||
| * explicitly requested by the client when authenticating, through JWT claims or other means. It | ||
| * may be a subset of the roles that the principal has in the system. | ||
| */ | ||
| Set<String> getRoles(); | ||
|
|
||
| /** | ||
| * Returns the properties of this principal. | ||
| * | ||
| * <p>Properties are key-value pairs that provide additional information about the principal, such | ||
| * as permissions, preferences, or other metadata. | ||
| */ | ||
| Map<String, String> getProperties(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We differentiate between persisted (
PersistedPolarisPrincipal) and non-persistent ones. I wonder whether this getter should be present at all here. It could at least return anOptionalLongto make it clear that only persisted principals have an ID. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that the Resolver requires the principal to have an id, since it resolves principals by id. Thus it seemed to me that it was legit to require from all principals to have at least a numeric identifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a follow-up task, we could attempt to modify the Resolver so that it makes principal lookups by name. WDYT @collado-mike ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be able to move past the Resolver needing to resolve the principal at all. This was largely present because the Resolver fetched the accessible PrincipalRoles based on grant records, but we have moved that requirement out so that we can rely on roles defined in the token instead. I think it's reasonable to change the Resolver to skip resolving the principal and roles entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's an interesting improvement for sure! I will try to do that in a follow-up task 👍