Initial sources

This commit is contained in:
2025-06-27 12:16:40 +02:00
parent f29fcf446c
commit e07d758f50
12 changed files with 545 additions and 1 deletions

View File

@ -0,0 +1,74 @@
/**
* Copyright (C) 2025 John Ahlroos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.devsoap.keycloak;
import java.io.IOException;
import java.io.InputStream;
import org.jboss.logging.Logger;
import org.keycloak.Config.Scope;
import org.keycloak.theme.ClasspathThemeResourceProviderFactory;
/**
* Provider that provides access to webjar static resource for Keycloak themes
*
* @author John Ahlroos / devsoap.com
* @version Unversioned
*
* <p>
* How to use:
* <ul>
* <li>Download the Webjar from the internet and place the JAR in the Keycloak <code>/opt/keycloak/providers</code> folder</li>
* <li>Easiest way to download is to use Gradle/Maven (See build.gradle composeProviders task in this project)</li>
* <li>
* In your Keycloak theme add a reference to the css and script files you want to include:
* <pre>
* //theme.properties
* styles=webjars/uikit/3.17.9/css/uikit.min.css
* scripts=webjars/htmx.org/1.9.2/dist/htmx.min.js
* </pre>
* </li>
* </ul>
* </p>
*/
public class WebjarThemeResourceProviderFactory extends ClasspathThemeResourceProviderFactory {
private final Logger LOGGER = Logger.getLogger(WebjarThemeResourceProviderFactory.class);
public WebjarThemeResourceProviderFactory() {
super("webjar", Thread.currentThread().getContextClassLoader());
}
@Override
public void init(Scope config) {
super.init(config);
try {
var webjars = classLoader.getResources("META-INF/resources/webjars/");
while (webjars.hasMoreElements()) {
LOGGER.debugf("Webjar: %s", webjars.nextElement());
}
} catch (IOException e) {
LOGGER.warn("Failed to resolve webjars", e);
}
}
@Override
public InputStream getResourceAsStream(String path) {
if (path != null && path.startsWith("webjars")) {
return classLoader.getResourceAsStream("META-INF/resources/" + path);
}
return null;
}
}

View File

@ -0,0 +1 @@
com.devsoap.keycloak.WebjarThemeResourceProviderFactory