0

我尝试添加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", "");
}
4

1 回答 1

0

found that way:

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();
}

I extracted the stuff in a method:

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();
}

and called it once in the configuration:

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

Result:

enter image description here

于 2021-12-14T17:11:44.260 回答