Keycloak - 自定义 SPI 未出现在列表中

我为我的 keycloak 服务器制作了一个自定义 SPI,现在我必须在管理控制台上配置它。

我将 SPI 添加为模块,并手动安装,因此我将其放在 module/{package-name}/main 中,并包含 module.xml;我还将其放在standalone.xml 中,并将其放在keycloak-server 子系统中。

完成所有这些配置后,我转到管理控制台来配置自定义用户提供程序,但它没有出现在列表中。

我能做些什么?


哈士奇WWW
浏览 102回答 3
3回答

慕码人8056858

找到了一种方法,就是在里面添加文件classpath:${jboss.home.dir}/providers/,因为那里找到的SPI内部模块是由Keycloak解释的。

蓝山帝景

我的最终解决方案是应用来自的示例https://github.com/thomasdarimont/keycloak-user-storage-provider-demo并更改 EntityManager 的 UserRepository 以连接数据库。

慕的地8271018

考虑将 SPI 实现部署为 JAR 或 EAR。当我想将它们部署到 keycloak 作为 JBoss 模块时,我也遇到了一些麻烦,但我不记得具体是什么(在我的公司,我们使用自定义 SPI 实现大量定制了 Keycloak,包括 Authenticators、UserStorageProvider、REST 端点、OIDC 映射器。 ..)。现在我们将它们部署为 EAR 包。以下是使用 Maven 执行 EAR 打包的方法:<name>Keycloak Extensions EAR</name><artifactId>cardpay-extensions</artifactId><packaging>ear</packaging><properties>&nbsp; &nbsp; ...</properties><dependencies>&nbsp; &nbsp; <!-- Your jars with provider implementations, I'm use two jars (for unit testing simplicity) -->&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.acme</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>extensions-core</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>${project.version}</version>&nbsp; &nbsp; &nbsp; &nbsp; <type>jar</type>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.acme</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>extensions-providers</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>${project.version}</version>&nbsp; &nbsp; &nbsp; &nbsp; <type>ejb</type>&nbsp; &nbsp; </dependency></dependencies><build>&nbsp; &nbsp; <finalName>${project.artifactId}</finalName>&nbsp; &nbsp; <plugins>&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-ear-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>3.0.1</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>8</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <defaultLibBundleDir>lib</defaultLibBundleDir>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <outputFileNameMapping>@{artifactId}@.@{extension}@</outputFileNameMapping>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; </plugins></build>不要忘记添加main/application/META-INF/jboss-deployment-structure.xml如下内容:<?xml version="1.0" ?><jboss-deployment-structure><!-- Core module --><module name="deployment.extensions.core">&nbsp; &nbsp; <resources>&nbsp; &nbsp; &nbsp; &nbsp; <resource-root path="lib/core.jar"/>&nbsp; &nbsp; </resources>&nbsp; &nbsp; <dependencies>&nbsp; &nbsp; &nbsp; &nbsp; <module name="com.oracle.ojdbc" export="true"/>&nbsp; &nbsp; &nbsp; &nbsp; <module name="org.jboss.logging" export="true"/>&nbsp; &nbsp; &nbsp; &nbsp; <module name="org.apache.commons.io" export="true"/>&nbsp; &nbsp; &nbsp; &nbsp; <module name="javax.ws.rs.api" export="true"/>&nbsp; &nbsp; &nbsp; &nbsp; <module name="org.keycloak.keycloak-common" export="true"/>&nbsp; &nbsp; &nbsp; &nbsp; <module name="org.keycloak.keycloak-core" export="true"/>&nbsp; &nbsp; &nbsp; &nbsp; <module name="org.keycloak.keycloak-server-spi" export="true"/>&nbsp; &nbsp; &nbsp; &nbsp; <module name="org.keycloak.keycloak-server-spi-private" export="true"/>&nbsp; &nbsp; &nbsp; &nbsp; <module name="org.keycloak.keycloak-services" export="true"/>&nbsp; &nbsp; </dependencies></module><!-- Define dependency on core module for all sub-deployments --><deployment>&nbsp; &nbsp; <dependencies>&nbsp; &nbsp; &nbsp; &nbsp; <module name="deployment.extensions.core" export="true"/>&nbsp; &nbsp; </dependencies></deployment><!-- Providers bundle --><sub-deployment name="providers.jar">&nbsp; &nbsp; <dependencies>&nbsp; &nbsp; &nbsp; &nbsp; <module name="javax.api"/>&nbsp; &nbsp; </dependencies></sub-deployment></jboss-deployment-structure>现在,您可以使用 maven-wildfly-plugin 进行 mvn wildfly:deploy 或通过 JBoss cli 或部署扫描器手动部署 Ear(查看 Wildfly 工件部署文档)。您应该在 Wildfly 日志中看到有关扩展部署的相应消息(会有 ProviderFactory id)关于使用模块时 SPI 实现不可用,我猜这是因为 JBoss 模块加载得太早,所以 Keycloak 部署程序子系统看不到它们。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java