Delete realm
This commit is contained in:
parent
5210f674c0
commit
52c7ae057a
7 changed files with 68 additions and 26 deletions
|
@ -137,7 +137,7 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, $ht
|
||||||
|
|
||||||
$scope.remove = function() {
|
$scope.remove = function() {
|
||||||
Dialog.confirmDelete($scope.realm.realm, 'realm', function() {
|
Dialog.confirmDelete($scope.realm.realm, 'realm', function() {
|
||||||
Realm.remove($scope.realm, function() {
|
Realm.remove({ id : $scope.realm.id }, function() {
|
||||||
Current.realms = Realm.get();
|
Current.realms = Realm.get();
|
||||||
$location.url("/realms");
|
$location.url("/realms");
|
||||||
Notifications.success("The realm has been deleted.");
|
Notifications.success("The realm has been deleted.");
|
||||||
|
|
|
@ -13,7 +13,7 @@ public interface KeycloakSession {
|
||||||
RealmModel createRealm(String id, String name);
|
RealmModel createRealm(String id, String name);
|
||||||
RealmModel getRealm(String id);
|
RealmModel getRealm(String id);
|
||||||
List<RealmModel> getRealms(UserModel admin);
|
List<RealmModel> getRealms(UserModel admin);
|
||||||
void deleteRealm(RealmModel realm);
|
boolean removeRealm(String id);
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package org.keycloak.models.jpa;
|
package org.keycloak.models.jpa;
|
||||||
|
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.*;
|
||||||
import org.keycloak.models.KeycloakTransaction;
|
import org.keycloak.models.jpa.entities.*;
|
||||||
import org.keycloak.models.RealmModel;
|
|
||||||
import org.keycloak.models.UserModel;
|
|
||||||
import org.keycloak.models.jpa.entities.RealmEntity;
|
|
||||||
import org.keycloak.models.utils.KeycloakSessionUtils;
|
import org.keycloak.models.utils.KeycloakSessionUtils;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,8 +60,26 @@ public class JpaKeycloakSession implements KeycloakSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteRealm(RealmModel realm) {
|
public boolean removeRealm(String id) {
|
||||||
throw new RuntimeException("Not Implemented Yet");
|
RealmEntity realm = em.find(RealmEntity.class, id);
|
||||||
|
if (realm == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
RealmAdapter adapter = new RealmAdapter(em, realm);
|
||||||
|
for (ApplicationEntity a : new LinkedList<ApplicationEntity>(realm.getApplications())) {
|
||||||
|
adapter.removeApplication(a.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (UserEntity u : em.createQuery("from UserEntity", UserEntity.class).getResultList()) {
|
||||||
|
adapter.removeUser(u.getLoginName());
|
||||||
|
}
|
||||||
|
|
||||||
|
em.createQuery("delete from " + OAuthClientEntity.class.getSimpleName() + " where realm = :realm").setParameter("realm", realm).executeUpdate();
|
||||||
|
|
||||||
|
em.remove(realm);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -95,9 +95,13 @@ public class PicketlinkKeycloakSession implements KeycloakSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteRealm(RealmModel realm) {
|
public boolean removeRealm(String id) {
|
||||||
throw new RuntimeException("Not Implemented Yet");
|
RealmData partition = partitionManager.getPartition(RealmData.class, id);
|
||||||
|
if (partition == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
partitionManager.remove(partition);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,11 +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 javax.ws.rs.Consumes;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.container.ResourceContext;
|
import javax.ws.rs.container.ResourceContext;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
|
|
||||||
|
@ -65,6 +61,12 @@ public class RealmAdminResource extends RoleContainerResource {
|
||||||
new RealmManager(session).updateRealm(rep, realm);
|
new RealmManager(session).updateRealm(rep, realm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
public void deleteRealms() {
|
||||||
|
if (!session.removeRealm(realm.getId())) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Path("users")
|
@Path("users")
|
||||||
public UsersResource users() {
|
public UsersResource users() {
|
||||||
|
|
|
@ -9,13 +9,7 @@ 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 javax.ws.rs.Consumes;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.NotFoundException;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.container.ResourceContext;
|
import javax.ws.rs.container.ResourceContext;
|
||||||
import javax.ws.rs.core.CacheControl;
|
import javax.ws.rs.core.CacheControl;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
|
@ -94,6 +88,4 @@ public class RealmsAdminResource {
|
||||||
resourceContext.initResource(adminResource);
|
resourceContext.initResource(adminResource);
|
||||||
return adminResource;
|
return adminResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,6 +228,34 @@ public class AdapterTest extends AbstractKeycloakTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveRealm() throws Exception {
|
||||||
|
test1CreateRealm();
|
||||||
|
|
||||||
|
UserModel user = realmModel.addUser("bburke");
|
||||||
|
|
||||||
|
UserCredentialModel cred = new UserCredentialModel();
|
||||||
|
cred.setType(CredentialRepresentation.PASSWORD);
|
||||||
|
cred.setValue("password");
|
||||||
|
realmModel.updateCredential(user, cred);
|
||||||
|
|
||||||
|
OAuthClientModel client = realmModel.addOAuthClient("client");
|
||||||
|
|
||||||
|
ApplicationModel app = realmModel.addApplication("test-app");
|
||||||
|
|
||||||
|
RoleModel appRole = app.addRole("test");
|
||||||
|
app.grantRole(user, appRole);
|
||||||
|
app.addScopeMapping(client.getOAuthAgent(), appRole);
|
||||||
|
|
||||||
|
RoleModel realmRole = realmModel.addRole("test");
|
||||||
|
realmModel.addScopeMapping(app.getApplicationUser(), realmRole);
|
||||||
|
|
||||||
|
Assert.assertTrue(identitySession.removeRealm(realmModel.getId()));
|
||||||
|
Assert.assertFalse(identitySession.removeRealm(realmModel.getId()));
|
||||||
|
Assert.assertNull(identitySession.getRealm(realmModel.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveRole() throws Exception {
|
public void testRemoveRole() throws Exception {
|
||||||
test1CreateRealm();
|
test1CreateRealm();
|
||||||
|
|
Loading…
Reference in a new issue