-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(authorization): Adding AuthorizerContext + ResourceSpecResolver …
…to context (#4982)
- Loading branch information
1 parent
b77f381
commit ce061e3
Showing
20 changed files
with
147 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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
17 changes: 17 additions & 0 deletions
17
metadata-service/auth-api/src/main/java/com/datahub/authorization/AuthorizerContext.java
This file contains 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,17 @@ | ||
package com.datahub.authorization; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
|
||
/** | ||
* Context provided to an Authorizer on initialization. | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
public class AuthorizerContext { | ||
/** | ||
* A utility for resolving a {@link ResourceSpec} to resolved resource field values. | ||
*/ | ||
private ResourceSpecResolver resourceSpecResolver; | ||
} |
File renamed without changes.
66 changes: 66 additions & 0 deletions
66
metadata-service/auth-api/src/main/java/com/datahub/authorization/ResolvedResourceSpec.java
This file contains 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,66 @@ | ||
package com.datahub.authorization; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import javax.annotation.Nullable; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
|
||
/** | ||
* Wrapper around authorization request with field resolvers for lazily fetching the field values for each field type | ||
*/ | ||
@RequiredArgsConstructor | ||
public class ResolvedResourceSpec { | ||
@Getter | ||
private final ResourceSpec spec; | ||
private final Map<ResourceFieldType, FieldResolver> fieldResolvers; | ||
|
||
public Set<String> getFieldValues(ResourceFieldType resourceFieldType) { | ||
if (!fieldResolvers.containsKey(resourceFieldType)) { | ||
return Collections.emptySet(); | ||
} | ||
return fieldResolvers.get(resourceFieldType).getFieldValuesFuture().join().getValues(); | ||
} | ||
|
||
/** | ||
* Fetch the entity-registry type for a resource. ('dataset', 'dashboard', 'chart'). | ||
* @return the entity type. | ||
*/ | ||
public String getType() { | ||
if (!fieldResolvers.containsKey(ResourceFieldType.RESOURCE_TYPE)) { | ||
throw new UnsupportedOperationException("Failed to resolve resource type! No field resolver for RESOURCE_TYPE provided."); | ||
} | ||
Set<String> resourceTypes = fieldResolvers.get(ResourceFieldType.RESOURCE_TYPE).getFieldValuesFuture().join().getValues(); | ||
assert resourceTypes.size() == 1; // There should always be a single resource type. | ||
return resourceTypes.stream().findFirst().get(); | ||
} | ||
|
||
/** | ||
* Fetch the owners for a resource. | ||
* @return a set of owner urns, or empty set if none exist. | ||
*/ | ||
public Set<String> getOwners() { | ||
if (!fieldResolvers.containsKey(ResourceFieldType.OWNER)) { | ||
return Collections.emptySet(); | ||
} | ||
return fieldResolvers.get(ResourceFieldType.OWNER).getFieldValuesFuture().join().getValues(); | ||
} | ||
|
||
/** | ||
* Fetch the domain for a Resolved Resource Spec | ||
* @return a Domain or null if one does not exist. | ||
*/ | ||
@Nullable | ||
public String getDomain() { | ||
if (!fieldResolvers.containsKey(ResourceFieldType.DOMAIN)) { | ||
return null; | ||
} | ||
Set<String> domains = fieldResolvers.get(ResourceFieldType.DOMAIN).getFieldValuesFuture().join().getValues(); | ||
if (domains.size() > 0) { | ||
return domains.stream().findFirst().get(); | ||
} | ||
return null; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ldresolverprovider/ResourceFieldType.java → ...ahub/authorization/ResourceFieldType.java
This file contains 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
11 changes: 11 additions & 0 deletions
11
metadata-service/auth-api/src/main/java/com/datahub/authorization/ResourceSpecResolver.java
This file contains 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,11 @@ | ||
package com.datahub.authorization; | ||
|
||
/** | ||
* A Resource Spec Resolver is responsible for resolving a {@link ResourceSpec} to a {@link ResolvedResourceSpec}. | ||
*/ | ||
public interface ResourceSpecResolver { | ||
/** | ||
Resolve a {@link ResourceSpec} to a resolved resource spec. | ||
**/ | ||
ResolvedResourceSpec resolve(ResourceSpec resourceSpec); | ||
} |
This file contains 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 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 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
1 change: 0 additions & 1 deletion
1
metadata-service/auth-impl/src/main/java/com/datahub/authorization/FilterUtils.java
This file contains 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
1 change: 0 additions & 1 deletion
1
metadata-service/auth-impl/src/main/java/com/datahub/authorization/PolicyEngine.java
This file contains 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
33 changes: 0 additions & 33 deletions
33
metadata-service/auth-impl/src/main/java/com/datahub/authorization/ResolvedResourceSpec.java
This file was deleted.
Oops, something went wrong.
This file contains 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
1 change: 1 addition & 0 deletions
1
...java/com/datahub/authorization/fieldresolverprovider/EntityTypeFieldResolverProvider.java
This file contains 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
1 change: 1 addition & 0 deletions
1
.../java/com/datahub/authorization/fieldresolverprovider/EntityUrnFieldResolverProvider.java
This file contains 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 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
1 change: 1 addition & 0 deletions
1
...n/java/com/datahub/authorization/fieldresolverprovider/ResourceFieldResolverProvider.java
This file contains 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 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
1 change: 0 additions & 1 deletion
1
metadata-service/auth-impl/src/test/java/com/datahub/authorization/PolicyEngineTest.java
This file contains 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.