How to Build a Role with Java API for indices privileges

Hi,

I'm trying tp create an Indices Role using the Java API. Such as below:

Role role = Role.builder()
			    .name("testPutRole")
			    .indicesPrivileges(???)
			    .build();

The example in the doco shows it for a cluster privilege but not for Indices privilege. Is there an example how to create one? I need to add "Granted documents query" as you do in Kibana.
Appreciated.

There's some code here: elasticsearch/SecurityDocumentationIT.java at v7.15.1 · elastic/elasticsearch · GitHub

What specifically are you having an issue with?

Champion! Had a quick look and looks good. Really appreciated.

Hi,
Actually it didn't have what I was looking for. I'm looking to create a Role using .indicesPrivileges(), as per my example ".indicesPrivileges(???)". But there is no examples on how to create one. Hence the question marks in the function indicesPrivileges().

Hi,
I can see the constructor for the IndicesPrivileges class. However Some of the Collections are "String" so no idea what they should be including the String variable called "query". An example or two would be great.

private IndicesPrivileges(Collection<String> indices, Collection<String> privileges, boolean allowRestrictedIndices,
                              @Nullable FieldSecurity fieldSecurity, @Nullable String query) {
        super(indices, privileges, allowRestrictedIndices);
        this.fieldSecurity = fieldSecurity;
        this.query = query;
    }

There's an example query on the main docs page for the Put Role API

Does that help? The string is literally identical to what you would put in the text box in Kibana.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.