KEYCLOAK-1187
This commit is contained in:
parent
4fbbf39c51
commit
600353899a
10 changed files with 21 additions and 21 deletions
|
@ -81,7 +81,7 @@ public class ImportUtils {
|
||||||
// We just imported master realm. All 'masterAdminApps' need to be refreshed
|
// We just imported master realm. All 'masterAdminApps' need to be refreshed
|
||||||
RealmModel adminRealm = realm;
|
RealmModel adminRealm = realm;
|
||||||
for (RealmModel currentRealm : model.getRealms()) {
|
for (RealmModel currentRealm : model.getRealms()) {
|
||||||
ClientModel masterApp = adminRealm.getClientByClientId(KeycloakModelUtils.getMasterRealmAdminApplicationName(currentRealm));
|
ClientModel masterApp = adminRealm.getClientByClientId(KeycloakModelUtils.getMasterRealmAdminApplicationClientId(currentRealm));
|
||||||
if (masterApp != null) {
|
if (masterApp != null) {
|
||||||
currentRealm.setMasterAdminClient(masterApp);
|
currentRealm.setMasterAdminClient(masterApp);
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,7 +91,7 @@ public class ImportUtils {
|
||||||
} else {
|
} else {
|
||||||
// Need to refresh masterApp for current realm
|
// Need to refresh masterApp for current realm
|
||||||
RealmModel adminRealm = model.getRealm(adminRealmId);
|
RealmModel adminRealm = model.getRealm(adminRealmId);
|
||||||
ClientModel masterApp = adminRealm.getClientByClientId(KeycloakModelUtils.getMasterRealmAdminApplicationName(realm));
|
ClientModel masterApp = adminRealm.getClientByClientId(KeycloakModelUtils.getMasterRealmAdminApplicationClientId(realm));
|
||||||
if (masterApp != null) {
|
if (masterApp != null) {
|
||||||
realm.setMasterAdminClient(masterApp);
|
realm.setMasterAdminClient(masterApp);
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,7 +119,7 @@ public class ImportUtils {
|
||||||
}
|
}
|
||||||
adminRole.setDescription("${role_"+AdminRoles.ADMIN+"}");
|
adminRole.setDescription("${role_"+AdminRoles.ADMIN+"}");
|
||||||
|
|
||||||
ClientModel realmAdminApp = KeycloakModelUtils.createClient(adminRealm, KeycloakModelUtils.getMasterRealmAdminApplicationName(realm));
|
ClientModel realmAdminApp = KeycloakModelUtils.createClient(adminRealm, KeycloakModelUtils.getMasterRealmAdminApplicationClientId(realm));
|
||||||
realmAdminApp.setBearerOnly(true);
|
realmAdminApp.setBearerOnly(true);
|
||||||
realm.setMasterAdminClient(realmAdminApp);
|
realm.setMasterAdminClient(realmAdminApp);
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class AdminRoles {
|
||||||
|
|
||||||
public static String ADMIN = "admin";
|
public static String ADMIN = "admin";
|
||||||
|
|
||||||
// for admin application local to each realm
|
// for admin client local to each realm
|
||||||
public static String REALM_ADMIN = "realm-admin";
|
public static String REALM_ADMIN = "realm-admin";
|
||||||
|
|
||||||
public static String CREATE_REALM = "create-realm";
|
public static String CREATE_REALM = "create-realm";
|
||||||
|
|
|
@ -16,7 +16,7 @@ public interface ClientModel extends RoleContainerModel {
|
||||||
String PUBLIC_KEY = "publicKey";
|
String PUBLIC_KEY = "publicKey";
|
||||||
String X509CERTIFICATE = "X509Certificate";
|
String X509CERTIFICATE = "X509Certificate";
|
||||||
|
|
||||||
void updateApplication();
|
void updateClient();
|
||||||
|
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,7 @@ public final class KeycloakModelUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMasterRealmAdminApplicationName(RealmModel realm) {
|
public static String getMasterRealmAdminApplicationClientId(RealmModel realm) {
|
||||||
return realm.getName() + "-realm";
|
return realm.getName() + "-realm";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -517,7 +517,7 @@ public class RepresentationToModel {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ClientModel createClient(KeycloakSession session, RealmModel realm, ClientRepresentation resourceRep, boolean addDefaultRoles) {
|
public static ClientModel createClient(KeycloakSession session, RealmModel realm, ClientRepresentation resourceRep, boolean addDefaultRoles) {
|
||||||
logger.debug("************ CREATE APPLICATION: {0}" + resourceRep.getClientId());
|
logger.debug("Create client: {0}" + resourceRep.getClientId());
|
||||||
|
|
||||||
ClientModel client = resourceRep.getId()!=null ? realm.addClient(resourceRep.getId(), resourceRep.getClientId()) : realm.addClient(resourceRep.getClientId());
|
ClientModel client = resourceRep.getId()!=null ? realm.addClient(resourceRep.getId(), resourceRep.getClientId()) : realm.addClient(resourceRep.getClientId());
|
||||||
if (resourceRep.isEnabled() != null) client.setEnabled(resourceRep.isEnabled());
|
if (resourceRep.isEnabled() != null) client.setEnabled(resourceRep.isEnabled());
|
||||||
|
@ -540,7 +540,7 @@ public class RepresentationToModel {
|
||||||
} else {
|
} else {
|
||||||
client.setNodeReRegistrationTimeout(-1);
|
client.setNodeReRegistrationTimeout(-1);
|
||||||
}
|
}
|
||||||
client.updateApplication();
|
client.updateClient();
|
||||||
|
|
||||||
if (resourceRep.getNotBefore() != null) {
|
if (resourceRep.getNotBefore() != null) {
|
||||||
client.setNotBefore(resourceRep.getNotBefore());
|
client.setNotBefore(resourceRep.getNotBefore());
|
||||||
|
@ -565,7 +565,7 @@ public class RepresentationToModel {
|
||||||
}
|
}
|
||||||
if (resourceRep.getWebOrigins() != null) {
|
if (resourceRep.getWebOrigins() != null) {
|
||||||
for (String webOrigin : resourceRep.getWebOrigins()) {
|
for (String webOrigin : resourceRep.getWebOrigins()) {
|
||||||
logger.debugv("Application: {0} webOrigin: {1}", resourceRep.getClientId(), webOrigin);
|
logger.debugv("Client: {0} webOrigin: {1}", resourceRep.getClientId(), webOrigin);
|
||||||
client.addWebOrigin(webOrigin);
|
client.addWebOrigin(webOrigin);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -580,7 +580,7 @@ public class RepresentationToModel {
|
||||||
if (uri.getPort() != -1) {
|
if (uri.getPort() != -1) {
|
||||||
origin += ":" + uri.getPort();
|
origin += ":" + uri.getPort();
|
||||||
}
|
}
|
||||||
logger.debugv("adding default application origin: {0}" , origin);
|
logger.debugv("adding default client origin: {0}" , origin);
|
||||||
origins.add(origin);
|
origins.add(origin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -627,7 +627,7 @@ public class RepresentationToModel {
|
||||||
if (rep.getBaseUrl() != null) resource.setBaseUrl(rep.getBaseUrl());
|
if (rep.getBaseUrl() != null) resource.setBaseUrl(rep.getBaseUrl());
|
||||||
if (rep.isSurrogateAuthRequired() != null) resource.setSurrogateAuthRequired(rep.isSurrogateAuthRequired());
|
if (rep.isSurrogateAuthRequired() != null) resource.setSurrogateAuthRequired(rep.isSurrogateAuthRequired());
|
||||||
if (rep.getNodeReRegistrationTimeout() != null) resource.setNodeReRegistrationTimeout(rep.getNodeReRegistrationTimeout());
|
if (rep.getNodeReRegistrationTimeout() != null) resource.setNodeReRegistrationTimeout(rep.getNodeReRegistrationTimeout());
|
||||||
resource.updateApplication();
|
resource.updateClient();
|
||||||
|
|
||||||
if (rep.getProtocol() != null) resource.setProtocol(rep.getProtocol());
|
if (rep.getProtocol() != null) resource.setProtocol(rep.getProtocol());
|
||||||
if (rep.getAttributes() != null) {
|
if (rep.getAttributes() != null) {
|
||||||
|
@ -725,7 +725,7 @@ public class RepresentationToModel {
|
||||||
for (ScopeMappingRepresentation mapping : mappings) {
|
for (ScopeMappingRepresentation mapping : mappings) {
|
||||||
ClientModel client = realm.getClientByClientId(mapping.getClient());
|
ClientModel client = realm.getClientByClientId(mapping.getClient());
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
throw new RuntimeException("Unknown client specified in application scope mappings");
|
throw new RuntimeException("Unknown client specified in client scope mappings");
|
||||||
}
|
}
|
||||||
for (String roleString : mapping.getRoles()) {
|
for (String roleString : mapping.getRoles()) {
|
||||||
RoleModel role = clientModel.getRole(roleString.trim());
|
RoleModel role = clientModel.getRole(roleString.trim());
|
||||||
|
@ -821,15 +821,15 @@ public class RepresentationToModel {
|
||||||
|
|
||||||
// Role mappings
|
// Role mappings
|
||||||
|
|
||||||
public static void createClientRoleMappings(ClientModel applicationModel, UserModel user, List<String> roleNames) {
|
public static void createClientRoleMappings(ClientModel clientModel, UserModel user, List<String> roleNames) {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new RuntimeException("User not found");
|
throw new RuntimeException("User not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String roleName : roleNames) {
|
for (String roleName : roleNames) {
|
||||||
RoleModel role = applicationModel.getRole(roleName.trim());
|
RoleModel role = clientModel.getRole(roleName.trim());
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
role = applicationModel.addRole(roleName.trim());
|
role = clientModel.addRole(roleName.trim());
|
||||||
}
|
}
|
||||||
user.grantRole(role);
|
user.grantRole(role);
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class ClientAdapter implements ClientModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateApplication() {
|
public void updateClient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -42,8 +42,8 @@ public class ClientAdapter implements ClientModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateApplication() {
|
public void updateClient() {
|
||||||
if (updated != null) updated.updateApplication();
|
if (updated != null) updated.updateClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -469,7 +469,7 @@ public class ClientAdapter implements ClientModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateApplication() {
|
public void updateClient() {
|
||||||
em.flush();
|
em.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class ClientAdapter extends AbstractMongoAdapter<MongoClientEntity> imple
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateApplication() {
|
public void updateClient() {
|
||||||
updateMongoEntity();
|
updateMongoEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class ClientModelTest extends AbstractModelTest {
|
||||||
client.registerNode("node1", 10);
|
client.registerNode("node1", 10);
|
||||||
client.registerNode("10.20.30.40", 50);
|
client.registerNode("10.20.30.40", 50);
|
||||||
|
|
||||||
client.updateApplication();
|
client.updateClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue