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

OZG-5422 simplify maping for realm roles

parent 18b290fd
Branches
Tags
No related merge requests found
......@@ -52,9 +52,13 @@ interface KeycloakRealmMapper {
@Mapping(target = "passwordPolicy", constant = "upperCase(1) and lowerCase(1) and length(8) and notUsername")
@Mapping(target = "actionTokenGeneratedByUserLifespan", constant = "900")
@Mapping(target = "smtpServer", source = "smtpServer", qualifiedByName = "smtpServer")
@Mapping(target = "roles", source = "realmRoles", qualifiedByName = "roles")
@Mapping(target = "roles.realm", source = "realmRoles")
public RealmRepresentation map(OzgCloudKeycloakRealmSpec realm);
@Mapping(target = "name", source = "name")
RoleRepresentation map(OzgCloudKeycloakRealmSpec.RealmRole role);
@Named("supportedLocales")
default Set<String> mapPassword(OzgCloudKeycloakRealmSpec spec) {
return Set.of("de");
......@@ -78,31 +82,4 @@ interface KeycloakRealmMapper {
}
@Named("roles")
default RolesRepresentation maprealmRoles(List<OzgCloudKeycloakRealmSpec.RealmRole> realmRoles) {
RolesRepresentation roles = new RolesRepresentation();
if (realmRoles != null) {
List<String> roleNames = realmRoles.stream()
.map(RealmRole::getName)
.collect(Collectors.toList());
List<RoleRepresentation> rolerepresentationList = new ArrayList<>(roleNames.size());
roleNames.forEach(roleName -> {
RoleRepresentation newRepresentation = new RoleRepresentation();
newRepresentation.setName(roleName);
rolerepresentationList.add(newRepresentation);
});
roles.setRealm(rolerepresentationList);
Map<String, List<RoleRepresentation>> client = new HashMap<>();
roles.setClient(client);
}
return roles;
}
}
......@@ -51,9 +51,7 @@ class OzgCloudKeycloakRealmSpec {
private KeycloakRealmSMTPServer smtpServer;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
static class KeycloakRealmSMTPServer {
......@@ -77,9 +75,7 @@ class OzgCloudKeycloakRealmSpec {
private List<RealmRole> realmRoles = new ArrayList<>();
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
static class RealmRole {
......
......@@ -123,7 +123,7 @@ class KeycloakRealmMapperTest {
void shouldMapRealmRoles() {
var mapped = mapper.map(OzgCloudKeycloakRealmSpecTestFactory.create());
assertThat(mapped.getRoles().getRealm().size()).isEqualTo(2);
assertThat(mapped.getRoles().getRealm()).hasSize(2);
}
@Test
......@@ -134,11 +134,4 @@ class KeycloakRealmMapperTest {
assertThat(mappedRealmRoles.getRealm().get(0).getName()).isEqualTo(OzgCloudKeycloakRealmSpecTestFactory.ROLE_NAME_1);
assertThat(mappedRealmRoles.getRealm().get(1).getName()).isEqualTo(OzgCloudKeycloakRealmSpecTestFactory.ROLE_NAME_2);
}
@Test
void shouldMapWhenRealmRolesIsNull() {
var mapped = mapper.map(OzgCloudKeycloakRealmSpecTestFactory.createBuilder().realmRoles(null).build());
assertThat(mapped.getRoles()).isNotNull();
}
}
......@@ -72,6 +72,9 @@ class KeycloakRealmReconcilerTest {
assertThat(response.getResource().getStatus().getStatus()).isEqualTo(OzgCloudCustomResourceStatus.OK);
}
}
@DisplayName("Reconciler Cleanup")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment