wip: compiles and doesn't break startup
This commit is contained in:
parent
86cfd9cf57
commit
cd738a4a6f
6
pom.xml
6
pom.xml
@ -60,6 +60,12 @@
|
||||
<scope>provided</scope>
|
||||
<version>${keycloak.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.auto.service</groupId>
|
||||
<artifactId>auto-service</artifactId>
|
||||
<version>1.0</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -12,10 +12,12 @@ import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.utils.FormMessage;
|
||||
import org.keycloak.provider.ProviderConfigProperty;
|
||||
import org.keycloak.services.messages.Messages;
|
||||
import org.keycloak.services.validation.Validation;
|
||||
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
//
|
||||
@ -26,7 +28,10 @@ import org.keycloak.events.Errors;
|
||||
import org.keycloak.forms.login.LoginFormsProvider;
|
||||
import org.keycloak.models.utils.FormMessage;
|
||||
|
||||
public abstract class RegistrationProfileDomainValidation extends RegistrationUserCreation {
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(FormActionFactory.class)
|
||||
public class RegistrationProfileDomainValidation extends RegistrationUserCreation {
|
||||
protected static final Logger logger = Logger.getLogger(RegistrationProfileDomainValidation.class);
|
||||
|
||||
protected static final String DEFAULT_DOMAIN_LIST = "example.org";
|
||||
@ -108,8 +113,62 @@ public abstract class RegistrationProfileDomainValidation extends RegistrationUs
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String[] getDomainList(AuthenticatorConfigModel mailDomainConfig);
|
||||
public String[] getDomainList(AuthenticatorConfigModel mailDomainConfig) {
|
||||
return mailDomainConfig.getConfig().getOrDefault(domainListConfigName, DEFAULT_DOMAIN_LIST).split(DOMAIN_LIST_SEPARATOR);
|
||||
}
|
||||
|
||||
public boolean isEmailValid(String email, String[] domains) {
|
||||
for (String domain : domains) {
|
||||
if (email.endsWith("@" + domain) || email.equals(domain) || globmatches(email, "*@" + domain)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static final String PROVIDER_ID = "registration-mail-check-action";
|
||||
|
||||
private static final List<ProviderConfigProperty> CONFIG_PROPERTIES = new ArrayList<>();
|
||||
|
||||
public static String domainListConfigName = "validDomains";
|
||||
|
||||
static {
|
||||
ProviderConfigProperty property;
|
||||
property = new ProviderConfigProperty();
|
||||
property.setName(domainListConfigName);
|
||||
property.setLabel("Valid domains for emails");
|
||||
property.setType(ProviderConfigProperty.STRING_TYPE);
|
||||
property.setHelpText("List mail domains authorized to register, separated by '##'");
|
||||
CONFIG_PROPERTIES.add(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayType() {
|
||||
return "Profile Validation with email domain check";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return PROVIDER_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() {
|
||||
return "Adds validation of domain emails for registration";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProviderConfigProperty> getConfigProperties() {
|
||||
return CONFIG_PROPERTIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildPage(FormContext context, LoginFormsProvider form) {
|
||||
List<String> authorizedMailDomains = Arrays.asList(
|
||||
context.getAuthenticatorConfig().getConfig().getOrDefault(domainListConfigName,DEFAULT_DOMAIN_LIST).split(DOMAIN_LIST_SEPARATOR));
|
||||
form.setAttribute("authorizedMailDomains", authorizedMailDomains);
|
||||
}
|
||||
|
||||
public abstract boolean isEmailValid(String email, String[] domains);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
com.thomasdarimont.keycloak.auth.CustomRegistrationUserCreation
|
||||
com.thomasdarimont.keycloak.auth.RegistrationProfileWithDomainBlock
|
||||
com.thomasdarimont.keycloak.auth.RegistrationProfileWithMailDomainCheck
|
||||
com.github.thomasdarimont.keycloak.auth.RegistrationProfileDomainValidation
|
||||
com.github.thomasdarimont.keycloak.auth.RegistrationProfileWithDomainBlock
|
||||
com.github.thomasdarimont.keycloak.auth.RegistrationProfileWithMailDomainCheck
|
||||
|
Loading…
Reference in New Issue
Block a user