Check if formData is empty before putting login hint (#20733)

closes keycloak#20732
This commit is contained in:
Bruno Sanches 2023-06-06 18:14:08 -03:00 committed by GitHub
parent 0c2ac4f776
commit ecf4dbfb18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -586,11 +586,19 @@ public class FreeMarkerLoginFormsProvider implements LoginFormsProvider {
public Response createRegistration() { public Response createRegistration() {
String loginHint = authenticationSession.getClientNote(OIDCLoginProtocol.LOGIN_HINT_PARAM); String loginHint = authenticationSession.getClientNote(OIDCLoginProtocol.LOGIN_HINT_PARAM);
if (loginHint != null && !loginHint.isEmpty()) { if (loginHint != null && !loginHint.isEmpty()) {
this.formData = new MultivaluedHashMap<>(); if (this.formData == null) {
this.formData = new MultivaluedHashMap<>();
}
if(this.realm.isRegistrationEmailAsUsername()) { if(this.realm.isRegistrationEmailAsUsername()) {
this.formData.putSingle("email", loginHint); String value = this.formData.getFirst("email");
if (value == null || value.trim().isEmpty()) {
this.formData.putSingle("email", loginHint);
}
} else { } else {
this.formData.putSingle("username", loginHint); String value = this.formData.getFirst("username");
if (value == null || value.trim().isEmpty()) {
this.formData.putSingle("username", loginHint);
}
} }
} }