use of org.keycloak.representations.provider.ScriptProviderDescriptor in project keycloak by keycloak.
the class DeployedScriptAuthenticatorTest method deploy.
@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = false, testable = false)
@TargetsContainer(AUTH_SERVER_CURRENT)
public static JavaArchive deploy() throws IOException {
ScriptProviderDescriptor representation = new ScriptProviderDescriptor();
representation.addAuthenticator("My Authenticator", "authenticator-a.js");
return ShrinkWrap.create(JavaArchive.class, SCRIPT_DEPLOYMENT_NAME).addAsManifestResource(new StringAsset(JsonSerialization.writeValueAsPrettyString(representation)), "keycloak-scripts.json").addAsResource("scripts/authenticator-example.js", "authenticator-a.js");
}
use of org.keycloak.representations.provider.ScriptProviderDescriptor 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.ScriptProviderDescriptor in project keycloak by keycloak.
the class DeployedScriptPolicyTest method deploy.
@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = false, testable = false)
@TargetsContainer(AUTH_SERVER_CURRENT)
public static JavaArchive deploy() throws IOException {
ScriptProviderDescriptor representation = new ScriptProviderDescriptor();
representation.addPolicy("Grant Policy", "policy-grant.js");
representation.addPolicy("Deny Policy", "policy-deny.js");
return ShrinkWrap.create(JavaArchive.class, SCRIPT_DEPLOYMENT_NAME).addAsManifestResource(new StringAsset(JsonSerialization.writeValueAsPrettyString(representation)), "keycloak-scripts.json").addAsResource(new StringAsset("$evaluation.grant();"), "policy-grant.js").addAsResource(new StringAsset("$evaluation.deny();"), "policy-deny.js");
}
use of org.keycloak.representations.provider.ScriptProviderDescriptor in project keycloak by keycloak.
the class DeployedScriptMapperTest method deploy.
@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = false, testable = false)
@TargetsContainer(AUTH_SERVER_CURRENT)
public static JavaArchive deploy() throws IOException {
ScriptProviderDescriptor representation = new ScriptProviderDescriptor();
representation.addMapper("My Mapper", "mapper-a.js");
return ShrinkWrap.create(JavaArchive.class, SCRIPT_DEPLOYMENT_NAME).addAsManifestResource(new StringAsset(JsonSerialization.writeValueAsPrettyString(representation)), "keycloak-scripts.json").addAsResource("scripts/mapper-example.js", "mapper-a.js");
}
use of org.keycloak.representations.provider.ScriptProviderDescriptor in project keycloak by keycloak.
the class UndeployedScriptMapperNotAvailableTest method deploy.
@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = false, testable = false)
@TargetsContainer(AUTH_SERVER_CURRENT)
public static JavaArchive deploy() throws IOException {
ScriptProviderDescriptor representation = new ScriptProviderDescriptor();
representation.addMapper("My Mapper", "mapper-a.js");
return ShrinkWrap.create(JavaArchive.class, SCRIPT_DEPLOYMENT_NAME).addAsManifestResource(new StringAsset(JsonSerialization.writeValueAsPrettyString(representation)), "keycloak-scripts.json").addAsResource("scripts/mapper-example.js", "mapper-a.js");
}
Aggregations