Skip to content
Snippets Groups Projects
Commit cc029461 authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-6495 addOrUpdateRole also by realm creation' (#33)...

Merge pull request 'OZG-6495 addOrUpdateRole also by realm creation' (#33) from OZG-6495 into master
parents 8d0968b4 b23dbc44
No related branches found
No related tags found
No related merge requests found
......@@ -43,22 +43,14 @@ class KeycloakRealmService {
private final KeycloakGenericRemoteService keycloakGenericRemoteService;
void createRealm(OzgCloudKeycloakRealmSpec realm, String realmName) {
Optional.of(realm)
.map(mapper::map)
.map(realmRepresentation -> addRealmName(realmRepresentation, realmName))
.filter(realmRepresentation -> !keycloakGenericRemoteService.realmExists(realmName))
.ifPresent(remoteService::createRealm);
}
public void createOrUpdateRealm(OzgCloudKeycloakRealmSpec realm, String realmName) {
keycloakGenericRemoteService.getRealmRepresentation(realmName)
.ifPresentOrElse(existingRealm -> updateRealm(existingRealm, realm),
() -> createRealm(realm, realmName));
addOrUpdateRealmRoles(realm, realmName);
}
void updateRealm(RealmRepresentation existingRealm, OzgCloudKeycloakRealmSpec spec) {
try {
LOG.debug("{}: Updating existing realm...", existingRealm);
var realmRepresentation = mapper.update(existingRealm, spec);
......@@ -67,8 +59,14 @@ class KeycloakRealmService {
LOG.warn(existingRealm + ": Updating existing realm failed: ", e);
throw e;
}
addOrUpdateRealmRoles(spec, existingRealm.getRealm());
}
void createRealm(OzgCloudKeycloakRealmSpec realm, String realmName) {
Optional.of(realm)
.map(mapper::map)
.map(realmRepresentation -> addRealmName(realmRepresentation, realmName))
.filter(realmRepresentation -> !keycloakGenericRemoteService.realmExists(realmName))
.ifPresent(remoteService::createRealm);
}
void addOrUpdateRealmRoles(OzgCloudKeycloakRealmSpec spec, String realm) {
......
......@@ -92,6 +92,13 @@ class KeycloakRealmServiceTest {
verify(keycloakGenericRemoteService).getRealmRepresentation(REALM_NAME);
}
@Test
void shouldCallAddOrUpdateRealmRoles() {
service.createOrUpdateRealm(REALM, REALM_NAME);
verify(service).addOrUpdateRealmRoles(REALM, REALM_NAME);
}
}
@DisplayName("Update Realm")
......@@ -118,13 +125,6 @@ class KeycloakRealmServiceTest {
verify(mapper).update(realmRepresentation, REALM);
}
@Test
void shouldCallAddOrUpdateRealmRoles() {
service.updateRealm(realmRepresentation, REALM);
verify(service).addOrUpdateRealmRoles(REALM, realmRepresentation.getRealm());
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment