Search in sources :

Example 1 with DDLClusterStateService

use of io.crate.metadata.cluster.DDLClusterStateService in project crate by crate.

the class AccessControlMayExecuteTest method setUpSQLExecutor.

@Before
public void setUpSQLExecutor() throws Exception {
    validationCallArguments = new ArrayList<>();
    RepositoriesMetadata repositoriesMetadata = new RepositoriesMetadata(singletonList(new RepositoryMetadata("my_repo", "fs", Settings.builder().put("location", "/tmp/my_repo").build())));
    ClusterState clusterState = ClusterState.builder(clusterService.state()).metadata(Metadata.builder(clusterService.state().metadata()).putCustom(RepositoriesMetadata.TYPE, repositoriesMetadata)).build();
    ClusterServiceUtils.setState(clusterService, clusterState);
    user = new User("normal", Set.of(), Set.of(), null) {

        @Override
        public boolean hasPrivilege(Privilege.Type type, Privilege.Clazz clazz, String ident, String defaultSchema) {
            validationCallArguments.add(CollectionUtils.arrayAsArrayList(type, clazz, ident, user.name()));
            return true;
        }
    };
    superUser = new User("crate", EnumSet.of(User.Role.SUPERUSER), Set.of(), null) {

        @Override
        public boolean hasPrivilege(Privilege.Type type, Privilege.Clazz clazz, @Nullable String ident, String defaultSchema) {
            validationCallArguments.add(CollectionUtils.arrayAsArrayList(type, clazz, ident, superUser.name()));
            return true;
        }
    };
    UserLookupService userLookupService = new UserLookupService(clusterService) {

        @Nullable
        @Override
        public User findUser(String userName) {
            if ("crate".equals(userName)) {
                return superUser;
            }
            return super.findUser(userName);
        }
    };
    userManager = new UserManagerService(null, null, null, null, mock(SysTableRegistry.class), clusterService, userLookupService, new DDLClusterStateService());
    e = SQLExecutor.builder(clusterService).addBlobTable("create blob table blobs").enableDefaultTables().setUser(superUser).addView(new RelationName("doc", "v1"), "select * from users").setUserManager(userManager).build();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) UserLookupService(io.crate.user.UserLookupService) User(io.crate.user.User) RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) UserManagerService(io.crate.user.UserManagerService) DDLClusterStateService(io.crate.metadata.cluster.DDLClusterStateService) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) RelationName(io.crate.metadata.RelationName) Privilege(io.crate.user.Privilege) Before(org.junit.Before)

Aggregations

RelationName (io.crate.metadata.RelationName)1 DDLClusterStateService (io.crate.metadata.cluster.DDLClusterStateService)1 Privilege (io.crate.user.Privilege)1 User (io.crate.user.User)1 UserLookupService (io.crate.user.UserLookupService)1 UserManagerService (io.crate.user.UserManagerService)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 RepositoriesMetadata (org.elasticsearch.cluster.metadata.RepositoriesMetadata)1 RepositoryMetadata (org.elasticsearch.cluster.metadata.RepositoryMetadata)1 Before (org.junit.Before)1