Skip to content

Commit

Permalink
Added check for keycloak26 client attributes. Rename exported realm f…
Browse files Browse the repository at this point in the history
…older.
  • Loading branch information
ma1uta committed Nov 5, 2024
1 parent 0031aa1 commit a403ca0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1608,13 +1608,14 @@ void shouldAddAuthzPoliciesForRealmManagement() throws IOException {
assertThat(client.getAuthorizationServicesEnabled(), is(true));
assertThat(client.isFrontchannelLogout(), is(false));
assertThat(client.getProtocol(), is("openid-connect"));
assertThat(client.getAttributes(), anEmptyMap());
assertThat(client.getAuthenticationFlowBindingOverrides(), anEmptyMap());
assertThat(client.isFullScopeAllowed(), is(false));
assertThat(client.getNodeReRegistrationTimeout(), is(0));
assertThat(client.getDefaultClientScopes(), containsInAnyOrder("web-origins", "profile", "roles", "email"));
assertThat(client.getOptionalClientScopes(), containsInAnyOrder("address", "phone", "offline_access", "microprofile-jwt"));

checkClientAttributes(client);

String[] clientsIds = new String[]{clientFineGrainedPermissionId};
String[] scopeNames = new String[]{
"manage",
Expand Down Expand Up @@ -1750,13 +1751,14 @@ void shouldUpdateAuthzPoliciesForRealmManagement() throws IOException {
assertThat(client.getAuthorizationServicesEnabled(), is(true));
assertThat(client.isFrontchannelLogout(), is(false));
assertThat(client.getProtocol(), is("openid-connect"));
assertThat(client.getAttributes(), anEmptyMap());
assertThat(client.getAuthenticationFlowBindingOverrides(), anEmptyMap());
assertThat(client.isFullScopeAllowed(), is(false));
assertThat(client.getNodeReRegistrationTimeout(), is(0));
assertThat(client.getDefaultClientScopes(), containsInAnyOrder("web-origins", "profile", "roles", "email"));
assertThat(client.getOptionalClientScopes(), containsInAnyOrder("address", "phone", "offline_access", "microprofile-jwt"));

checkClientAttributes(client);

String[] clientsIds = new String[]{clientFineGrainedPermissionId, clientZFineGrainedPermissionWithoutIdId};
String[] scopeNames = new String[]{
"manage",
Expand Down Expand Up @@ -1876,13 +1878,14 @@ void shouldRemoveClientAndAuthzPoliciesForRealmManagement() throws IOException {
assertThat(client.getAuthorizationServicesEnabled(), is(true));
assertThat(client.isFrontchannelLogout(), is(false));
assertThat(client.getProtocol(), is("openid-connect"));
assertThat(client.getAttributes(), anEmptyMap());
assertThat(client.getAuthenticationFlowBindingOverrides(), anEmptyMap());
assertThat(client.isFullScopeAllowed(), is(false));
assertThat(client.getNodeReRegistrationTimeout(), is(0));
assertThat(client.getDefaultClientScopes(), containsInAnyOrder("web-origins", "profile", "roles", "email"));
assertThat(client.getOptionalClientScopes(), containsInAnyOrder("address", "phone", "offline_access", "microprofile-jwt"));

checkClientAttributes(client);

String[] clientsIds = new String[]{clientZFineGrainedPermissionWithoutIdId};
String[] scopeNames = new String[]{
"manage",
Expand Down Expand Up @@ -1985,13 +1988,14 @@ void shouldRemoveAuthzPoliciesForRealmManagement() throws IOException {
assertThat(client.getAuthorizationServicesEnabled(), is(true));
assertThat(client.isFrontchannelLogout(), is(false));
assertThat(client.getProtocol(), is("openid-connect"));
assertThat(client.getAttributes(), anEmptyMap());
assertThat(client.getAuthenticationFlowBindingOverrides(), anEmptyMap());
assertThat(client.isFullScopeAllowed(), is(false));
assertThat(client.getNodeReRegistrationTimeout(), is(0));
assertThat(client.getDefaultClientScopes(), containsInAnyOrder("web-origins", "profile", "roles", "email"));
assertThat(client.getOptionalClientScopes(), containsInAnyOrder("address", "phone", "offline_access", "microprofile-jwt"));

checkClientAttributes(client);

ResourceServerRepresentation authorizationSettings = client.getAuthorizationSettings();
assertThat(authorizationSettings.isAllowRemoteResourceManagement(), is(false));
assertThat(authorizationSettings.getPolicyEnforcementMode(), is(PolicyEnforcementMode.ENFORCING));
Expand Down Expand Up @@ -2679,4 +2683,13 @@ private void createRemoteManagedClientResource(String realm, String clientId, St

authzClient.protection().resource().create(resource);
}

private void checkClientAttributes(ClientRepresentation client) {
if (VersionUtil.lt(KEYCLOAK_VERSION, "26")) {
assertThat(client.getAttributes(), anEmptyMap());
} else {
// https://github.com/keycloak/keycloak/pull/30433 Added attribute to recognize realm client
assertThat(client.getAttributes(), hasEntry("realm_client", "true"));
}
}
}

0 comments on commit a403ca0

Please sign in to comment.