Search in sources :

Example 1 with ScriptProviderDescriptor

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");
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) ScriptProviderDescriptor(org.keycloak.representations.provider.ScriptProviderDescriptor) Deployment(org.jboss.arquillian.container.test.api.Deployment) TargetsContainer(org.jboss.arquillian.container.test.api.TargetsContainer)

Example 2 with ScriptProviderDescriptor

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);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ScriptProviderMetadata(org.keycloak.representations.provider.ScriptProviderMetadata) InputStream(java.io.InputStream) ScriptProviderDescriptor(org.keycloak.representations.provider.ScriptProviderDescriptor) List(java.util.List) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ScriptProviderDescriptor

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");
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) ScriptProviderDescriptor(org.keycloak.representations.provider.ScriptProviderDescriptor) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment) TargetsContainer(org.jboss.arquillian.container.test.api.TargetsContainer)

Example 4 with ScriptProviderDescriptor

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");
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) ScriptProviderDescriptor(org.keycloak.representations.provider.ScriptProviderDescriptor) Deployment(org.jboss.arquillian.container.test.api.Deployment) TargetsContainer(org.jboss.arquillian.container.test.api.TargetsContainer)

Example 5 with ScriptProviderDescriptor

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");
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) ScriptProviderDescriptor(org.keycloak.representations.provider.ScriptProviderDescriptor) Deployment(org.jboss.arquillian.container.test.api.Deployment) TargetsContainer(org.jboss.arquillian.container.test.api.TargetsContainer)

Aggregations

ScriptProviderDescriptor (org.keycloak.representations.provider.ScriptProviderDescriptor)6 Deployment (org.jboss.arquillian.container.test.api.Deployment)4 TargetsContainer (org.jboss.arquillian.container.test.api.TargetsContainer)4 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ScriptProviderMetadata (org.keycloak.representations.provider.ScriptProviderMetadata)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)1 VirtualFile (org.jboss.vfs.VirtualFile)1 DefaultJpaConnectionProviderFactory (org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory)1 LiquibaseJpaUpdaterProviderFactory (org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProviderFactory)1 EnvironmentDependentProviderFactory (org.keycloak.provider.EnvironmentDependentProviderFactory)1