diff --git a/Dockerfile b/Dockerfile index 82ffceb..d3c4545 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,5 +3,3 @@ FROM jboss/keycloak:15.1.1 ENV DB_VENDOR H2 ADD target/keycloak-verify-email-by-code-*-SNAPSHOT.jar /opt/jboss/keycloak/standalone/deployments/ - - diff --git a/docker-compose.yml b/docker-compose.yml index ee1769c..1a3fd57 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,14 @@ version: '3.8' services: keycloak: - image: quay.io/keycloak/keycloak:23.0 + image: quay.io/keycloak/keycloak:24.0 command: [ 'start-dev', '--import-realm', '--debug', '--spi-required-action-VERIFY_EMAIL_CODE-code-length=5' ] volumes: - ./realm-config/local:/opt/keycloak/data/import - - ./target/keycloak-verify-email-by-code-23.0.0-SNAPSHOT.jar:/opt/keycloak/providers/keycloak-verify-email-by-code.jar + - ./target/keycloak-verify-email-by-code-24.0.0-SNAPSHOT.jar:/opt/keycloak/providers/keycloak-verify-email-by-code.jar environment: - KC_DB=dev-file - KEYCLOAK_ADMIN=admin diff --git a/pom.xml b/pom.xml index 41ed7f1..7509675 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ fr.redfroggy.keycloak keycloak-verify-email-by-code - 23.0.0-SNAPSHOT + 24.0.0-SNAPSHOT ${project.groupId}:${project.artifactId} Action to verify email by code for Keycloak @@ -53,11 +53,11 @@ 3.3.0 3.5.0 - 23.0.4 + 24.0.0 3.5.3.Final - 5.10.0 - 5.3.1 + 5.10.2 + 5.11.0 3.24.2 @@ -172,6 +172,12 @@ ${mockito.version} test + + net.bytebuddy + byte-buddy + 1.14.13 + test + org.assertj assertj-core diff --git a/src/main/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCode.java b/src/main/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCode.java index d367991..5c4cb24 100644 --- a/src/main/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCode.java +++ b/src/main/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCode.java @@ -71,7 +71,7 @@ private static void createFormChallenge(RequiredActionContext context, FormMessa loginFormsProvider = loginFormsProvider.addError(new FormMessage(EMAIL_CODE, INVALID_CODE)); } Response challenge = loginFormsProvider - .setAttribute("user", new ProfileBean(context.getUser())) + .setAttribute("user", new ProfileBean(context.getUser(), context.getSession())) .createForm(LOGIN_VERIFY_EMAIL_CODE_TEMPLATE); context.challenge(challenge); } @@ -182,7 +182,6 @@ private void sendVerifyEmailAndCreateForm(RequiredActionContext context) throws @Override public String getDisplayText() { - logger.info("Retrieved display text for VerifyEmailByCode"); return "Verify Email by code"; } diff --git a/src/test/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCodeTest.java b/src/test/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCodeTest.java index 3f8c515..a59d352 100644 --- a/src/test/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCodeTest.java +++ b/src/test/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCodeTest.java @@ -21,6 +21,7 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; import org.keycloak.sessions.AuthenticationSessionModel; +import org.keycloak.userprofile.UserProfileProvider; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -38,6 +39,8 @@ class VerifyEmailByCodeTest { @Mock private UserModel user; @Mock + private UserProfileProvider provider; + @Mock private KeycloakSession session; @Mock private EventBuilder event; @@ -167,7 +170,7 @@ public void shouldGenerateCodeWithSixDigits() { private void mockChallenge() { when(requiredActionContext.getUser()).thenReturn(user); when(user.getEmail()).thenReturn("keycloak@redfroggy.fr"); - + when(session.getProvider(UserProfileProvider.class)).thenReturn(provider); when(requiredActionContext.getSession()).thenReturn(session); when(requiredActionContext.getEvent()).thenReturn(event); @@ -235,6 +238,8 @@ public void shouldChallengeOnProcessActionWhenCodeIsNull() throws EmailException public void shouldChallengeWithErrorOnProcessActionWhenCodeIsNotValid() { initAction(); when(requiredActionContext.getUser()).thenReturn(user); + when(session.getProvider(UserProfileProvider.class)).thenReturn(provider); + when(requiredActionContext.getSession()).thenReturn(session); when(user.getEmail()).thenReturn("keycloak@redfroggy.fr"); when(requiredActionContext.getEvent()).thenReturn(event); @@ -243,6 +248,7 @@ public void shouldChallengeWithErrorOnProcessActionWhenCodeIsNotValid() { when(event.detail(Details.EMAIL, user.getEmail())).thenReturn(event); when(requiredActionContext.getAuthenticationSession()).thenReturn(authSession); + when(authSession.getAuthNote(VerifyEmailByCode.VERIFY_EMAIL_CODE)).thenReturn("code is valid"); HttpRequest request = mock(HttpRequest.class);