use of org.keycloak.representations.account.UserProfileAttributeMetadata in project keycloak by keycloak.
the class AccountRestServiceWithUserProfileTest method testGetUserProfileMetadata_EditUsernameAllowed.
@Test
@Override
public void testGetUserProfileMetadata_EditUsernameAllowed() throws IOException {
setUserProfileConfiguration(UP_CONFIG_FOR_METADATA);
UserRepresentation user = getUser();
assertNotNull(user.getUserProfileMetadata());
assertUserProfileAttributeMetadata(user, "username", "${username}", true, false);
assertUserProfileAttributeMetadata(user, "email", "${email}", true, false);
UserProfileAttributeMetadata uam = assertUserProfileAttributeMetadata(user, "firstName", "${profile.firstName}", false, false);
assertNull(uam.getAnnotations());
Map<String, Object> vc = assertValidatorExists(uam, "length");
assertEquals(255, vc.get("max"));
uam = assertUserProfileAttributeMetadata(user, "lastName", "Last name", true, false);
assertNotNull(uam.getAnnotations());
assertEquals(3, uam.getAnnotations().size());
assertAnnotationValue(uam, "formHintKey", "userEmailFormFieldHint");
assertAnnotationValue(uam, "anotherKey", 10);
assertUserProfileAttributeMetadata(user, "attr_with_scope_selector", "attr_with_scope_selector", false, false);
assertUserProfileAttributeMetadata(user, "attr_required", "attr_required", true, false);
assertUserProfileAttributeMetadata(user, "attr_required_by_role", "attr_required_by_role", true, false);
assertUserProfileAttributeMetadata(user, "attr_required_by_scope", "attr_required_by_scope", false, false);
assertUserProfileAttributeMetadata(user, "attr_not_required_due_to_role", "attr_not_required_due_to_role", false, false);
assertUserProfileAttributeMetadata(user, "attr_readonly", "attr_readonly", false, true);
assertNull(getUserProfileAttributeMetadata(user, "attr_no_permission"));
}
use of org.keycloak.representations.account.UserProfileAttributeMetadata in project keycloak by keycloak.
the class AccountRestServiceWithUserProfileTest method testGetUserProfileMetadata_EditUsernameDisallowed.
@Test
@Override
public void testGetUserProfileMetadata_EditUsernameDisallowed() throws IOException {
try {
RealmRepresentation realmRep = adminClient.realm("test").toRepresentation();
realmRep.setEditUsernameAllowed(false);
adminClient.realm("test").update(realmRep);
setUserProfileConfiguration(UP_CONFIG_FOR_METADATA);
UserRepresentation user = getUser();
assertNotNull(user.getUserProfileMetadata());
assertUserProfileAttributeMetadata(user, "username", "${username}", true, true);
assertUserProfileAttributeMetadata(user, "email", "${email}", true, false);
UserProfileAttributeMetadata uam = assertUserProfileAttributeMetadata(user, "firstName", "${profile.firstName}", false, false);
assertNull(uam.getAnnotations());
Map<String, Object> vc = assertValidatorExists(uam, "length");
assertEquals(255, vc.get("max"));
uam = assertUserProfileAttributeMetadata(user, "lastName", "Last name", true, false);
assertNotNull(uam.getAnnotations());
assertEquals(3, uam.getAnnotations().size());
assertAnnotationValue(uam, "formHintKey", "userEmailFormFieldHint");
assertAnnotationValue(uam, "anotherKey", 10);
assertUserProfileAttributeMetadata(user, "attr_with_scope_selector", "attr_with_scope_selector", false, false);
assertUserProfileAttributeMetadata(user, "attr_required", "attr_required", true, false);
assertUserProfileAttributeMetadata(user, "attr_required_by_role", "attr_required_by_role", true, false);
assertUserProfileAttributeMetadata(user, "attr_required_by_scope", "attr_required_by_scope", false, false);
assertUserProfileAttributeMetadata(user, "attr_not_required_due_to_role", "attr_not_required_due_to_role", false, false);
assertUserProfileAttributeMetadata(user, "attr_readonly", "attr_readonly", false, true);
assertNull(getUserProfileAttributeMetadata(user, "attr_no_permission"));
} finally {
RealmRepresentation realmRep = testRealm().toRepresentation();
realmRep.setEditUsernameAllowed(true);
testRealm().update(realmRep);
}
}
use of org.keycloak.representations.account.UserProfileAttributeMetadata in project keycloak by keycloak.
the class AccountRestServiceTest method assertUserProfileAttributeMetadata.
protected UserProfileAttributeMetadata assertUserProfileAttributeMetadata(UserRepresentation user, String attName, String displayName, boolean required, boolean readOnly) {
UserProfileAttributeMetadata uam = getUserProfileAttributeMetadata(user, attName);
assertNotNull(uam);
assertEquals("Unexpected display name for attribute " + uam.getName(), displayName, uam.getDisplayName());
assertEquals("Unexpected required flag for attribute " + uam.getName(), required, uam.isRequired());
assertEquals("Unexpected readonly flag for attribute " + uam.getName(), readOnly, uam.isReadOnly());
return uam;
}
use of org.keycloak.representations.account.UserProfileAttributeMetadata in project keycloak by keycloak.
the class AccountRestServiceTest method testGetUserProfileMetadata_EditUsernameDisallowed.
@Test
public void testGetUserProfileMetadata_EditUsernameDisallowed() throws IOException {
try {
RealmRepresentation realmRep = adminClient.realm("test").toRepresentation();
realmRep.setEditUsernameAllowed(false);
adminClient.realm("test").update(realmRep);
UserRepresentation user = getUser();
assertNotNull(user.getUserProfileMetadata());
UserProfileAttributeMetadata upm = assertUserProfileAttributeMetadata(user, "username", "${username}", true, true);
// makes sure internal validators are not exposed
Assert.assertEquals(0, upm.getValidators().size());
upm = assertUserProfileAttributeMetadata(user, "email", "${email}", true, false);
Assert.assertEquals(1, upm.getValidators().size());
Assert.assertTrue(upm.getValidators().containsKey(EmailValidator.ID));
assertUserProfileAttributeMetadata(user, "firstName", "${firstName}", true, false);
assertUserProfileAttributeMetadata(user, "lastName", "${lastName}", true, false);
} finally {
RealmRepresentation realmRep = testRealm().toRepresentation();
realmRep.setEditUsernameAllowed(true);
testRealm().update(realmRep);
}
}
Aggregations