简体   繁体   中英

Create Admin User using Couchbase Java SDK

I am figuring out the couchbase java SDK 3.3 and how to manage users. Using the User Management documentation , I can run this snippet of code:

# Example Read Only User
User user = new User(testUsername).password(userPassword);
user.roles(new Role("data_reader","*"),new Role("query_select","*"));
cluster.users().upsertUser(user);

My question is it possible to create a user this way with administrator privileges (security, cluster, full, etc.), add the user to an existing group (which looking at lack of a Group field in the User object from the SDK, I don't think so), or are there additional privileges assignable other than Data Reader/Writer and Query Select/Insert/Delete/Manage Index

Yes, you can use the management API to create admin users. You can do this by assigning the various admin roles to the user.

And yes, you can assign users to groups.

To view all available roles:

cluster.users().getRoles().forEach(System.out::println);

Note: Couchbase Server Enterprise Edition provides many more roles than Community Edition.

To create a read-only admin user that's a member of group "existing-group":

cluster.users().upsertUser(
    new User("example-admin")
        .displayName("Example Admin")
        .password("Correct Horse Battery Staple")
        .roles(new Role("ro_admin")) // Read-Only Admin
        .groups("existing-group") // must already exist
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM