如何在 Apache Camels RouteBuilder.restConfiguration() 中添加 OpenApi/Swagger securitySchemes?
Posted
技术标签:
【中文标题】如何在 Apache Camels RouteBuilder.restConfiguration() 中添加 OpenApi/Swagger securitySchemes?【英文标题】:How to add OpenApi/Swagger securitySchemes in Apache Camels RouteBuilder.restConfiguration()? 【发布时间】:2022-01-17 20:20:31 【问题描述】:我尝试添加springdoc-openapi-ui
和camel-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", "");
【问题讨论】:
【参考方案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()
...
结果:
【讨论】:
以上是关于如何在 Apache Camels RouteBuilder.restConfiguration() 中添加 OpenApi/Swagger securitySchemes?的主要内容,如果未能解决你的问题,请参考以下文章
bzoj4430 [Nwerc2015]Guessing Camels赌骆驼
bzoj 4430: [Nwerc2015]Guessing Camels赌骆驼