KEYCLOAK-1070 Migration for adding names to builtin clients

This commit is contained in:
mposolda 2015-04-28 09:35:57 +02:00
parent 1d4bf4ddaa
commit 5e0f560fdc
9 changed files with 40 additions and 6 deletions

View file

@ -40,7 +40,8 @@ public class DefaultMongoConnectionFactoryProvider implements MongoConnectionPro
"org.keycloak.models.entities.UserFederationProviderEntity",
"org.keycloak.models.entities.ProtocolMapperEntity",
"org.keycloak.models.entities.IdentityProviderMapperEntity",
"org.keycloak.models.mongo.keycloak.entities.MongoUserConsentEntity"
"org.keycloak.models.mongo.keycloak.entities.MongoUserConsentEntity",
"org.keycloak.models.mongo.keycloak.entities.MongoMigrationModelEntity"
};
private static final Logger logger = Logger.getLogger(DefaultMongoConnectionFactoryProvider.class);

View file

@ -9,6 +9,7 @@
<form action="${url.revokeClientUrl}" method="post">
<input type="hidden" id="stateChecker" name="stateChecker" value="${stateChecker}">
<input type="hidden" id="referrer" name="referrer" value="${stateChecker}">
<table class="table table-striped table-bordered">
<thead>

View file

@ -51,9 +51,11 @@ role_manage-clients=Manage clients
role_manage-events=Manage events
role_view-profile=View profile
role_manage-account=Manage account
role_read-token=Read token
client_account=Account
client_security-admin-console=Security Admin Console
client_realm-management=Realm Management
client_broker=Broker
requiredFields=Required fields

View file

@ -84,9 +84,11 @@ role_manage-clients=Manage clients
role_manage-events=Manage events
role_view-profile=View profile
role_manage-account=Manage account
role_read-token=Read token
client_account=Account
client_security-admin-console=Security Admin Console
client_realm-management=Realm Management
client_broker=Broker
invalidUserMessage=Invalid username or password.
invalidEmailMessage=Invalid email address.

View file

@ -8,6 +8,7 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.utils.KeycloakModelUtils;
import java.util.List;
import java.util.Map;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
@ -21,17 +22,33 @@ public class MigrationTo1_2_0_RC1 {
if (client == null) {
client = KeycloakModelUtils.createClient(realm, Constants.BROKER_SERVICE_CLIENT_ID);
client.setEnabled(true);
client.setName("${client_" + Constants.BROKER_SERVICE_CLIENT_ID + "}");
client.setFullScopeAllowed(false);
for (String role : Constants.BROKER_SERVICE_ROLES) {
client.addRole(role).setDescription("${role_"+role+"}");
client.addRole(role).setDescription("${role_"+ role.toLowerCase().replaceAll("_", "-") +"}");
}
}
}
private void setupClientNames(RealmModel realm) {
Map<String, ClientModel> clients = realm.getClientNameMap();
setupClientName(clients, Constants.ACCOUNT_MANAGEMENT_CLIENT_ID);
setupClientName(clients, Constants.ADMIN_CONSOLE_CLIENT_ID);
setupClientName(clients, Constants.REALM_MANAGEMENT_CLIENT_ID);
}
private void setupClientName(Map<String, ClientModel> clients, String clientId) {
ClientModel client = clients.get(clientId);
if (client != null && client.getName() == null) client.setName("${client_" + clientId + "}");
}
public void migrate(KeycloakSession session) {
List<RealmModel> realms = session.realms().getRealms();
for (RealmModel realm : realms) {
setupBrokerService(realm);
setupClientNames(realm);
}
}

View file

@ -9,6 +9,7 @@ public interface Constants {
String ACCOUNT_MANAGEMENT_CLIENT_ID = "account";
String BROKER_SERVICE_CLIENT_ID = "broker";
String REALM_MANAGEMENT_CLIENT_ID = "realm-management";
String INSTALLED_APP_URN = "urn:ietf:wg:oauth:2.0:oob";
String INSTALLED_APP_URL = "http://localhost";

View file

@ -1,5 +1,6 @@
package org.keycloak.models.mongo.keycloak.entities;
import org.keycloak.connections.mongo.api.MongoCollection;
import org.keycloak.connections.mongo.api.MongoIdentifiableEntity;
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
@ -7,6 +8,7 @@ import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
@MongoCollection(collectionName = "migrationModel")
public class MongoMigrationModelEntity implements MongoIdentifiableEntity {
public static final String MIGRATION_MODEL_ID = "VERSION";
private String id = MIGRATION_MODEL_ID;

View file

@ -113,11 +113,11 @@ public class RealmManager {
}
public String getRealmAdminClientId(RealmModel realm) {
return "realm-management";
return Constants.REALM_MANAGEMENT_CLIENT_ID;
}
public String getRealmAdminClientId(RealmRepresentation realm) {
return "realm-management";
return Constants.REALM_MANAGEMENT_CLIENT_ID;
}
@ -223,10 +223,11 @@ public class RealmManager {
if (client == null) {
client = new ClientManager(this).createClient(realm, Constants.BROKER_SERVICE_CLIENT_ID);
client.setEnabled(true);
client.setName("${client_" + Constants.BROKER_SERVICE_CLIENT_ID + "}");
client.setFullScopeAllowed(false);
for (String role : Constants.BROKER_SERVICE_ROLES) {
client.addRole(role).setDescription("${role_"+role+"}");
client.addRole(role).setDescription("${role_"+ role.toLowerCase().replaceAll("_", "-") +"}");
}
}
}

View file

@ -531,7 +531,14 @@ public class AccountService {
event.event(EventType.REVOKE_GRANT).client(auth.getClient()).user(auth.getUser()).detail(Details.REVOKED_CLIENT, client.getClientId()).success();
setReferrerOnPage();
return account.setSuccess(Messages.SUCCESS_GRANT_REVOKED).createResponse(AccountPages.APPLICATIONS);
UriBuilder builder = Urls.accountBase(uriInfo.getBaseUri()).path(AccountService.class, "applicationsPage");
String referrer = uriInfo.getQueryParameters().getFirst("referrer");
if (referrer != null) {
builder.queryParam("referrer", referrer);
}
URI location = builder.build(realm.getName());
return Response.seeOther(location).build();
}
/**