我已为角色设置了属性。转到角色->编辑角色->转到“属性”选项卡,然后添加键和值。 然后,使用以下代码尝试检索属性。我设法检索所有角色(role.getName()具有值),但是属性为null。我忘了给钥匙斗篷设置一些东西吗?
Keycloak keycloak = KeycloakBuilder.builder()
.serverUrl("http://host.docker.internal:8080/auth")
.realm("test")
.username("admin")
.password("admin")
.clientId("testId")
.authorization(kp.getKeycloakSecurityContext().getTokenString())
.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(20).build())
.build();
RealmResource realm = keycloak.realm("test");
realm.roles().list().forEach(role->System.out.println(role.getName() + " " +role.getAttributes()));
答案 0 :(得分:0)
您需要使用import os
import csv
import xml.etree.ElementTree as ET
xml_path = r'D:\scripts\xml'
csv_path = r'D:\scripts\csv'
# DEFINED METHOD
def xml_to_csv(xml_file):
csv_file = os.path.join(csv_path, f'Output_{xml_file[:-4]}.csv')
tree = ET.parse(os.path.join(xml_path, xml_file))
with open(csv_file, 'w', newline='', errors='ignore') as data_out:
csvwriter = csv.writer(data_out)
col_names = ['Fichier', 'No. de document', 'Titre']
csvwriter.writerow(col_names)
root = tree.getroot()
for elem in root.iter(tag='Document'):
row = [elem.find('FileType').text,
elem.find('DocumentNumber').text,
elem.find('Title').text]
csvwriter.writerow(row)
# FILE ITERATION
for f in os.listdir(xml_path):
xml_to_csv(f)
来获取所有数据。
realm.roles().list(false)