我是Keycloak(6.0.1)的几个自定义SPI,还需要创建一个自定义操作令牌,该令牌将发送给用户。
我已经创建了一个自定义事件侦听器,电子邮件发件人,必需的操作,并将所有这些部署在一个jar中。
当我尝试将动作令牌处理程序与正确的清单条目一起放置时,我会得到
Caused by: java.lang.NoClassDefFoundError: Failed to link com/mycompany/providers/registration/actiontoken/Invitati
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1095)
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:424)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:555)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:339)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:126)
at org.jboss.modules.Module.loadModuleClass(Module.java:731)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:247)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1209)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1220)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1264)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1299)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1384)
at org.keycloak.keycloak-services@6.0.1//org.keycloak.provider.DefaultProviderLoader.load(DefaultProviderLoader.java:60)
处理程序的定义
package com.mycompany.providers.registration.actiontoken;
import org.keycloak.TokenVerifier;
import
org.keycloak.authentication.actiontoken.AbstractActionTokenHander;
import org.keycloak.authentication.actiontoken.ActionTokenContext;
import org.keycloak.authentication.actiontoken.TokenUtils;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventType;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.sessions.AuthenticationSessionModel;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
public class InvitationActionTokenHandler extends AbstractActionTokenHander<InvitationActionToken> {
public InvitationActionTokenHandler(String id, Class<InvitationActionToken> tokenClass, String defaultErrorMessage, EventType defaultEventType, String defaultEventError) {
super(id, tokenClass, defaultErrorMessage, defaultEventType, defaultEventError);
}
@Override
public Response handleToken(InvitationActionToken invitationActionToken, ActionTokenContext<InvitationActionToken> tokenContext) {
AuthenticationSessionModel authSession = tokenContext.getAuthenticationSession();
final UriInfo uriInfo = tokenContext.getUriInfo();
final RealmModel realm = tokenContext.getRealm();
EventBuilder event = tokenContext.getEvent();
final KeycloakSession session = tokenContext.getSession();
String nextAction = AuthenticationManager.nextRequiredAction(session, authSession, tokenContext.getClientConnection(), tokenContext.getRequest(), uriInfo, event);
return AuthenticationManager.redirectToRequiredActions(session, realm, authSession, uriInfo, nextAction);
}
@Override
public TokenVerifier.Predicate<? super InvitationActionToken>[] getVerifiers(ActionTokenContext<InvitationActionToken> tokenContext) {
return TokenUtils.predicates(
);
}
}
文件META-INF/services/org.keycloak.authentication.actiontoken.ActionTokenHandlerFactory
中的清单
com.mycompany.providers.registration.actiontoken.InvitationActionTokenHandler
我已经添加了Keycloak的所有依赖项
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
dependencies {
compileOnly group: 'org.keycloak', name: 'keycloak-model-jpa', version: '6.0.1'
compileOnly group: 'org.keycloak', name: 'keycloak-services', version: '6.0.1'
compileOnly group: 'org.keycloak', name: 'keycloak-server-spi', version: '6.0.1'
compileOnly group: 'org.keycloak', name: 'keycloak-server-spi-private', version: '6.0.1'
compileOnly group: 'org.keycloak', name: 'keycloak-core', version: '6.0.1'
compileOnly group: 'org.keycloak', name: 'keycloak-common', version: '6.0.1'
编辑:更新
所以我指出了类ActionTokenHandler在类路径中不可用,已在已经运行的SPI中使用此代码段进行了验证
try {
Class cls = Class.forName("org.keycloak.authentication.actiontoken.ActionTokenHandler");
} catch (ClassNotFoundException e) {
//is thrown always
e.printStackTrace();
}
我已将gradle依赖项更改为compileOnly,以确保不会发生类路径问题
答案 0 :(得分:3)
您必须提供应用程序服务器的程序包依赖关系列表。使用以下内容在jboss-deployment-structure.xml
目录中创建src/main/resources/META-INF
:
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.keycloak.keycloak-core" />
<module name="org.keycloak.keycloak-server-spi" />
<module name="org.keycloak.keycloak-server-spi-private" />
<module name="org.keycloak.keycloak-services" />
<module name="org.keycloak.keycloak-common" />
<module name="org.keycloak.keycloak-model-jpa" />
</dependencies>
</deployment>
</jboss-deployment-structure>