use of org.keycloak.theme.Theme in project keycloak by keycloak.
the class AdminRoot method getMessages.
public static Properties getMessages(KeycloakSession session, RealmModel realm, String lang) {
try {
Theme theme = getTheme(session, realm);
Locale locale = lang != null ? Locale.forLanguageTag(lang) : Locale.ENGLISH;
return theme.getMessages(locale);
} catch (IOException e) {
logger.error("Failed to load messages from theme", e);
return new Properties();
}
}
use of org.keycloak.theme.Theme in project keycloak by keycloak.
the class KeycloakErrorHandler method toResponse.
@Override
public Response toResponse(Throwable throwable) {
KeycloakSession session = Resteasy.getContextData(KeycloakSession.class);
KeycloakTransaction tx = session.getTransactionManager();
tx.setRollbackOnly();
int statusCode = getStatusCode(throwable);
if (statusCode >= 500 && statusCode <= 599) {
logger.error(UNCAUGHT_SERVER_ERROR_TEXT, throwable);
} else {
logger.debugv(throwable, ERROR_RESPONSE_TEXT, statusCode);
}
if (!MediaTypeMatcher.isHtmlRequest(headers)) {
OAuth2ErrorRepresentation error = new OAuth2ErrorRepresentation();
error.setError(getErrorCode(throwable));
return Response.status(statusCode).header(HttpHeaders.CONTENT_TYPE, javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE.toString()).entity(error).build();
}
try {
RealmModel realm = resolveRealm(session);
Theme theme = session.theme().getTheme(Theme.Type.LOGIN);
Locale locale = session.getContext().resolveLocale(null);
FreeMarkerUtil freeMarker = new FreeMarkerUtil();
Map<String, Object> attributes = initAttributes(session, realm, theme, locale, statusCode);
String templateName = "error.ftl";
String content = freeMarker.processTemplate(attributes, templateName, theme);
return Response.status(statusCode).type(MediaType.TEXT_HTML_UTF_8_TYPE).entity(content).build();
} catch (Throwable t) {
logger.error("Failed to create error page", t);
return Response.serverError().build();
}
}
use of org.keycloak.theme.Theme in project keycloak by keycloak.
the class ThemeResourceProviderTest method getResourceIllegalTraversal.
@Test
public void getResourceIllegalTraversal() {
testingClient.server().run(session -> {
try {
Theme theme = session.theme().getTheme("base", Theme.Type.LOGIN);
Assert.assertNull(theme.getResourceAsStream("../templates/test.ftl"));
} catch (IOException e) {
Assert.fail(e.getMessage());
}
});
}
use of org.keycloak.theme.Theme in project keycloak by keycloak.
the class ThemeResourceProviderTest method getMessages.
@Test
public void getMessages() {
testingClient.server().run(session -> {
try {
Theme theme = session.theme().getTheme("base", Theme.Type.LOGIN);
Assert.assertNotNull(theme.getMessages("messages", Locale.ENGLISH).get("test.keycloak-8818"));
Assert.assertNotEquals("Full name (Theme-resources)", theme.getMessages("messages", Locale.ENGLISH).get("fullName"));
} catch (IOException e) {
Assert.fail(e.getMessage());
}
});
}
use of org.keycloak.theme.Theme in project keycloak by keycloak.
the class DefaultThemeManagerTest method systemPropertiesSubstitutionInThemeProperties.
// KEYCLOAK-6698
@Test
public void systemPropertiesSubstitutionInThemeProperties() {
testingClient.server().run(session -> {
try {
Theme theme = session.theme().getTheme(THEME_NAME, Theme.Type.LOGIN);
Assert.assertEquals("getTheme(...) returns default theme when no matching theme found, but we need " + THEME_NAME + " theme deployed.", THEME_NAME, theme.getName());
Assert.assertEquals("Keycloak is awesome", theme.getProperties().getProperty("system.property.found"));
Assert.assertEquals("${missing_system_property}", theme.getProperties().getProperty("system.property.missing"));
Assert.assertEquals("defaultValue", theme.getProperties().getProperty("system.property.missing.with.default"));
} catch (IOException e) {
Assert.fail(e.getMessage());
}
});
}
Aggregations