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

OZG-7303 add realm loginTheme

parent 2c53c2d1
Branches OZG-7303
No related tags found
No related merge requests found
......@@ -42,6 +42,16 @@ import lombok.extern.log4j.Log4j2;
class KeycloakRealmService {
public static final String USER_PROFILE_CONFIG_OZGCLOUD_ATTRIBUTE_NAME = "ozgCloudUserId";
public static final String ENVIRONMENT_PROD ="prod";
public static final String ENVIRONMENT_TEST ="test";
public static final String ENVIRONMENT_DEV ="dev";
public static final String BUNDESLAND_BY ="by";
public static final String BUNDESLAND_SH ="sh";
public static final String LOGIN_THEME_OZG_SH = "ozg-sh";
public static final String LOGIN_THEME_OZG_BY = "ozg-by";
public static final String LOGIN_THEME_OZG_DEFAULT = "ozg";
private final KeycloakRealmRemoteService remoteService;
......@@ -73,6 +83,7 @@ class KeycloakRealmService {
Optional.of(realm)
.map(mapper::map)
.map(realmRepresentation -> addRealmName(realmRepresentation, realmName))
.map(realmRepresentation -> addRealmTheme(realmRepresentation, realmName))
.ifPresent(realmRepresentation -> {
remoteService.createRealm(realmRepresentation);
addUserProfileAttributes(realmRepresentation);
......@@ -92,6 +103,11 @@ class KeycloakRealmService {
return realm;
}
RealmRepresentation addRealmTheme(RealmRepresentation realm, String realmName) {
realm.setLoginTheme(determinLoginTheme(realmName));
return realm;
}
public void deleteRealm(String realmName) {
remoteService.deleteRealm(realmName);
}
......@@ -113,4 +129,27 @@ class KeycloakRealmService {
new UPAttribute(USER_PROFILE_CONFIG_OZGCLOUD_ATTRIBUTE_NAME,
new UPAttributePermissions(Set.of("admin", "user"), Set.of("admin", "user"))));
}
String determinLoginTheme(String realmName) {
String[] parts = realmName.split("-");
String bundesland = parts[0].toLowerCase();
String environment = parts[parts.length - 1].toLowerCase();
switch (environment) {
case ENVIRONMENT_PROD:
return LOGIN_THEME_OZG_BY;
case ENVIRONMENT_DEV,ENVIRONMENT_TEST:
switch (bundesland) {
case BUNDESLAND_SH:
return LOGIN_THEME_OZG_SH;
case BUNDESLAND_BY:
return LOGIN_THEME_OZG_BY;
default:
return LOGIN_THEME_OZG_DEFAULT;
}
default:
return LOGIN_THEME_OZG_DEFAULT;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment