keycloak-aplcache

Changes

Details

diff --git a/core/src/main/java/org/keycloak/representations/info/ServerInfoRepresentation.java b/core/src/main/java/org/keycloak/representations/info/ServerInfoRepresentation.java
index 640f3f6..935c441 100755
--- a/core/src/main/java/org/keycloak/representations/info/ServerInfoRepresentation.java
+++ b/core/src/main/java/org/keycloak/representations/info/ServerInfoRepresentation.java
@@ -14,7 +14,7 @@ public class ServerInfoRepresentation {
     private SystemInfoRepresentation systemInfo;
     private MemoryInfoRepresentation memoryInfo;
 
-    private Map<String, List<String>> themes;
+    private Map<String, List<ThemeInfoRepresentation>> themes;
 
     private List<Map<String, String>> socialProviders;
     private List<Map<String, String>> identityProviders;
@@ -43,11 +43,12 @@ public class ServerInfoRepresentation {
     public void setMemoryInfo(MemoryInfoRepresentation memoryInfo) {
         this.memoryInfo = memoryInfo;
     }
-    public Map<String, List<String>> getThemes() {
+
+    public Map<String, List<ThemeInfoRepresentation>> getThemes() {
         return themes;
     }
 
-    public void setThemes(Map<String, List<String>> themes) {
+    public void setThemes(Map<String, List<ThemeInfoRepresentation>> themes) {
         this.themes = themes;
     }
 
diff --git a/core/src/main/java/org/keycloak/representations/info/ThemeInfoRepresentation.java b/core/src/main/java/org/keycloak/representations/info/ThemeInfoRepresentation.java
new file mode 100644
index 0000000..4607045
--- /dev/null
+++ b/core/src/main/java/org/keycloak/representations/info/ThemeInfoRepresentation.java
@@ -0,0 +1,29 @@
+/*
+ */
+
+package org.keycloak.representations.info;
+
+/**
+ * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
+ */
+public class ThemeInfoRepresentation {
+
+    private String name;
+    private String[] locales;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String[] getLocales() {
+        return locales;
+    }
+
+    public void setLocales(String[] locales) {
+        this.locales = locales;
+    }
+}
diff --git a/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java b/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java
index cd288b7..35e1d56 100755
--- a/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java
+++ b/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java
@@ -1,5 +1,6 @@
 package org.keycloak.services.resources.admin.info;
 
+import java.io.IOException;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -10,6 +11,7 @@ import java.util.Map;
 import java.util.ServiceLoader;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 
 import org.keycloak.broker.provider.IdentityProvider;
@@ -109,13 +111,31 @@ public class ServerInfoAdminResource {
 
     private void setThemes(ServerInfoRepresentation info) {
         ThemeProvider themeProvider = session.getProvider(ThemeProvider.class, "extending");
-        info.setThemes(new HashMap<String, List<String>>());
+        info.setThemes(new HashMap<String, List<ThemeInfoRepresentation>>());
 
         for (Theme.Type type : Theme.Type.values()) {
-            List<String> themes = new LinkedList<String>(themeProvider.nameSet(type));
-            Collections.sort(themes);
+            List<String> themeNames = new LinkedList<>(themeProvider.nameSet(type));
+            Collections.sort(themeNames);
 
+            List<ThemeInfoRepresentation> themes = new LinkedList<>();
             info.getThemes().put(type.toString().toLowerCase(), themes);
+
+            for (String name : themeNames) {
+                try {
+                    Theme theme = themeProvider.getTheme(name, type);
+                    ThemeInfoRepresentation ti = new ThemeInfoRepresentation();
+                    ti.setName(name);
+
+                    String locales = theme.getProperties().getProperty("locales");
+                    if (locales != null) {
+                        ti.setLocales(locales.replaceAll(" ", "").split(","));
+                    }
+
+                    themes.add(ti);
+                } catch (IOException e) {
+                    throw new WebApplicationException("Failed to load themes", e);
+                }
+            }
         }
     }
 
diff --git a/themes/src/main/resources/META-INF/keycloak-themes.json b/themes/src/main/resources/META-INF/keycloak-themes.json
index 56322d3..12711ea 100755
--- a/themes/src/main/resources/META-INF/keycloak-themes.json
+++ b/themes/src/main/resources/META-INF/keycloak-themes.json
@@ -1,7 +1,7 @@
 {
     "themes": [{
         "name" : "base",
-        "types": [ "admin", "account", "login" ]
+        "types": [ "admin", "account", "login", "email" ]
     }, {
         "name" : "keycloak",
         "types": [ "admin", "account", "login", "common", "email", "welcome" ]
diff --git a/themes/src/main/resources/theme/base/account/theme.properties b/themes/src/main/resources/theme/base/account/theme.properties
new file mode 100644
index 0000000..29af932
--- /dev/null
+++ b/themes/src/main/resources/theme/base/account/theme.properties
@@ -0,0 +1 @@
+locales=ca,de,en,es,fr,it,pt_BR
\ No newline at end of file
diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js
index f58004d..f300616 100755
--- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js
+++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js
@@ -338,15 +338,55 @@ module.controller('RealmThemeCtrl', function($scope, Current, Realm, realm, serv
 
     $scope.supportedLocalesOptions = {
         'multiple' : true,
-        'simple_tags' : true,
-        'tags' : ['en', 'de', 'pt-BR', 'it', 'es', 'ca']
+        'simple_tags' : true
     };
 
-    $scope.$watch('realm.supportedLocales', function(oldVal, newVal) {
-        if ($scope.realm.defaultLocale && newVal && newVal.indexOf($scope.realm.defaultLocale) == -1) {
-            $scope.realm.defaultLocale = null;
+    function localeForTheme(type, name) {
+        name = name || 'base';
+        for (var i = 0; i < serverInfo.themes[type].length; i++) {
+            if (serverInfo.themes[type][i].name == name) {
+                return serverInfo.themes[type][i].locales;
+            }
         }
-    }, true);
+    }
+
+    function updateSupported() {
+        if ($scope.realm.internationalizationEnabled) {
+            var accountLocales = localeForTheme('account', $scope.realm.loginTheme);
+            var adminLocales = localeForTheme('admin', $scope.realm.loginTheme);
+            var loginLocales = localeForTheme('login', $scope.realm.loginTheme);
+            var emailLocales = localeForTheme('email', $scope.realm.loginTheme);
+
+            var supportedLocales = [];
+            for (var i = 0; i < accountLocales.length; i++) {
+                var l = accountLocales[i];
+                if (adminLocales.indexOf(l) >= 0 && loginLocales.indexOf(l) >= 0 && emailLocales.indexOf(l) >= 0) {
+                    supportedLocales.push(l);
+                }
+            }
+
+            $scope.supportedLocalesOptions.tags = supportedLocales;
+
+            if (!$scope.realm.supportedLocales) {
+                $scope.realm.supportedLocales = supportedLocales;
+            } else {
+                for (var i = 0; i < $scope.realm.supportedLocales.length; i++) {
+                    if ($scope.realm.supportedLocales.indexOf($scope.realm.supportedLocales[i]) == -1) {
+                        $scope.realm.supportedLocales = supportedLocales;
+                    }
+                }
+            }
+
+            if (!$scope.realm.defaultLocale || supportedLocales.indexOf($scope.realm.defaultLocale) == -1) {
+                $scope.realm.defaultLocale = 'en';
+            }
+        }
+    }
+
+    $scope.$watch('realm.loginTheme', updateSupported);
+    $scope.$watch('realm.accountTheme', updateSupported);
+    $scope.$watch('realm.emailTheme', updateSupported);
+    $scope.$watch('realm.internationalizationEnabled', updateSupported);
 });
 
 module.controller('RealmCacheCtrl', function($scope, realm, RealmClearUserCache, RealmClearRealmCache, Notifications) {
diff --git a/themes/src/main/resources/theme/base/admin/resources/partials/realm-theme-settings.html b/themes/src/main/resources/theme/base/admin/resources/partials/realm-theme-settings.html
index 0c36f93..2011c08 100755
--- a/themes/src/main/resources/theme/base/admin/resources/partials/realm-theme-settings.html
+++ b/themes/src/main/resources/theme/base/admin/resources/partials/realm-theme-settings.html
@@ -9,7 +9,7 @@
                     <div>
                         <select class="form-control" id="loginTheme"
                                 ng-model="realm.loginTheme"
-                                ng-options="o as o for o in serverInfo.themes.login">
+                                ng-options="o.name as o.name for o in serverInfo.themes.login">
                             <option value="" disabled selected>{{:: 'select-one' | translate}}</option>
                         </select>
                     </div>
@@ -22,7 +22,7 @@
                     <div>
                         <select class="form-control" id="accountTheme"
                                 ng-model="realm.accountTheme"
-                                ng-options="o as o for o in serverInfo.themes.account">
+                                ng-options="o.name as o.name for o in serverInfo.themes.account">
                             <option value="" disabled selected>{{:: 'select-one' | translate}}</option>
                         </select>
                     </div>
@@ -35,7 +35,7 @@
                     <div>
                         <select class="form-control" id="adminTheme"
                                 ng-model="realm.adminTheme"
-                                ng-options="o as o for o in serverInfo.themes.admin">
+                                ng-options="o.name as o.name for o in serverInfo.themes.admin">
                             <option value="" disabled selected>{{:: 'select-one' | translate}}</option>
                         </select>
                     </div>
@@ -48,7 +48,7 @@
                     <div>
                         <select class="form-control" id="emailTheme"
                                 ng-model="realm.emailTheme"
-                                ng-options="o as o for o in serverInfo.themes.email">
+                                ng-options="o.name as o.name for o in serverInfo.themes.email">
                             <option value="" disabled selected>{{:: 'select-one' | translate}}</option>
                         </select>
                     </div>
diff --git a/themes/src/main/resources/theme/base/admin/theme.properties b/themes/src/main/resources/theme/base/admin/theme.properties
index 5eb8ef9..9f605c7 100644
--- a/themes/src/main/resources/theme/base/admin/theme.properties
+++ b/themes/src/main/resources/theme/base/admin/theme.properties
@@ -1 +1,2 @@
-import=common/keycloak
\ No newline at end of file
+import=common/keycloak
+locales=ca,de,en,es,fr
\ No newline at end of file
diff --git a/themes/src/main/resources/theme/base/email/theme.properties b/themes/src/main/resources/theme/base/email/theme.properties
new file mode 100644
index 0000000..29af932
--- /dev/null
+++ b/themes/src/main/resources/theme/base/email/theme.properties
@@ -0,0 +1 @@
+locales=ca,de,en,es,fr,it,pt_BR
\ No newline at end of file
diff --git a/themes/src/main/resources/theme/base/login/theme.properties b/themes/src/main/resources/theme/base/login/theme.properties
new file mode 100644
index 0000000..29af932
--- /dev/null
+++ b/themes/src/main/resources/theme/base/login/theme.properties
@@ -0,0 +1 @@
+locales=ca,de,en,es,fr,it,pt_BR
\ No newline at end of file
diff --git a/themes/src/main/resources/theme/keycloak/email/theme.properties b/themes/src/main/resources/theme/keycloak/email/theme.properties
new file mode 100644
index 0000000..f1dbb72
--- /dev/null
+++ b/themes/src/main/resources/theme/keycloak/email/theme.properties
@@ -0,0 +1 @@
+parent=base
\ No newline at end of file