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

OZG-3961 - add realm settings

parent 98311071
No related branches found
No related tags found
No related merge requests found
package de.ozgcloud.operator.keycloak.realm; package de.ozgcloud.operator.keycloak.realm;
import java.util.Set;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.ReportingPolicy; import org.mapstruct.ReportingPolicy;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, unmappedSourcePolicy = ReportingPolicy.IGNORE) @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, unmappedSourcePolicy = ReportingPolicy.IGNORE)
interface KeycloakRealmMapper { interface KeycloakRealmMapper {
@Mapping(target = "displayName", source = "displayName") @Mapping(target = "displayName", source = "displayName")
@Mapping(target = "enabled", constant = "true")
@Mapping(target = "resetPasswordAllowed", constant = "true")
@Mapping(target = "supportedLocales", source = ".", qualifiedByName = "supportedLocales")
@Mapping(target = "defaultLocale", constant = "de")
@Mapping(target = "internationalizationEnabled", constant = "true")
@Mapping(target = "passwordPolicy", constant = "upperCase(1) and lowerCase(1) and length(8) and notUsername")
RealmRepresentation map(OzgKeycloakRealmSpec realm); RealmRepresentation map(OzgKeycloakRealmSpec realm);
@Named("supportedLocales")
default Set<String> mapPassword(OzgKeycloakRealmSpec spec) {
return Set.of("de");
}
} }
...@@ -41,7 +41,7 @@ class KeycloakUserPreconditionService { ...@@ -41,7 +41,7 @@ class KeycloakUserPreconditionService {
.map(KeycloakUserSpecClientRole::getClientId) .map(KeycloakUserSpecClientRole::getClientId)
.map(clientId -> keycloakGenericRemoteService.getByClientId(clientId, realm)) .map(clientId -> keycloakGenericRemoteService.getByClientId(clientId, realm))
.filter(Optional::isEmpty) .filter(Optional::isEmpty)
.map(clientId -> "Cient " + clientId + " does not yet exist") .map(clientId -> "Client " + clientId + " does not yet exist")
.findAny(); .findAny();
} }
......
...@@ -17,4 +17,46 @@ class KeycloakRealmMapperTest { ...@@ -17,4 +17,46 @@ class KeycloakRealmMapperTest {
assertThat(mapped.getDisplayName()).isEqualTo(OzgKeycloakRealmSpecTestFactory.DISPLAY_NAME); assertThat(mapped.getDisplayName()).isEqualTo(OzgKeycloakRealmSpecTestFactory.DISPLAY_NAME);
} }
@Test
void shouldBeEnabled() {
var mapped = mapper.map(OzgKeycloakRealmSpecTestFactory.create());
assertThat(mapped.isEnabled()).isTrue();
}
@Test
void shouldBeResetPasswordAllowed() {
var mapped = mapper.map(OzgKeycloakRealmSpecTestFactory.create());
assertThat(mapped.isResetPasswordAllowed()).isTrue();
}
@Test
void shouldBeSupportedLocaleDe() {
var mapped = mapper.map(OzgKeycloakRealmSpecTestFactory.create());
assertThat(mapped.getSupportedLocales()).containsExactly("de");
}
@Test
void shouldBeDefaultLocaleDe() {
var mapped = mapper.map(OzgKeycloakRealmSpecTestFactory.create());
assertThat(mapped.getDefaultLocale()).isEqualTo("de");
}
@Test
void shouldBeInternationalizationEnabled() {
var mapped = mapper.map(OzgKeycloakRealmSpecTestFactory.create());
assertThat(mapped.isInternationalizationEnabled()).isTrue();
}
@Test
void checkPasswordPolicy() {
var mapped = mapper.map(OzgKeycloakRealmSpecTestFactory.create());
assertThat(mapped.getPasswordPolicy()).isEqualTo("upperCase(1) and lowerCase(1) and length(8) and notUsername");
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment