diff --git a/src/main/java/net/micedre/keycloak/registration/RegistrationProfileDomainValidation.java b/src/main/java/com/github/thomasdarimont/keycloak/auth/CustomRegistrationUserCreation.java similarity index 83% rename from src/main/java/net/micedre/keycloak/registration/RegistrationProfileDomainValidation.java rename to src/main/java/com/github/thomasdarimont/keycloak/auth/CustomRegistrationUserCreation.java index 165133c..57887c4 100644 --- a/src/main/java/net/micedre/keycloak/registration/RegistrationProfileDomainValidation.java +++ b/src/main/java/com/github/thomasdarimont/keycloak/auth/CustomRegistrationUserCreation.java @@ -1,5 +1,5 @@ -package net.micedre.keycloak.registration; - +package com.github.thomasdarimont.keycloak.auth; +// import org.jboss.logging.Logger; import org.keycloak.authentication.FormAction; import org.keycloak.authentication.ValidationContext; @@ -10,16 +10,25 @@ import org.keycloak.events.Errors; import org.keycloak.models.AuthenticatorConfigModel; import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; +import org.keycloak.models.UserModel; import org.keycloak.models.utils.FormMessage; import org.keycloak.services.messages.Messages; import org.keycloak.services.validation.Validation; -import org.keycloak.storage.adapter.AbstractUserAdapter; import jakarta.ws.rs.core.MultivaluedMap; import java.util.ArrayList; import java.util.List; +// +import com.google.auto.service.AutoService; +import org.keycloak.authentication.FormActionFactory; +import org.keycloak.authentication.FormContext; +import org.keycloak.authentication.forms.RegistrationUserCreation; +import org.keycloak.events.Errors; +import org.keycloak.forms.login.LoginFormsProvider; +import org.keycloak.models.utils.FormMessage; -public abstract class RegistrationProfileDomainValidation extends RegistrationProfile implements FormAction { +@AutoService(FormActionFactory.class) +public class CustomRegistrationUserCreation extends RegistrationUserCreation { protected static final Logger logger = Logger.getLogger(RegistrationProfileDomainValidation.class); protected static final String DEFAULT_DOMAIN_LIST = "example.org"; @@ -85,15 +94,13 @@ public abstract class RegistrationProfileDomainValidation extends RegistrationPr boolean emailDomainValid = isEmailValid(email, domainList); if (!emailDomainValid) { - // add user to a "waiting" group - // show a message saying you need to be approved by admin + super.success(context); KeycloakSession session = context.getSession(); RealmModel realm = context.getRealm(); - AbstractUserAdapter user = new AbstractUserAdapter(); + UserModel user = context.getUser(); user.addRequiredAction("USER_MUST_BE_APPROVED"); - setRequiredActions(context.getSession(), context.getRealm(), user); + setRequiredActions(session, realm, user); - context.success(); } if (errors.size() > 0) { context.error(eventError); diff --git a/src/main/java/net/micedre/keycloak/registration/RegistrationProfileWithDomainBlock.java b/src/main/java/com/github/thomasdarimont/keycloak/auth/RegistrationProfileWithDomainBlock.java similarity index 97% rename from src/main/java/net/micedre/keycloak/registration/RegistrationProfileWithDomainBlock.java rename to src/main/java/com/github/thomasdarimont/keycloak/auth/RegistrationProfileWithDomainBlock.java index 4298b0f..b1bdba6 100644 --- a/src/main/java/net/micedre/keycloak/registration/RegistrationProfileWithDomainBlock.java +++ b/src/main/java/com/github/thomasdarimont/keycloak/auth/RegistrationProfileWithDomainBlock.java @@ -1,4 +1,4 @@ -package net.micedre.keycloak.registration; +package com.github.thomasdarimont.keycloak.auth; import org.keycloak.authentication.FormContext; import org.keycloak.forms.login.LoginFormsProvider; diff --git a/src/main/java/net/micedre/keycloak/registration/RegistrationProfileWithMailDomainCheck.java b/src/main/java/com/github/thomasdarimont/keycloak/auth/RegistrationProfileWithMailDomainCheck.java similarity index 81% rename from src/main/java/net/micedre/keycloak/registration/RegistrationProfileWithMailDomainCheck.java rename to src/main/java/com/github/thomasdarimont/keycloak/auth/RegistrationProfileWithMailDomainCheck.java index 3437e7e..b5cfa3f 100644 --- a/src/main/java/net/micedre/keycloak/registration/RegistrationProfileWithMailDomainCheck.java +++ b/src/main/java/com/github/thomasdarimont/keycloak/auth/RegistrationProfileWithMailDomainCheck.java @@ -1,4 +1,17 @@ -package net.micedre.keycloak.registration; +package com.github.thomasdarimont.keycloak.auth; + +import org.keycloak.authentication.FormContext; +import org.keycloak.forms.login.LoginFormsProvider; +import org.keycloak.provider.ProviderConfigProperty; +import org.keycloak.models.AuthenticatorConfigModel; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class RegistrationProfileWithMailDomainCheck extends RegistrationProfileDomainValidation { + + public static final String PROVIDER_ID = "registration-mail-check-action"; import org.keycloak.authentication.FormContext; import org.keycloak.forms.login.LoginFormsProvider; @@ -69,4 +82,4 @@ public class RegistrationProfileWithMailDomainCheck extends RegistrationProfileD return false; } -} \ No newline at end of file +}