diff --git a/integration/admin-client-jee/src/main/java/org/keycloak/admin/client/resource/OrganizationMembersResource.java b/integration/admin-client-jee/src/main/java/org/keycloak/admin/client/resource/OrganizationMembersResource.java index ec5199ee77..a3b6ab6fb7 100644 --- a/integration/admin-client-jee/src/main/java/org/keycloak/admin/client/resource/OrganizationMembersResource.java +++ b/integration/admin-client-jee/src/main/java/org/keycloak/admin/client/resource/OrganizationMembersResource.java @@ -73,4 +73,9 @@ public interface OrganizationMembersResource { @Path("{id}") OrganizationMemberResource member(@PathParam("id") String id); + + @POST + @Path("invite") + @Consumes(MediaType.APPLICATION_JSON) + Response inviteMember(UserRepresentation rep); } diff --git a/services/src/main/java/org/keycloak/authentication/actiontoken/inviteorg/InviteOrgActionToken.java b/services/src/main/java/org/keycloak/authentication/actiontoken/inviteorg/InviteOrgActionToken.java index b09daa8aca..d93163672d 100644 --- a/services/src/main/java/org/keycloak/authentication/actiontoken/inviteorg/InviteOrgActionToken.java +++ b/services/src/main/java/org/keycloak/authentication/actiontoken/inviteorg/InviteOrgActionToken.java @@ -27,7 +27,7 @@ import org.keycloak.models.Constants; */ public class InviteOrgActionToken extends DefaultActionToken { - public static final String TOKEN_TYPE = "invite-org"; + public static final String TOKEN_TYPE = "ORGIVT"; private static final String JSON_FIELD_REDIRECT_URI = "reduri"; private static final String JSON_ORG_ID = "org_id"; diff --git a/services/src/main/java/org/keycloak/authentication/actiontoken/inviteorg/InviteOrgActionTokenHandler.java b/services/src/main/java/org/keycloak/authentication/actiontoken/inviteorg/InviteOrgActionTokenHandler.java index b07b63afe8..50ebc2276e 100644 --- a/services/src/main/java/org/keycloak/authentication/actiontoken/inviteorg/InviteOrgActionTokenHandler.java +++ b/services/src/main/java/org/keycloak/authentication/actiontoken/inviteorg/InviteOrgActionTokenHandler.java @@ -133,9 +133,4 @@ public class InviteOrgActionTokenHandler extends AbstractActionTokenHandler smtpConfig = testRealm.getSmtpServer(); + super.configureTestRealm(testRealm); + testRealm.setSmtpServer(smtpConfig); + } + + @Test + public void testInviteExistingUser() throws IOException { + UserRepresentation user = UserBuilder.create() + .username("invited") + .email("invited@myemail.com") + .password("password") + .enabled(true) + .build(); + try (Response response = testRealm().users().create(user)) { + user.setId(ApiUtil.getCreatedId(response)); + } + + OrganizationResource organization = testRealm().organizations().get(createOrganization().getId()); + + organization.members().inviteMember(user).close(); + + MimeMessage message = greenMail.getLastReceivedMessage(); + Assert.assertNotNull(message); + String link = MailUtils.getPasswordResetEmailLink(message); + driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.DAYS); + driver.navigate().to(link.trim()); + Assert.assertFalse(organization.members().getAll().stream().anyMatch(actual -> user.getId().equals(actual.getId()))); + infoPage.clickToContinue(); + assertThat(infoPage.getInfo(), containsString("Your account has been updated.")); + Assert.assertTrue(organization.members().getAll().stream().anyMatch(actual -> user.getId().equals(actual.getId()))); + } +} \ No newline at end of file diff --git a/themes/src/main/resources/theme/base/email/text/org-invite.ftl b/themes/src/main/resources/theme/base/email/text/org-invite.ftl new file mode 100644 index 0000000000..afc32a7230 --- /dev/null +++ b/themes/src/main/resources/theme/base/email/text/org-invite.ftl @@ -0,0 +1,2 @@ +<#ftl output_format="plainText"> +${kcSanitize(msg("orgInviteBodyHtml", link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration)))}