-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new Query Example permission policy (#1633)
Co-authored-by: vburlachenko <[email protected]> Co-authored-by: ayemets-corcentric <[email protected]>
- Loading branch information
1 parent
516a9d1
commit 57a4ec3
Showing
28 changed files
with
513 additions
and
167 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
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
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
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
7 changes: 7 additions & 0 deletions
7
.../java/org/opendatadiscovery/oddplatform/dto/policy/QueryExamplePolicyResolverContext.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,7 @@ | ||
package org.opendatadiscovery.oddplatform.dto.policy; | ||
|
||
import org.opendatadiscovery.oddplatform.dto.QueryExampleDto; | ||
import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerPojo; | ||
|
||
public record QueryExamplePolicyResolverContext(QueryExampleDto detailsDto, OwnerPojo currentOwner) { | ||
} |
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
60 changes: 60 additions & 0 deletions
60
...tadiscovery/oddplatform/service/permission/extractor/QueryExamplePermissionExtractor.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,60 @@ | ||
package org.opendatadiscovery.oddplatform.service.permission.extractor; | ||
|
||
import java.util.Collection; | ||
import org.opendatadiscovery.oddplatform.auth.AuthIdentityProvider; | ||
import org.opendatadiscovery.oddplatform.dto.QueryExampleDto; | ||
import org.opendatadiscovery.oddplatform.dto.policy.PolicyDto; | ||
import org.opendatadiscovery.oddplatform.dto.policy.PolicyPermissionDto; | ||
import org.opendatadiscovery.oddplatform.dto.policy.PolicyTypeDto; | ||
import org.opendatadiscovery.oddplatform.dto.policy.QueryExamplePolicyResolverContext; | ||
import org.opendatadiscovery.oddplatform.mapper.PolicyMapper; | ||
import org.opendatadiscovery.oddplatform.model.tables.pojos.OwnerPojo; | ||
import org.opendatadiscovery.oddplatform.repository.reactive.ReactiveDataEntityQueryExampleRelationRepository; | ||
import org.opendatadiscovery.oddplatform.service.PolicyService; | ||
import org.opendatadiscovery.oddplatform.service.policy.PolicyPermissionExtractor; | ||
import org.springframework.stereotype.Component; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
public class QueryExamplePermissionExtractor | ||
extends AbstractContextualPermissionExtractor<QueryExamplePolicyResolverContext> { | ||
|
||
private final AuthIdentityProvider authIdentityProvider; | ||
private final ReactiveDataEntityQueryExampleRelationRepository repository; | ||
private final PolicyPermissionExtractor permissionExtractor; | ||
|
||
public QueryExamplePermissionExtractor(final PolicyService policyService, | ||
final PolicyMapper policyMapper, | ||
final AuthIdentityProvider authIdentityProvider, | ||
final ReactiveDataEntityQueryExampleRelationRepository repository, | ||
final PolicyPermissionExtractor permissionExtractor) { | ||
super(policyService, policyMapper); | ||
this.authIdentityProvider = authIdentityProvider; | ||
this.repository = repository; | ||
this.permissionExtractor = permissionExtractor; | ||
} | ||
|
||
@Override | ||
protected Mono<QueryExamplePolicyResolverContext> getContext(final long resourceId) { | ||
final Mono<QueryExampleDto> dtoMono = repository.getQueryExampleDatasetRelations(resourceId); | ||
|
||
final Mono<OwnerPojo> ownerPojoMono = authIdentityProvider.fetchAssociatedOwner(); | ||
return ownerPojoMono | ||
.zipWith(dtoMono) | ||
.map(tuple | ||
-> new QueryExamplePolicyResolverContext(tuple.getT2(), tuple.getT1())) | ||
.switchIfEmpty(Mono.defer(() | ||
-> dtoMono.map(dto -> new QueryExamplePolicyResolverContext(dto, null)))); | ||
} | ||
|
||
@Override | ||
protected Collection<PolicyPermissionDto> getPermissions(final PolicyDto policyDto, | ||
final QueryExamplePolicyResolverContext context) { | ||
return permissionExtractor.extractQueryExamplePermissions(policyDto.getStatements(), context); | ||
} | ||
|
||
@Override | ||
public PolicyTypeDto getResourceType() { | ||
return PolicyTypeDto.QUERY_EXAMPLE; | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...scovery/oddplatform/service/policy/comparer/queryexample/QueryExampleComparorFactory.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,15 @@ | ||
package org.opendatadiscovery.oddplatform.service.policy.comparer.queryexample; | ||
|
||
import java.util.function.Function; | ||
import org.opendatadiscovery.oddplatform.dto.QueryExampleDto; | ||
import org.opendatadiscovery.oddplatform.dto.policy.QueryExamplePolicyResolverContext; | ||
import org.opendatadiscovery.oddplatform.service.policy.comparer.Comparer; | ||
|
||
public final class QueryExampleComparorFactory { | ||
private QueryExampleComparorFactory() {} | ||
|
||
public static Comparer<QueryExamplePolicyResolverContext> | ||
queryExample(final Function<QueryExampleDto, String> fieldExtractor) { | ||
return new QueryExampleFieldComparer(fieldExtractor); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...discovery/oddplatform/service/policy/comparer/queryexample/QueryExampleFieldComparer.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,16 @@ | ||
package org.opendatadiscovery.oddplatform.service.policy.comparer.queryexample; | ||
|
||
import java.util.function.Function; | ||
import org.opendatadiscovery.oddplatform.dto.QueryExampleDto; | ||
import org.opendatadiscovery.oddplatform.dto.policy.QueryExamplePolicyResolverContext; | ||
import org.opendatadiscovery.oddplatform.service.policy.comparer.SimpleFieldComparer; | ||
|
||
public class QueryExampleFieldComparer extends SimpleFieldComparer<QueryExamplePolicyResolverContext> { | ||
public QueryExampleFieldComparer(final Function<QueryExampleDto, String> fieldExtractor) { | ||
super(context -> fieldExtractor.apply(getQueryExample(context))); | ||
} | ||
|
||
private static QueryExampleDto getQueryExample(final QueryExamplePolicyResolverContext context) { | ||
return context.detailsDto(); | ||
} | ||
} |
Oops, something went wrong.