Search in sources :

Example 1 with AttributeGroupMetadata

use of org.keycloak.userprofile.AttributeGroupMetadata in project keycloak by keycloak.

the class UserProfileTest method testGetProfileAttributeGroups.

private static void testGetProfileAttributeGroups(KeycloakSession session) {
    RealmModel realm = session.getContext().getRealm();
    UserModel user = session.users().addUser(realm, org.keycloak.models.utils.KeycloakModelUtils.generateId());
    UserProfileProvider provider = getDynamicUserProfileProvider(session);
    String configuration = "{\n" + "  \"attributes\": [\n" + "    {\n" + "      \"name\": \"address\",\n" + "      \"group\": \"companyaddress\"\n" + "    },\n" + "    {\n" + "      \"name\": \"second\",\n" + "      \"group\": \"groupwithanno" + "\"\n" + "    }\n" + "  ],\n" + "  \"groups\": [\n" + "    {\n" + "      \"name\": \"companyaddress\",\n" + "      \"displayHeader\": \"header\",\n" + "      \"displayDescription\": \"description\"\n" + "    },\n" + "    {\n" + "      \"name\": \"groupwithanno\",\n" + "      \"annotations\": {\n" + "        \"anno1\": \"value1\",\n" + "        \"anno2\": \"value2\"\n" + "      }\n" + "    }\n" + "  ]\n" + "}\n";
    provider.setConfiguration(configuration);
    UserProfile profile = provider.create(UserProfileContext.ACCOUNT, user);
    Attributes attributes = profile.getAttributes();
    assertThat(attributes.nameSet(), containsInAnyOrder(UserModel.USERNAME, UserModel.EMAIL, UserModel.FIRST_NAME, UserModel.LAST_NAME, "address", "second"));
    AttributeGroupMetadata companyAddressGroup = attributes.getMetadata("address").getAttributeGroupMetadata();
    assertEquals("companyaddress", companyAddressGroup.getName());
    assertEquals("header", companyAddressGroup.getDisplayHeader());
    assertEquals("description", companyAddressGroup.getDisplayDescription());
    assertNull(companyAddressGroup.getAnnotations());
    AttributeGroupMetadata groupwithannoGroup = attributes.getMetadata("second").getAttributeGroupMetadata();
    assertEquals("groupwithanno", groupwithannoGroup.getName());
    assertNull(groupwithannoGroup.getDisplayHeader());
    assertNull(groupwithannoGroup.getDisplayDescription());
    Map<String, Object> annotations = groupwithannoGroup.getAnnotations();
    assertEquals(2, annotations.size());
    assertEquals("value1", annotations.get("anno1"));
    assertEquals("value2", annotations.get("anno2"));
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserModel(org.keycloak.models.UserModel) AttributeGroupMetadata(org.keycloak.userprofile.AttributeGroupMetadata) UserProfile(org.keycloak.userprofile.UserProfile) DeclarativeUserProfileProvider(org.keycloak.userprofile.DeclarativeUserProfileProvider) UserProfileProvider(org.keycloak.userprofile.UserProfileProvider) Attributes(org.keycloak.userprofile.Attributes)

Aggregations

RealmModel (org.keycloak.models.RealmModel)1 UserModel (org.keycloak.models.UserModel)1 AttributeGroupMetadata (org.keycloak.userprofile.AttributeGroupMetadata)1 Attributes (org.keycloak.userprofile.Attributes)1 DeclarativeUserProfileProvider (org.keycloak.userprofile.DeclarativeUserProfileProvider)1 UserProfile (org.keycloak.userprofile.UserProfile)1 UserProfileProvider (org.keycloak.userprofile.UserProfileProvider)1