Merge pull request #1671 from stianst/master

KEYCLOAK-1882 Add locale mapper to admin console clients during migra…
This commit is contained in:
Stian Thorgersen 2015-10-02 15:09:43 +02:00
commit 53b86cbace
3 changed files with 31 additions and 7 deletions

View file

@ -1,5 +1,6 @@
package org.keycloak.migration;
import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.provider.Provider;
import org.keycloak.representations.idm.ProtocolMapperRepresentation;
@ -18,4 +19,6 @@ public interface MigrationProvider extends Provider {
*/
List<ProtocolMapperRepresentation> getMappersForClaimMask(Long claimMask);
List<ProtocolMapperModel> getBuiltinMappers(String protocol);
}

View file

@ -2,13 +2,10 @@ package org.keycloak.migration.migrators;
import java.util.List;
import org.keycloak.Config;
import org.keycloak.migration.MigrationProvider;
import org.keycloak.migration.ModelVersion;
import org.keycloak.models.ClientModel;
import org.keycloak.models.Constants;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.*;
import org.keycloak.models.utils.KeycloakModelUtils;
/**
@ -19,6 +16,20 @@ public class MigrateTo1_6_0 {
public static final ModelVersion VERSION = new ModelVersion("1.6.0");
public void migrate(KeycloakSession session) {
MigrationProvider provider = session.getProvider(MigrationProvider.class);
List<ProtocolMapperModel> builtinMappers = provider.getBuiltinMappers("openid-connect");
ProtocolMapperModel localeMapper = null;
for (ProtocolMapperModel m : builtinMappers) {
if (m.getName().equals("locale")) {
localeMapper = m;
}
}
if (localeMapper == null) {
throw new RuntimeException("Can't find default locale mapper");
}
List<RealmModel> realms = session.realms().getRealms();
for (RealmModel realm : realms) {
if (realm.getRole(Constants.OFFLINE_ACCESS_ROLE) == null) {
@ -39,8 +50,12 @@ public class MigrateTo1_6_0 {
user.grantRole(role);
}
}
}
ClientModel adminConsoleClient = realm.getClientByClientId(Constants.ADMIN_CONSOLE_CLIENT_ID);
if (adminConsoleClient != null) {
adminConsoleClient.addProtocolMapper(localeMapper);
}
}
}
}

View file

@ -53,6 +53,12 @@ public class DefaultMigrationProvider implements MigrationProvider {
return new ArrayList<ProtocolMapperRepresentation>(allMappers.values());
}
@Override
public List<ProtocolMapperModel> getBuiltinMappers(String protocol) {
LoginProtocolFactory providerFactory = (LoginProtocolFactory) session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, protocol);
return providerFactory.getBuiltinMappers();
}
@Override
public void close() {
}