【问题标题】:How to add OpenApi/Swagger securitySchemes in Apache Camels RouteBuilder.restConfiguration()?如何在 Apache Camels RouteBuilder.restConfiguration() 中添加 OpenApi/Swagger securitySchemes?
【发布时间】:2022-01-17 20:20:31
【问题描述】:

我尝试添加springdoc-openapi-uicamel-springdoc-starter。效果还不错。
现在我在上下文路径 '/camel' 和缺少的 securitySchemes 上遇到了麻烦。
有谁知道如何做到这一点

我如何获得这样的配置?

{
    "openapi": "3.0.1",
    "info": {
        "title": "some title",
        "version": "0.8.15-SNAPSHOT"
    },
    "servers": [
        {
            "url": "http://localhost"
        }
    ],
    "security": [
        {
            "Keycloak": []
        }
    ],
    "components": {
        "schemas": {
            ...
        },
        "securitySchemes": {
            "Keycloak": {
                "type": "oauth2",
                "name": "Keycloak",
                "flows": {
                    "password": {
                        "tokenUrl": "http://localhost:8080/auth/realms/sample-app/protocol/openid-connect/token",
                        "scopes": {
                            "email": "",
                            "profile": ""
                        }
                    }
                }
            }
        }
    }
}

使用这样的东西:

@Override
public void configure() {
    restConfiguration()     
            .component("servlet")
            .apiProperty("api.title", "RDF-Pub Server")
            .apiProperty("api.version", appVersion)
            .apiProperty("api.components.securitySchemes.Keycloak.type", "oauth2")
            .apiProperty("api.components.securitySchemes.Keycloak.name", "Keycloak")
            .apiProperty("api.components.securitySchemes.Keycloak.flows.password.tokenUrl", "http://localhost:8080/auth/realms/example-app/protocol/openid-connect/token")
            .apiProperty("api.components.securitySchemes.Keycloak.flows.password.scopes.email", "")
            .apiProperty("api.components.securitySchemes.Keycloak.flows.password.scopes.profile", "");
}

【问题讨论】:

    标签: spring-boot apache-camel swagger openapi springdoc-ui


    【解决方案1】:

    这样找到的:

    private void routeCollection() {
        rest()
            .securityDefinitions()
                .oauth2("local_keycloak", "Using a local keycloak instance")                
                    .password("http://localhost:8080/auth/realms/sample-app/protocol/openid-connect/token")
                    .withScope("email", "accessing the email address")
                    .withScope("profile", "accessing the profile")
                    .end()              
                .end()
            .get("/{owner}/{collection}")       
            .route()
            .routeId("readCollection")
            .process("processorA")
            .process("processorB")
            .endRest();
    }
    

    我在一个方法中提取了这些东西:

    private RestDefinition oauth2Rest() {
        return rest()
            .securityDefinitions()
                .oauth2("local_keycloak", "Using a local keycloak instance")                
                    .password("http://localhost:8080/auth/realms/sample-app/protocol/openid-connect/token")
                    .withScope("email", "accessing the email address")
                    .withScope("profile", "accessing the profile")
                    .end()              
                .end();
    }
    

    并在配置中调用一次:

    @Override
    public void configure() {
                
        oauth2Rest();
        // it tells Camel how to configure the REST service
        restConfiguration()
        ...
    

    结果:

    【讨论】:

      猜你喜欢
      • 2020-04-25
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-05
      • 2015-02-20
      • 1970-01-01
      相关资源
      最近更新 更多