feat: adding support for Keycloak 22
This commit is contained in:
parent
81514b06a3
commit
df60257603
8
pom.xml
8
pom.xml
@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.micedre.keycloak</groupId>
|
||||
<artifactId>keycloak-mail-whitelisting</artifactId>
|
||||
<version>1.7-SNAPSHOT</version>
|
||||
<version>1.8-SNAPSHOT</version>
|
||||
|
||||
<name>Keycloak mail whitelisting extension</name>
|
||||
<description>A keycloak extension to block non authorized domain to register</description>
|
||||
@ -30,9 +30,9 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<keycloak.version>19.0.0</keycloak.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<keycloak.version>22.0.0</keycloak.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.micedre.keycloak.registration;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.authentication.FormAction;
|
||||
import org.keycloak.authentication.ValidationContext;
|
||||
import org.keycloak.authentication.forms.RegistrationPage;
|
||||
@ -11,18 +12,18 @@ import org.keycloak.models.utils.FormMessage;
|
||||
import org.keycloak.services.messages.Messages;
|
||||
import org.keycloak.services.validation.Validation;
|
||||
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RegistrationProfileDomainValidation extends RegistrationProfile implements FormAction {
|
||||
protected static final Logger logger = Logger.getLogger(RegistrationProfileDomainValidation.class);
|
||||
|
||||
protected static String domainListConfigName;
|
||||
protected static final String DEFAULT_DOMAIN_LIST = "example.org";
|
||||
protected static final String DOMAIN_LIST_SEPARATOR = "##";
|
||||
|
||||
@Override
|
||||
public boolean isConfigurable() {
|
||||
public boolean isConfigurable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -76,7 +77,8 @@ public abstract class RegistrationProfileDomainValidation extends RegistrationPr
|
||||
return;
|
||||
}
|
||||
|
||||
String[] domainList = mailDomainConfig.getConfig().getOrDefault(domainListConfigName, DEFAULT_DOMAIN_LIST).split(DOMAIN_LIST_SEPARATOR);
|
||||
String[] domainList = getDomainList(mailDomainConfig);
|
||||
|
||||
boolean emailDomainValid = isEmailValid(email, domainList);
|
||||
|
||||
if (!emailDomainValid) {
|
||||
@ -91,6 +93,8 @@ public abstract class RegistrationProfileDomainValidation extends RegistrationPr
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String[] getDomainList(AuthenticatorConfigModel mailDomainConfig);
|
||||
|
||||
public abstract boolean isEmailValid(String email, String[] domains);
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,23 @@
|
||||
package net.micedre.keycloak.registration;
|
||||
|
||||
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;
|
||||
|
||||
import org.keycloak.authentication.FormContext;
|
||||
import org.keycloak.forms.login.LoginFormsProvider;
|
||||
import org.keycloak.provider.ProviderConfigProperty;
|
||||
|
||||
public class RegistrationProfileWithDomainBlock extends RegistrationProfileDomainValidation {
|
||||
|
||||
public static final String PROVIDER_ID = "registration-domain-block-action";
|
||||
|
||||
private static final List<ProviderConfigProperty> CONFIG_PROPERTIES = new ArrayList<>();
|
||||
|
||||
static {
|
||||
domainListConfigName = "invalidDomains";
|
||||
public static String domainListConfigName = "invalidDomains";
|
||||
|
||||
static {
|
||||
ProviderConfigProperty property;
|
||||
property = new ProviderConfigProperty();
|
||||
property.setName(domainListConfigName);
|
||||
@ -26,7 +28,7 @@ public class RegistrationProfileWithDomainBlock extends RegistrationProfileDomai
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayType() {
|
||||
public String getDisplayType() {
|
||||
return "Profile Validation with domain block";
|
||||
}
|
||||
|
||||
@ -52,6 +54,11 @@ public class RegistrationProfileWithDomainBlock extends RegistrationProfileDomai
|
||||
form.setAttribute("unauthorizedMailDomains", unauthorizedMailDomains);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getDomainList(AuthenticatorConfigModel mailDomainConfig) {
|
||||
return mailDomainConfig.getConfig().getOrDefault(domainListConfigName, DEFAULT_DOMAIN_LIST).split(DOMAIN_LIST_SEPARATOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmailValid(String email, String[] domains) {
|
||||
for (String domain : domains) {
|
||||
|
@ -3,6 +3,7 @@ package net.micedre.keycloak.registration;
|
||||
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;
|
||||
@ -14,9 +15,9 @@ public class RegistrationProfileWithMailDomainCheck extends RegistrationProfileD
|
||||
|
||||
private static final List<ProviderConfigProperty> CONFIG_PROPERTIES = new ArrayList<>();
|
||||
|
||||
static {
|
||||
domainListConfigName = "validDomains";
|
||||
public static String domainListConfigName = "validDomains";
|
||||
|
||||
static {
|
||||
ProviderConfigProperty property;
|
||||
property = new ProviderConfigProperty();
|
||||
property.setName(domainListConfigName);
|
||||
@ -53,6 +54,11 @@ public class RegistrationProfileWithMailDomainCheck extends RegistrationProfileD
|
||||
form.setAttribute("authorizedMailDomains", authorizedMailDomains);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getDomainList(AuthenticatorConfigModel mailDomainConfig) {
|
||||
return mailDomainConfig.getConfig().getOrDefault(domainListConfigName, DEFAULT_DOMAIN_LIST).split(DOMAIN_LIST_SEPARATOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmailValid(String email, String[] domains) {
|
||||
for (String domain : domains) {
|
||||
|
Loading…
Reference in New Issue
Block a user