Skip to content

Commit

Permalink
Applied the eosc-kc/keycloak#129
Browse files Browse the repository at this point in the history
  • Loading branch information
laskasn committed Oct 15, 2021
1 parent 7ea955f commit 3dd451e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
32 changes: 32 additions & 0 deletions src/main/java/org/eosc/kc/resolver/ThemeConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.eosc.kc.resolver;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
* This class loads additional configuration for different projects (i.e. different icons, different header and footer captions, etc.)
*/
public class ThemeConfig {

private Map<String, String> config;

public ThemeConfig() throws IOException {
InputStream is = getClass().getClassLoader().getResourceAsStream("configuration.json");
config = new ObjectMapper().readValue(is, new TypeReference<HashMap<String, String>>() {});
}

public String get(String configParam){
return config.get(configParam);
}

public Map<String, String> getConfig() {
return config;
}

}

14 changes: 13 additions & 1 deletion src/main/java/org/eosc/kc/rest/ThemeResourceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.eosc.kc.rest;

import org.eosc.kc.resolver.ThemeConfig;
import org.keycloak.authentication.authenticators.broker.util.SerializedBrokeredIdentityContext;
import org.keycloak.forms.login.freemarker.model.IdentityProviderBean;
import org.keycloak.models.IdentityProviderModel;
Expand All @@ -37,6 +38,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -49,9 +51,12 @@
public class ThemeResourceProvider implements RealmResourceProvider {

private KeycloakSession session;
private static ThemeConfig themeConfig;

public ThemeResourceProvider(KeycloakSession session) {
public ThemeResourceProvider(KeycloakSession session) throws IOException {
this.session = session;
if(themeConfig==null)
themeConfig = new ThemeConfig();
}

@Override
Expand All @@ -64,6 +69,13 @@ public void close() {
}


@GET
@Path("/theme-config")
@Produces(MediaType.APPLICATION_JSON )
public Map<String,String> getThemeConfig(){
return themeConfig.getConfig();
}


/**
* This should be used from login pages to show all available identity providers of the realm for logging in.
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"projectLogoIconUrl": "../img/keycloak-logo-text.png"
}
13 changes: 13 additions & 0 deletions src/main/resources/theme/eosc-kc/login/login.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,24 @@
);
}
function getConfigAndApply() {
$http({method: 'GET', url: baseUri + 'realms/' + realm + '/theme-info/theme-config' })
.then(
function(success) {
var projectLogoIconUrl = success.data['projectLogoIconUrl'];
var r = document.querySelector(':root');
r.style.setProperty('--logo-image', 'url(projectLogoIconUrl)');
},
function(error){
}
);
}
getIdps();
getPromotedIdps();
getConfigAndApply();
$scope.scrollCallback = function ($event, $direct) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/resources/theme/eosc-kc/login/resources/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
}

div.kc-logo-text {
background-image: url(https://synthesys.rciam.grnet.gr/proxy/module.php/themevanilla/resources/images/logo.png);
height: 80px;
width: 380px;
background-image: var(--logo-image);
height: 100px;
width: 210px;
}

.login-pf body {
background: whitesmoke !important;
}

:root {
--logo-image: url('');
}

0 comments on commit 3dd451e

Please sign in to comment.