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

OZG-7303 add realm loginTheme

parent 2c53c2d1
No related merge requests found
...@@ -42,6 +42,16 @@ import lombok.extern.log4j.Log4j2; ...@@ -42,6 +42,16 @@ import lombok.extern.log4j.Log4j2;
class KeycloakRealmService { class KeycloakRealmService {
public static final String USER_PROFILE_CONFIG_OZGCLOUD_ATTRIBUTE_NAME = "ozgCloudUserId"; 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; private final KeycloakRealmRemoteService remoteService;
...@@ -73,6 +83,7 @@ class KeycloakRealmService { ...@@ -73,6 +83,7 @@ class KeycloakRealmService {
Optional.of(realm) Optional.of(realm)
.map(mapper::map) .map(mapper::map)
.map(realmRepresentation -> addRealmName(realmRepresentation, realmName)) .map(realmRepresentation -> addRealmName(realmRepresentation, realmName))
.map(realmRepresentation -> addRealmTheme(realmRepresentation, realmName))
.ifPresent(realmRepresentation -> { .ifPresent(realmRepresentation -> {
remoteService.createRealm(realmRepresentation); remoteService.createRealm(realmRepresentation);
addUserProfileAttributes(realmRepresentation); addUserProfileAttributes(realmRepresentation);
...@@ -92,6 +103,11 @@ class KeycloakRealmService { ...@@ -92,6 +103,11 @@ class KeycloakRealmService {
return realm; return realm;
} }
RealmRepresentation addRealmTheme(RealmRepresentation realm, String realmName) {
realm.setLoginTheme(determinLoginTheme(realmName));
return realm;
}
public void deleteRealm(String realmName) { public void deleteRealm(String realmName) {
remoteService.deleteRealm(realmName); remoteService.deleteRealm(realmName);
} }
...@@ -113,4 +129,27 @@ class KeycloakRealmService { ...@@ -113,4 +129,27 @@ class KeycloakRealmService {
new UPAttribute(USER_PROFILE_CONFIG_OZGCLOUD_ATTRIBUTE_NAME, new UPAttribute(USER_PROFILE_CONFIG_OZGCLOUD_ATTRIBUTE_NAME,
new UPAttributePermissions(Set.of("admin", "user"), Set.of("admin", "user")))); 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.
Please register or to comment