KEYCLOAK-192 Set realm id to name if not specified
This commit is contained in:
parent
742acaf8db
commit
f133ecfcf7
2 changed files with 6 additions and 1 deletions
|
@ -65,7 +65,7 @@ public class RealmManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealmModel createRealm(String name) {
|
public RealmModel createRealm(String name) {
|
||||||
return createRealm(generateId(), name);
|
return createRealm(name, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealmModel createRealm(String id, String name) {
|
public RealmModel createRealm(String id, String name) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.representations.idm.RealmRepresentation;
|
import org.keycloak.representations.idm.RealmRepresentation;
|
||||||
import org.keycloak.services.managers.RealmManager;
|
import org.keycloak.services.managers.RealmManager;
|
||||||
import org.keycloak.services.resources.SaasService;
|
import org.keycloak.services.resources.SaasService;
|
||||||
|
import org.keycloak.services.resources.flows.Flows;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.container.ResourceContext;
|
import javax.ws.rs.container.ResourceContext;
|
||||||
|
@ -71,6 +72,10 @@ public class RealmsAdminResource {
|
||||||
public Response importRealm(@Context final UriInfo uriInfo, final RealmRepresentation rep) {
|
public Response importRealm(@Context final UriInfo uriInfo, final RealmRepresentation rep) {
|
||||||
logger.debug("importRealm: {0}", rep.getRealm());
|
logger.debug("importRealm: {0}", rep.getRealm());
|
||||||
RealmManager realmManager = new RealmManager(session);
|
RealmManager realmManager = new RealmManager(session);
|
||||||
|
if (realmManager.getRealm(rep.getRealm()) != null) {
|
||||||
|
return Flows.errors().exists("Realm " + rep.getRealm() + " already exists");
|
||||||
|
}
|
||||||
|
|
||||||
RealmModel realm = realmManager.importRealm(rep, admin);
|
RealmModel realm = realmManager.importRealm(rep, admin);
|
||||||
URI location = realmUrl(uriInfo).build(realm.getId());
|
URI location = realmUrl(uriInfo).build(realm.getId());
|
||||||
logger.debug("imported realm success, sending back: {0}", location.toString());
|
logger.debug("imported realm success, sending back: {0}", location.toString());
|
||||||
|
|
Loading…
Reference in a new issue