in polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BaseResolverTest.java [464:523]
private Resolver allocateResolver(
@Nullable InMemoryEntityCache cache,
Set<String> principalRolesScope,
@Nullable String referenceCatalogName) {
// create a new cache if needs be
if (cache == null) {
this.cache = new InMemoryEntityCache(metaStoreManager());
}
boolean allRoles = principalRolesScope == null;
Optional<List<PrincipalRoleEntity>> roleEntities =
Optional.ofNullable(principalRolesScope)
.map(
scopes ->
scopes.stream()
.map(
role ->
metaStoreManager()
.readEntityByName(
callCtx(),
null,
PolarisEntityType.PRINCIPAL_ROLE,
PolarisEntitySubType.NULL_SUBTYPE,
role))
.filter(EntityResult::isSuccess)
.map(EntityResult::getEntity)
.map(PrincipalRoleEntity::of)
.collect(Collectors.toList()));
AuthenticatedPolarisPrincipal authenticatedPrincipal =
new AuthenticatedPolarisPrincipal(
PrincipalEntity.of(P1), Optional.ofNullable(principalRolesScope).orElse(Set.of()));
return new Resolver(
callCtx(),
metaStoreManager(),
new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return authenticatedPrincipal;
}
@Override
public boolean isUserInRole(String role) {
return roleEntities
.map(l -> l.stream().map(PrincipalRoleEntity::getName).anyMatch(role::equals))
.orElse(allRoles);
}
@Override
public boolean isSecure() {
return false;
}
@Override
public String getAuthenticationScheme() {
return "";
}
},
this.shouldUseCache ? this.cache : null,
referenceCatalogName);
}