Search in sources :

Example 1 with OAuthClientRepresentation

use of org.keycloak.representations.idm.OAuthClientRepresentation in project keycloak by keycloak.

the class RepresentationToModel method convertDeprecatedApplications.

private static void convertDeprecatedApplications(KeycloakSession session, RealmRepresentation realm) {
    if (realm.getApplications() != null || realm.getOauthClients() != null) {
        if (realm.getClients() == null) {
            realm.setClients(new LinkedList<ClientRepresentation>());
        }
        List<ApplicationRepresentation> clients = new LinkedList<>();
        if (realm.getApplications() != null) {
            clients.addAll(realm.getApplications());
        }
        if (realm.getOauthClients() != null) {
            clients.addAll(realm.getOauthClients());
        }
        for (ApplicationRepresentation app : clients) {
            app.setClientId(app.getName());
            app.setName(null);
            if (app instanceof OAuthClientRepresentation) {
                app.setConsentRequired(true);
                app.setFullScopeAllowed(false);
            }
            if (app.getProtocolMappers() == null && app.getClaims() != null) {
                long mask = getClaimsMask(app.getClaims());
                List<ProtocolMapperRepresentation> convertedProtocolMappers = session.getProvider(MigrationProvider.class).getMappersForClaimMask(mask);
                app.setProtocolMappers(convertedProtocolMappers);
                app.setClaims(null);
            }
            realm.getClients().add(app);
        }
    }
    if (realm.getApplicationScopeMappings() != null && realm.getClientScopeMappings() == null) {
        realm.setClientScopeMappings(realm.getApplicationScopeMappings());
    }
    if (realm.getRoles() != null && realm.getRoles().getApplication() != null && realm.getRoles().getClient() == null) {
        realm.getRoles().setClient(realm.getRoles().getApplication());
    }
    if (realm.getUsers() != null) {
        for (UserRepresentation user : realm.getUsers()) {
            if (user.getApplicationRoles() != null && user.getClientRoles() == null) {
                user.setClientRoles(user.getApplicationRoles());
            }
        }
    }
    if (realm.getRoles() != null && realm.getRoles().getRealm() != null) {
        for (RoleRepresentation role : realm.getRoles().getRealm()) {
            if (role.getComposites() != null && role.getComposites().getApplication() != null && role.getComposites().getClient() == null) {
                role.getComposites().setClient(role.getComposites().getApplication());
            }
        }
    }
    if (realm.getRoles() != null && realm.getRoles().getClient() != null) {
        for (Map.Entry<String, List<RoleRepresentation>> clientRoles : realm.getRoles().getClient().entrySet()) {
            for (RoleRepresentation role : clientRoles.getValue()) {
                if (role.getComposites() != null && role.getComposites().getApplication() != null && role.getComposites().getClient() == null) {
                    role.getComposites().setClient(role.getComposites().getApplication());
                }
            }
        }
    }
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) OAuthClientRepresentation(org.keycloak.representations.idm.OAuthClientRepresentation) ArtifactBindingUtils.computeArtifactBindingIdentifierString(org.keycloak.protocol.saml.util.ArtifactBindingUtils.computeArtifactBindingIdentifierString) LinkedList(java.util.LinkedList) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) OAuthClientRepresentation(org.keycloak.representations.idm.OAuthClientRepresentation) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) ApplicationRepresentation(org.keycloak.representations.idm.ApplicationRepresentation) MigrationProvider(org.keycloak.migration.MigrationProvider) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) HashMap(java.util.HashMap) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)1 MigrationProvider (org.keycloak.migration.MigrationProvider)1 ArtifactBindingUtils.computeArtifactBindingIdentifierString (org.keycloak.protocol.saml.util.ArtifactBindingUtils.computeArtifactBindingIdentifierString)1 ApplicationRepresentation (org.keycloak.representations.idm.ApplicationRepresentation)1 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)1 OAuthClientRepresentation (org.keycloak.representations.idm.OAuthClientRepresentation)1 ProtocolMapperRepresentation (org.keycloak.representations.idm.ProtocolMapperRepresentation)1 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)1 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)1