mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-10 15:32:05 -03:30
[FGAP] Create scopes upon creation of the admin permission client
Closes #35810 Signed-off-by: vramik <vramik@redhat.com>
This commit is contained in:
parent
4c263f4897
commit
16a42d5a64
@ -85,7 +85,14 @@ import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.keycloak.authorization.AuthorizationProvider;
|
||||
import org.keycloak.authorization.model.ResourceServer;
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.representations.idm.authorization.AdminPermissionsAuthorizationSchema;
|
||||
import org.keycloak.representations.idm.authorization.AuthorizationSchema;
|
||||
import org.keycloak.representations.idm.authorization.ResourceServerRepresentation;
|
||||
import org.keycloak.representations.idm.authorization.ResourceType;
|
||||
import org.keycloak.representations.idm.authorization.ScopeRepresentation;
|
||||
|
||||
import static org.keycloak.utils.StreamsUtil.closing;
|
||||
|
||||
@ -1192,7 +1199,21 @@ public final class KeycloakModelUtils {
|
||||
public static void setupAdminPermissionsClient(KeycloakSession session, RealmModel realm) {
|
||||
ClientModel client = session.clients().addClient(realm, Constants.ADMIN_PERMISSIONS_CLIENT_ID);
|
||||
realm.setAdminPermissionsClient(client);
|
||||
RepresentationToModel.createResourceServer(client, session, false);
|
||||
|
||||
ResourceServer resourceServer = RepresentationToModel.createResourceServer(client, session, false);
|
||||
ResourceServerRepresentation resourceServerRep = ModelToRepresentation.toRepresentation(resourceServer, client);
|
||||
|
||||
AuthorizationSchema schema = AdminPermissionsAuthorizationSchema.INSTANCE;
|
||||
|
||||
//there is no way how to map scopes to the resourceType, we need to collect all scopes from all resourceTypes
|
||||
Set<ScopeRepresentation> scopes = schema.getResourceTypes().stream()
|
||||
.flatMap((resourceType) -> resourceType.getScopes().stream())
|
||||
.map(scope -> new ScopeRepresentation(scope))
|
||||
.collect(Collectors.toSet());//collecting to set to get rid of duplicities
|
||||
|
||||
resourceServerRep.setScopes(List.copyOf(scopes));
|
||||
|
||||
RepresentationToModel.toModel(resourceServerRep, session.getProvider(AuthorizationProvider.class), client);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,6 +22,8 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
@ -90,6 +92,9 @@ public class AdminPermissionsTest extends AbstractTestRealmKeycloakTest {
|
||||
|
||||
authorizationSettings = testRealm().clients().get(adminPermissionsClient.getId()).authorization().getSettings();
|
||||
assertThat(authorizationSettings.getAuthorizationSchema(), notNullValue());
|
||||
|
||||
List<String> scopeNames = testRealm().clients().get(adminPermissionsClient.getId()).authorization().scopes().scopes().stream().map((rep) -> rep.getName()).collect(Collectors.toList());
|
||||
assertThat(scopeNames, Matchers.hasItem("manage"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user