You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Keycloak 21.1.1自定义端点异常求助,附示例项目

Keycloak 21.1.1 自定义端点问题排查请求

我在Keycloak 21.1.1版本中添加了一个自定义测试端点,项目内的问题描述、Keycloak日志文件及错误位置文件均存放于项目的custom_endpoint/options/1路径下。请帮忙排查问题,谢谢!

以下是我的Java端点类代码:

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.ext.Provider;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.jboss.logging.Logger;
import org.keycloak.models.KeycloakSession;
import org.keycloak.services.resource.RealmResourceProvider;

//参考示例项目实现
@Provider
@javax.ws.rs.Path("/")
public class CustomEndpointResource implements RealmResourceProvider {

    private static final Logger logger = Logger.getLogger(CustomEndpointResource.class);

    private final KeycloakSession session;

    public CustomEndpointResource(KeycloakSession session) {
        this.session = session;
    }

    @javax.ws.rs.Path("custom")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Operation(
            summary = "Public hello endpoint",
            description = "This endpoint returns hello and the name of the requested realm."
    )
    @APIResponse(
            responseCode = "200",
            description = "",
            content = {@Content(
                    schema = @Schema(
                            implementation = String.class,
                            type = SchemaType.STRING
                    )
            )}
    )
    public String customTest() {
        logger.info("called custom endpoint!");
        return "Test!";
    }

    @Override
    public Object getResource() {
        logger.info("CUSTOM RealmResourceProvider.getResource");
        return this;
    }

    @Override
    public void close() {
        logger.info("CUSTOM RealmResourceProvider.close");
    }
}

内容的提问来源于stack exchange,提问作者JDev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 15:43:15