use of io.crate.user.metadata.UsersPrivilegesMetadata in project crate by crate.
the class TransportPrivilegesAction method applyPrivileges.
@VisibleForTesting
static long applyPrivileges(Metadata.Builder mdBuilder, PrivilegesRequest request) {
// create a new instance of the metadata, to guarantee the cluster changed action.
UsersPrivilegesMetadata newMetadata = UsersPrivilegesMetadata.copyOf((UsersPrivilegesMetadata) mdBuilder.getCustom(UsersPrivilegesMetadata.TYPE));
long affectedRows = newMetadata.applyPrivileges(request.userNames(), request.privileges());
mdBuilder.putCustom(UsersPrivilegesMetadata.TYPE, newMetadata);
return affectedRows;
}
use of io.crate.user.metadata.UsersPrivilegesMetadata in project crate by crate.
the class UserLookupService method clusterChanged.
@Override
public void clusterChanged(ClusterChangedEvent event) {
Metadata prevMetadata = event.previousState().metadata();
Metadata newMetadata = event.state().metadata();
UsersMetadata prevUsers = prevMetadata.custom(UsersMetadata.TYPE);
UsersMetadata newUsers = newMetadata.custom(UsersMetadata.TYPE);
UsersPrivilegesMetadata prevUsersPrivileges = prevMetadata.custom(UsersPrivilegesMetadata.TYPE);
UsersPrivilegesMetadata newUsersPrivileges = newMetadata.custom(UsersPrivilegesMetadata.TYPE);
if (prevUsers != newUsers || prevUsersPrivileges != newUsersPrivileges) {
users = getUsers(newUsers, newUsersPrivileges);
}
}
use of io.crate.user.metadata.UsersPrivilegesMetadata in project crate by crate.
the class UserManagerDDLModifier method dropPrivileges.
private static boolean dropPrivileges(Metadata.Builder mdBuilder, RelationName relationName) {
// create a new instance of the metadata, to guarantee the cluster changed action.
UsersPrivilegesMetadata newMetadata = UsersPrivilegesMetadata.copyOf((UsersPrivilegesMetadata) mdBuilder.getCustom(UsersPrivilegesMetadata.TYPE));
long affectedRows = newMetadata.dropTableOrViewPrivileges(relationName.fqn());
mdBuilder.putCustom(UsersPrivilegesMetadata.TYPE, newMetadata);
return affectedRows > 0L;
}
use of io.crate.user.metadata.UsersPrivilegesMetadata in project crate by crate.
the class UserManagerDDLModifier method onSwapRelations.
@Override
public ClusterState onSwapRelations(ClusterState currentState, RelationName source, RelationName target) {
Metadata currentMetadata = currentState.metadata();
UsersPrivilegesMetadata userPrivileges = currentMetadata.custom(UsersPrivilegesMetadata.TYPE);
if (userPrivileges == null) {
return currentState;
}
UsersPrivilegesMetadata updatedPrivileges = UsersPrivilegesMetadata.swapPrivileges(userPrivileges, source, target);
return ClusterState.builder(currentState).metadata(Metadata.builder(currentMetadata).putCustom(UsersPrivilegesMetadata.TYPE, updatedPrivileges).build()).build();
}
use of io.crate.user.metadata.UsersPrivilegesMetadata in project crate by crate.
the class UserLookupServiceTest method testNewUser.
@Test
public void testNewUser() {
Set<User> users = UserLookupService.getUsers(new UsersMetadata(UserDefinitions.SINGLE_USER_ONLY), new UsersPrivilegesMetadata());
assertThat(users, containsInAnyOrder(User.of("Arthur"), CRATE_USER));
}
Aggregations