Search in sources :

Example 6 with UsersPrivilegesMetadata

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;
}
Also used : UsersPrivilegesMetadata(io.crate.user.metadata.UsersPrivilegesMetadata) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 7 with UsersPrivilegesMetadata

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);
    }
}
Also used : UsersPrivilegesMetadata(io.crate.user.metadata.UsersPrivilegesMetadata) UsersMetadata(io.crate.user.metadata.UsersMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) UsersMetadata(io.crate.user.metadata.UsersMetadata) UsersPrivilegesMetadata(io.crate.user.metadata.UsersPrivilegesMetadata)

Example 8 with UsersPrivilegesMetadata

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;
}
Also used : UsersPrivilegesMetadata(io.crate.user.metadata.UsersPrivilegesMetadata)

Example 9 with UsersPrivilegesMetadata

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();
}
Also used : UsersPrivilegesMetadata(io.crate.user.metadata.UsersPrivilegesMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) UsersPrivilegesMetadata(io.crate.user.metadata.UsersPrivilegesMetadata)

Example 10 with UsersPrivilegesMetadata

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));
}
Also used : UsersPrivilegesMetadata(io.crate.user.metadata.UsersPrivilegesMetadata) UsersMetadata(io.crate.user.metadata.UsersMetadata) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Aggregations

UsersPrivilegesMetadata (io.crate.user.metadata.UsersPrivilegesMetadata)10 UsersMetadata (io.crate.user.metadata.UsersMetadata)6 Metadata (org.elasticsearch.cluster.metadata.Metadata)4 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)3 Test (org.junit.Test)3 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1