APISonar


org.elasticsearch.xpack.core.security.authc.support.mapper.TemplateRoleName.Format.JSON

> org > elasticsearch > xpack > core > security > authc > support > mapper > TemplateRoleName > Format > JSON
org APIs elasticsearch APIs xpack APIs core APIs security APIs authc APIs support APIs mapper APIs TemplateRoleName APIs Format APIs JSON APIs

Example 1
public void testParseRoles() throws Exception {
        final TemplateRoleName role1 = parse("{ \"template\": { \"source\": \"_user_{{username}}\" } }");
        assertThat(role1, Matchers.instanceOf(TemplateRoleName.class));
        assertThat(role1.getTemplate().utf8ToString(), equalTo("{\"source\":\"_user_{{username}}\"}"));
        assertThat(role1.getFormat(), equalTo(Format.STRING));

        final TemplateRoleName role2 = parse(
            "{ \"template\": \"{\\\"source\\\":\\\"{{#tojson}}groups{{/tojson}}\\\"}\", \"format\":\"json\" }");
        assertThat(role2, Matchers.instanceOf(TemplateRoleName.class));
        assertThat(role2.getTemplate().utf8ToString(),
            equalTo("{\"source\":\"{{#tojson}}groups{{/tojson}}\"}"));
        assertThat(role2.getFormat(), equalTo(Format.JSON));
    }