This commit is contained in:
knoflook 2023-12-08 15:23:25 +01:00
parent 9db284388b
commit cc4c0867f1
3 changed files with 32 additions and 12 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;