keydepot:在java客户机中创建具有属性的角色

wvyml7n5  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(278)

我正在尝试用keydove admin client(11.0.0)和一些自定义属性在keydove(11.0.0)中创建一个客户端角色。角色被创建,但是属性字段只是被key斗篷忽略。有人知道怎么让它工作吗?
这是我使用的简化代码:

public void createRole(String name) {
    RoleRepresentation roleRepresentation = new RoleRepresentation();
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put("att1", Collections.singletonList("attribute1"));
    attributes.put("att2", Collections.singletonList("attribute2"));
    roleRepresentation.setAttributes(attributes);
    roleRepresentation.setClientRole(true);
    roleRepresentation.setName(name);
    realm.clients().get(client.getId()).roles().create(roleRepresentation);
}

我将非常感谢在这个问题上的任何帮助。谢谢!

yduiuuwa

yduiuuwa1#

对于每个与同一问题作斗争的人:我自己刚刚找到了一个解决办法。您需要用相同的对象更新新创建的角色,它就可以工作了。

public void createRole(String name) {
        RoleRepresentation roleRepresentation = new RoleRepresentation();
        Map<String, List<String>> attributes = new HashMap<>();
        attributes.put("att1", Collections.singletonList("attribute1"));
        attributes.put("att2", Collections.singletonList("attribute2"));
        roleRepresentation.setAttributes(attributes);
        roleRepresentation.setClientRole(true);
        roleRepresentation.setName(name);
        realm.clients().get(client.getId()).roles().create(roleRepresentation);

        // Now update the new role immediately
        RoleResource roleResource = realm.clients().get(client.getId()).roles().get(name);
        roleResource.update(roleRepresentation);
    }

相关问题