Skip to content

Commit

Permalink
breaking: Update Keycloak to version 24
Browse files Browse the repository at this point in the history
  • Loading branch information
anarsultanov committed Mar 15, 2024
1 parent 7eed2c7 commit 08de6e6
Show file tree
Hide file tree
Showing 12 changed files with 616 additions and 272 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ the created users will be tenantless and asked to create a new tenant.
To address this issue, this extension introduces the concept of `tenant-specific IDPs` and an additional authenticator that facilitates the creation of required memberships.

To configure an IDP as tenant-specific, tenants' IDs should be added to the `multi-tenancy.tenants` configuration attribute of the IDP as a **comma-separated list**.
This can be achieved using the standard [Keycloak REST API](https://www.keycloak.org/docs-api/23.0.7/rest-api/index.html#_identity_providers).
This can be achieved using the standard [Keycloak REST API](https://www.keycloak.org/docs-api/24.0.1/rest-api/index.html#_identity_providers).

> **_Note_**
> - _With tenant-specific IDP configuration, the IDP limits access to only the tenants listed in the configuration.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</licenses>

<properties>
<keycloak.version>23.0.7</keycloak.version>
<keycloak.version>24.0.1</keycloak.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
import org.keycloak.representations.AccessToken;
import org.keycloak.services.cors.Cors;
import org.keycloak.services.managers.AppAuthManager;
import org.keycloak.services.managers.AppAuthManager.BearerTokenAuthenticator;
import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.services.managers.AuthenticationManager.AuthResult;
import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.resources.Cors;
import org.keycloak.services.resources.admin.AdminAuth;
import org.keycloak.services.resources.admin.AdminEventBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
import org.keycloak.http.HttpRequest;
import org.keycloak.services.resources.Cors;
import org.keycloak.services.cors.Cors;

public class CorsResource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void user_shouldBePromptedToCreateTenant_whenTheyDontHaveInvitations() {

nextPage = ((CreateTenantPage) nextPage).fillTenantData(TenantData.random()).submit();
assertThat(nextPage).isInstanceOf(AccountPage.class);
assertThat(((AccountPage) nextPage).getLoggedInUser()).contains(user.getUserData().getFullName());
assertThat(((AccountPage) nextPage).getLoggedInUser()).contains(user.getUserData().getEmail());
}

@Test
Expand All @@ -54,7 +54,7 @@ void user_shouldBePromptedToCreateTenant_whenTheyDeclineInvitation() {

nextPage = ((CreateTenantPage) nextPage).fillTenantData(TenantData.random()).submit();
assertThat(nextPage).isInstanceOf(AccountPage.class);
assertThat(((AccountPage) nextPage).getLoggedInUser()).contains(user.getUserData().getFullName());
assertThat(((AccountPage) nextPage).getLoggedInUser()).contains(user.getUserData().getEmail());
}

@Test
Expand All @@ -70,7 +70,7 @@ void user_shouldNotBePromptedToCreateTenant_whenTheyAcceptInvitation() {
nextPage = ((ReviewInvitationsPage) nextPage).accept();

assertThat(nextPage).isInstanceOf(AccountPage.class);
assertThat(((AccountPage) nextPage).getLoggedInUser()).contains(user.getUserData().getFullName());
assertThat(((AccountPage) nextPage).getLoggedInUser()).hasValue(user.getUserData().getEmail());
}

@Test
Expand All @@ -91,7 +91,7 @@ void user_shouldBePromptedToSelectTenant_whenTheyAcceptMultipleInvitations() {
nextPage = ((SelectTenantPage) nextPage).select(invitationTenant2.getName()).signIn();

assertThat(nextPage).isInstanceOf(AccountPage.class);
assertThat(((AccountPage) nextPage).getLoggedInUser()).contains(user.getUserData().getFullName());
assertThat(((AccountPage) nextPage).getLoggedInUser()).contains(user.getUserData().getEmail());
}

private TenantData createInvitationFor(UserData inviteeData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void shouldRequireToCreateTenant_whenSignInUsingPublicIdpAndNotMemberOfAnyTenant
// then
nextPage = ((CreateTenantPage) nextPage).fillTenantData(TenantData.random()).submit();
assertThat(nextPage).isInstanceOf(AccountPage.class);
assertThat(((AccountPage) nextPage).getLoggedInUser()).contains(idpUser.getUserData().getFullName());
assertThat(((AccountPage) nextPage).getLoggedInUser()).hasValue(idpUser.getUserData().getEmail());

// cleanup
deleteIdentityProvider(idpAlias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BaseIntegrationTest {
private static final Integer MAILHOG_HTTP_PORT = 8025;

private static final Network network = Network.newNetwork();
private static final KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:23.0.7")
private static final KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:24.0.1")
.withRealmImportFiles("/realm-export.json", "/idp-realm-export.json")
.withProviderClassesFrom("target/classes")
.withNetwork(network)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public KeycloakUser createVerifiedUser(UserData userData, Map<String, List<Strin
var userRepresentation = new UserRepresentation();
userRepresentation.setFirstName(userData.getFirstName());
userRepresentation.setLastName(userData.getLastName());
userRepresentation.setUsername(userData.getEmail());
userRepresentation.setEmail(userData.getEmail());
userRepresentation.setEmailVerified(true);
userRepresentation.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public SignInPage signIn() {
}

public Optional<String> getLoggedInUser() {
var locator = page.locator("#landingLoggedInUser");
return Optional.ofNullable(locator.textContent());
var locator = page.getByTestId("username");
return Optional.ofNullable(locator.inputValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static AbstractPage resolve(Page page) {
return new ReviewInvitationsPage(page);
} else if (page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Select tenant")).isVisible()) {
return new SelectTenantPage(page);
} else if (page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Welcome to Keycloak account management")).isVisible()) {
} else if (page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Personal info")).isVisible()) {
return new AccountPage(page);
} else if (page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("We are sorry...")).isVisible()) {
return new ErrorPage(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class UserData {
public static UserData random() {
var firstName = faker.name().firstName();
var lastName = faker.name().lastName();
var email = faker.internet().emailAddress(firstName + "." + lastName);
var email = faker.internet().emailAddress(firstName + "." + lastName.replaceAll("[^A-Za-z]", "")).toLowerCase();
var password = faker.internet().password();
return new UserData(firstName, lastName, email, password);
}
Expand Down
Loading

0 comments on commit 08de6e6

Please sign in to comment.