Search in sources :

Example 1 with MigrationProvider

use of org.keycloak.migration.MigrationProvider in project keycloak by keycloak.

the class MigrateTo1_6_0 method migrateImport.

@Override
public void migrateImport(KeycloakSession session, RealmModel realm, RealmRepresentation rep, boolean skipUserDependent) {
    MigrationProvider provider = session.getProvider(MigrationProvider.class);
    ProtocolMapperModel localeMapper = provider.getBuiltinMappers("openid-connect").get("locale");
    if (localeMapper == null) {
        throw new RuntimeException("Can't find default locale mapper");
    }
    migrateRealm(session, localeMapper, realm);
}
Also used : MigrationProvider(org.keycloak.migration.MigrationProvider) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel)

Example 2 with MigrationProvider

use of org.keycloak.migration.MigrationProvider in project keycloak by keycloak.

the class MigrateTo1_6_0 method migrate.

public void migrate(KeycloakSession session) {
    MigrationProvider provider = session.getProvider(MigrationProvider.class);
    ProtocolMapperModel localeMapper = provider.getBuiltinMappers("openid-connect").get("locale");
    if (localeMapper == null) {
        throw new RuntimeException("Can't find default locale mapper");
    }
    session.realms().getRealmsStream().forEach(realm -> migrateRealm(session, localeMapper, realm));
}
Also used : MigrationProvider(org.keycloak.migration.MigrationProvider) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel)

Example 3 with MigrationProvider

use of org.keycloak.migration.MigrationProvider in project keycloak by keycloak.

the class JpaUpdate1_2_0_Beta1 method addDefaultProtocolMappers.

protected void addDefaultProtocolMappers() throws SQLException, DatabaseException {
    String protocolMapperTableName = database.correctObjectName("PROTOCOL_MAPPER", Table.class);
    String protocolMapperCfgTableName = database.correctObjectName("PROTOCOL_MAPPER_CONFIG", Table.class);
    PreparedStatement statement = jdbcConnection.prepareStatement("select ID, NAME, ALLOWED_CLAIMS_MASK from " + getTableName("CLIENT"));
    try {
        ResultSet resultSet = statement.executeQuery();
        try {
            boolean first = true;
            while (resultSet.next()) {
                if (first) {
                    confirmationMessage.append("Migrating claimsMask to protocol mappers for clients: ");
                    first = false;
                }
                Object acmObj = resultSet.getObject("ALLOWED_CLAIMS_MASK");
                long mask = (acmObj != null) ? ((Number) acmObj).longValue() : ClaimMask.ALL;
                MigrationProvider migrationProvider = this.kcSession.getProvider(MigrationProvider.class);
                List<ProtocolMapperRepresentation> protocolMappers = migrationProvider.getMappersForClaimMask(mask);
                for (ProtocolMapperRepresentation protocolMapper : protocolMappers) {
                    String mapperId = KeycloakModelUtils.generateId();
                    InsertStatement insert = new InsertStatement(null, null, protocolMapperTableName).addColumnValue("ID", mapperId).addColumnValue("PROTOCOL", protocolMapper.getProtocol()).addColumnValue("NAME", protocolMapper.getName()).addColumnValue("CONSENT_REQUIRED", false).addColumnValue("PROTOCOL_MAPPER_NAME", protocolMapper.getProtocolMapper()).addColumnValue("CLIENT_ID", resultSet.getString("ID"));
                    statements.add(insert);
                    for (Map.Entry<String, String> cfgEntry : protocolMapper.getConfig().entrySet()) {
                        InsertStatement cfgInsert = new InsertStatement(null, null, protocolMapperCfgTableName).addColumnValue("PROTOCOL_MAPPER_ID", mapperId).addColumnValue("NAME", cfgEntry.getKey()).addColumnValue("VALUE", cfgEntry.getValue());
                        statements.add(cfgInsert);
                    }
                }
                confirmationMessage.append(resultSet.getString("NAME") + ", ");
            }
            // It means that some provider where processed
            if (!first) {
                confirmationMessage.append(". ");
            }
        } finally {
            resultSet.close();
        }
    } finally {
        statement.close();
    }
}
Also used : ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) ResultSet(java.sql.ResultSet) MigrationProvider(org.keycloak.migration.MigrationProvider) PreparedStatement(java.sql.PreparedStatement) Map(java.util.Map) InsertStatement(liquibase.statement.core.InsertStatement)

Example 4 with MigrationProvider

use of org.keycloak.migration.MigrationProvider in project keycloak by keycloak.

the class MigrateTo6_0_0 method migrateRealm.

protected void migrateRealm(KeycloakSession session, RealmModel realm, boolean jsn) {
    MigrationProvider migrationProvider = session.getProvider(MigrationProvider.class);
    // create 'microprofile-jwt' optional client scope in the realm.
    ClientScopeModel mpJWTScope = migrationProvider.addOIDCMicroprofileJWTClientScope(realm);
    LOG.debugf("Added '%s' optional client scope", mpJWTScope.getName());
    // assign 'microprofile-jwt' optional client scope to all the OIDC clients.
    realm.getClientsStream().filter(MigrationUtils::isOIDCNonBearerOnlyClient).forEach(c -> c.addClientScope(mpJWTScope, false));
    LOG.debugf("Client scope '%s' assigned to all the clients", mpJWTScope.getName());
}
Also used : MigrationProvider(org.keycloak.migration.MigrationProvider) ClientScopeModel(org.keycloak.models.ClientScopeModel)

Example 5 with MigrationProvider

use of org.keycloak.migration.MigrationProvider in project keycloak by keycloak.

the class MigrateTo4_6_0 method migrateRealm.

protected void migrateRealm(KeycloakSession session, RealmModel realm, boolean json) {
    MigrationProvider migrationProvider = session.getProvider(MigrationProvider.class);
    // Create "roles" and "web-origins" clientScopes
    ClientScopeModel rolesScope = migrationProvider.addOIDCRolesClientScope(realm);
    ClientScopeModel webOriginsScope = migrationProvider.addOIDCWebOriginsClientScope(realm);
    LOG.debugf("Added '%s' and '%s' default client scopes", rolesScope.getName(), webOriginsScope.getName());
    // Assign "roles" and "web-origins" clientScopes to all the OIDC clients
    realm.getClientsStream().filter(MigrationUtils::isOIDCNonBearerOnlyClient).forEach(c -> {
        c.addClientScope(rolesScope, true);
        c.addClientScope(webOriginsScope, true);
    });
    LOG.debugf("Client scope '%s' assigned to all the clients", rolesScope.getName());
}
Also used : MigrationProvider(org.keycloak.migration.MigrationProvider) ClientScopeModel(org.keycloak.models.ClientScopeModel)

Aggregations

MigrationProvider (org.keycloak.migration.MigrationProvider)6 ClientScopeModel (org.keycloak.models.ClientScopeModel)2 ProtocolMapperModel (org.keycloak.models.ProtocolMapperModel)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Map (java.util.Map)1 InsertStatement (liquibase.statement.core.InsertStatement)1 ModelVersion (org.keycloak.migration.ModelVersion)1 AuthenticationFlowModel (org.keycloak.models.AuthenticationFlowModel)1 Constants (org.keycloak.models.Constants)1 KeycloakSession (org.keycloak.models.KeycloakSession)1 RealmModel (org.keycloak.models.RealmModel)1 DefaultAuthenticationFlows (org.keycloak.models.utils.DefaultAuthenticationFlows)1 ProtocolMapperRepresentation (org.keycloak.representations.idm.ProtocolMapperRepresentation)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1