use of org.keycloak.representations.provider.ScriptProviderMetadata in project keycloak by keycloak.
the class ScriptProviderDeploymentProcessor method deploy.
static void deploy(DeploymentUnit deploymentUnit, KeycloakDeploymentInfo info) {
ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
if (resourceRoot == null) {
return;
}
VirtualFile jarFile = resourceRoot.getRoot();
if (jarFile == null || !jarFile.exists() || !jarFile.getName().endsWith(".jar")) {
return;
}
ScriptProviderDescriptor descriptor = readScriptProviderDescriptor(jarFile);
if (descriptor == null) {
return;
}
for (Map.Entry<String, List<ScriptProviderMetadata>> entry : descriptor.getProviders().entrySet()) {
for (ScriptProviderMetadata metadata : entry.getValue()) {
String fileName = metadata.getFileName();
if (fileName == null) {
throw new RuntimeException("You must provide the script file name");
}
try (InputStream in = jarFile.getChild(fileName).openStream()) {
metadata.setCode(StreamUtil.readString(in, StandardCharsets.UTF_8));
} catch (IOException cause) {
throw new RuntimeException("Failed to read script file [" + fileName + "]", cause);
}
metadata.setId(new StringBuilder("script").append("-").append(fileName).toString());
String name = metadata.getName();
if (name == null) {
name = fileName;
}
metadata.setName(name);
PROVIDERS.get(entry.getKey()).accept(info, metadata);
}
}
}
use of org.keycloak.representations.provider.ScriptProviderMetadata in project keycloak by keycloak.
the class KeycloakProcessor method loadDeployedScriptProviders.
private Map<String, ProviderFactory> loadDeployedScriptProviders(ClassLoader classLoader, Spi spi) {
Map<String, ProviderFactory> providers = new HashMap<>();
if (supportsDeployeableScripts(spi)) {
try {
Enumeration<URL> urls = classLoader.getResources(KEYCLOAK_SCRIPTS_JSON_PATH);
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
int fileSeparator = url.getFile().indexOf(JAR_FILE_SEPARATOR);
if (fileSeparator != -1) {
JarFile jarFile = new JarFile(url.getFile().substring("file:".length(), fileSeparator));
JarEntry descriptorEntry = jarFile.getJarEntry(KEYCLOAK_SCRIPTS_JSON_PATH);
ScriptProviderDescriptor descriptor;
try (InputStream is = jarFile.getInputStream(descriptorEntry)) {
descriptor = JsonSerialization.readValue(is, ScriptProviderDescriptor.class);
}
for (Entry<String, List<ScriptProviderMetadata>> entry : descriptor.getProviders().entrySet()) {
if (isScriptForSpi(spi, entry.getKey())) {
for (ScriptProviderMetadata metadata : entry.getValue()) {
ProviderFactory provider = createDeployableScriptProvider(jarFile, entry, metadata);
providers.put(metadata.getId(), provider);
}
}
}
}
}
} catch (IOException e) {
throw new RuntimeException("Failed to discover script providers", e);
}
}
return providers;
}
Aggregations