This repository has been archived by the owner on Jun 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beginning of Keycloak Server fraction.
Auto-config Datasources, Infinispan, and apply a keycloak-server.json Still needs significant improvement, but doesn't fail the build.
- Loading branch information
1 parent
ab6af82
commit ebdc37f
Showing
25 changed files
with
951 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
bootstrap/src/main/java/org/wildfly/swarm/bootstrap/modules/NestedJarResourceLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.wildfly.swarm.bootstrap.modules; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.Arrays; | ||
import java.util.Enumeration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.jar.JarEntry; | ||
import java.util.jar.JarFile; | ||
|
||
import org.jboss.modules.ResourceLoader; | ||
import org.jboss.modules.ResourceLoaders; | ||
|
||
/** | ||
* @author Bob McWhirter | ||
*/ | ||
public class NestedJarResourceLoader { | ||
|
||
private static Map<String, File> exploded = new HashMap<>(); | ||
|
||
public static ResourceLoader loaderFor(URL base, String rootPath, String loaderPath, String loaderName) throws IOException { | ||
|
||
//System.err.println( "** " + base + ", " + rootPath + ", " + loaderPath + ", " + loaderName ); | ||
|
||
if (base.toExternalForm().startsWith("jar:file:")) { | ||
int endLoc = base.toExternalForm().indexOf(".jar!"); | ||
if (endLoc > 0) { | ||
String jarPath = base.toExternalForm().substring(9, endLoc + 4); | ||
|
||
File exp = exploded.get(jarPath); | ||
|
||
if (exp == null) { | ||
exp = File.createTempFile("module-jar", ".jar_d"); | ||
exp.delete(); | ||
exp.mkdirs(); | ||
exp.deleteOnExit(); | ||
|
||
JarFile jarFile = new JarFile(jarPath); | ||
|
||
Enumeration<JarEntry> entries = jarFile.entries(); | ||
|
||
while (entries.hasMoreElements()) { | ||
JarEntry each = entries.nextElement(); | ||
|
||
if (!each.isDirectory()) { | ||
File out = new File(exp, each.getName()); | ||
out.getParentFile().mkdirs(); | ||
Files.copy(jarFile.getInputStream(each), out.toPath(), StandardCopyOption.REPLACE_EXISTING); | ||
} | ||
} | ||
} | ||
|
||
String relativeRoot = base.toExternalForm().substring(endLoc + 5); | ||
File resourceRoot = new File( new File( exp, relativeRoot ), loaderPath ); | ||
/* | ||
if ( resourceRoot.listFiles() != null ) { | ||
System.err.println("@ " + resourceRoot + " --> " + Arrays.asList(resourceRoot.listFiles())); | ||
} | ||
*/ | ||
return ResourceLoaders.createFileResourceLoader(loaderName, resourceRoot ); | ||
} | ||
} | ||
|
||
return ResourceLoaders.createFileResourceLoader(loaderPath, new File(rootPath)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2015 Red Hat, Inc. and/or its affiliates. | ||
~ | ||
~ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.wildfly.swarm</groupId> | ||
<artifactId>wildfly-swarm-keycloak-server-parent</artifactId> | ||
<version>1.0.0.Alpha6-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
|
||
<groupId>org.wildfly.swarm</groupId> | ||
<artifactId>wildfly-swarm-keycloak-server</artifactId> | ||
|
||
<name>WildFly Swarm: Keycloak Server API</name> | ||
<description>WildFly Swarm: Keycloak Server API</description> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.wildfly.swarm</groupId> | ||
<artifactId>wildfly-swarm-container</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wildfly.swarm</groupId> | ||
<artifactId>wildfly-swarm-keycloak-server-modules</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- Dependent APIs --> | ||
<dependency> | ||
<groupId>org.wildfly.swarm</groupId> | ||
<artifactId>wildfly-swarm-jaxrs</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wildfly.swarm</groupId> | ||
<artifactId>wildfly-swarm-infinispan</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wildfly.swarm</groupId> | ||
<artifactId>wildfly-swarm-datasources</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wildfly.swarm</groupId> | ||
<artifactId>wildfly-swarm-ee</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<!-- | ||
<dependency> | ||
<groupId>org.wildfly.swarm</groupId> | ||
<artifactId>wildfly-swarm-security</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
--> | ||
|
||
</dependencies> | ||
|
||
</project> |
98 changes: 98 additions & 0 deletions
98
...ak-server/api/src/main/java/org/wildfly/swarm/keycloak/server/KeycloakServerFraction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* Copyright 2015 Red Hat, Inc, and individual contributors. | ||
* | ||
* 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 org.wildfly.swarm.keycloak.server; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.wildfly.swarm.config.datasources.DataSource; | ||
import org.wildfly.swarm.config.infinispan.CacheContainer; | ||
import org.wildfly.swarm.config.infinispan.cache_container.LocalCache; | ||
import org.wildfly.swarm.container.Container; | ||
import org.wildfly.swarm.container.Fraction; | ||
import org.wildfly.swarm.datasources.DatasourcesFraction; | ||
import org.wildfly.swarm.ee.EEFraction; | ||
import org.wildfly.swarm.infinispan.InfinispanFraction; | ||
|
||
/** | ||
* @author Bob McWhirter | ||
*/ | ||
public class KeycloakServerFraction implements Fraction { | ||
|
||
public KeycloakServerFraction() { | ||
} | ||
|
||
@Override | ||
public void postInitialize(Container.PostInitContext initContext) { | ||
|
||
if (System.getProperty("jboss.server.config.dir") == null) { | ||
try { | ||
Path dir = Files.createTempDirectory("swarm-keycloak-config"); | ||
System.setProperty("jboss.server.config.dir", dir.toString() ); | ||
Files.copy( getClass().getClassLoader().getResourceAsStream( "keycloak-server.json"), | ||
dir.resolve( "keycloak-server.json" ), | ||
StandardCopyOption.REPLACE_EXISTING); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
InfinispanFraction infinispan = (InfinispanFraction) initContext.fraction("infinispan"); | ||
|
||
CacheContainer cache = infinispan.subresources().cacheContainer("keycloak"); | ||
if (cache == null) { | ||
infinispan.cacheContainer("keycloak", (c) -> { | ||
c.jndiName("infinispan/Keycloak"); | ||
c.localCache("realms", KeycloakServerFraction::configureCache); | ||
c.localCache("users", KeycloakServerFraction::configureCache); | ||
c.localCache("sessions", KeycloakServerFraction::configureCache); | ||
c.localCache("loginFailures", KeycloakServerFraction::configureCache); | ||
}); | ||
} | ||
|
||
DatasourcesFraction datasources = (DatasourcesFraction) initContext.fraction("datasources"); | ||
|
||
if (datasources.subresources().dataSource("KeycloakDS") == null) { | ||
if (datasources.subresources().jdbcDriver("h2") == null) { | ||
datasources.jdbcDriver("h2", (driver) -> { | ||
driver.driverModuleName("com.h2database.h2"); | ||
driver.moduleSlot("main"); | ||
driver.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource"); | ||
}); | ||
} | ||
datasources.dataSource("KeycloakDS", (ds) -> { | ||
ds.jndiName("java:jboss/datasources/KeycloakDS"); | ||
ds.useJavaContext(true); | ||
ds.connectionUrl("jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE"); | ||
ds.driverName("h2"); | ||
ds.userName("sa"); | ||
ds.password("sa"); | ||
}); | ||
} | ||
} | ||
|
||
private static void configureCache(LocalCache c) { | ||
c.transactionComponent(); | ||
c.evictionComponent(); | ||
c.lockingComponent(); | ||
c.expirationComponent(); | ||
c.noneStore(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../src/main/java/org/wildfly/swarm/keycloak/server/KeycloakServerRuntimeModuleProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2015 Red Hat, Inc, and individual contributors. | ||
* | ||
* 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 org.wildfly.swarm.keycloak.server; | ||
|
||
import org.wildfly.swarm.container.RuntimeModuleProvider; | ||
|
||
/** | ||
* @author Bob McWhirter | ||
*/ | ||
public class KeycloakServerRuntimeModuleProvider implements RuntimeModuleProvider { | ||
@Override | ||
public String getModuleName() { | ||
return "org.wildfly.swarm.keycloak.server"; | ||
} | ||
|
||
@Override | ||
public String getSlotName() { | ||
return "runtime"; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...pi/src/main/resources/META-INF/services/org.wildfly.swarm.container.RuntimeModuleProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.wildfly.swarm.keycloak.server.KeycloakServerRuntimeModuleProvider |
Oops, something went wrong.