337장. API doc에 보안 정의 추가
Camel 3.1.0부터 사용 가능
Rest DSL은 이제 생성된 API 문서에서 OpenApi 보안Definitions 선언을 지원합니다. 예를 들면 다음과 같습니다.
rest("/user").tag("dude").description("User rest service")
// setup security definitions
.securityDefinitions()
.oauth2("petstore_auth").authorizationUrl("http://petstore.swagger.io/oauth/dialog").end()
.apiKey("api_key").withHeader("myHeader").end()
.end()
.consumes("application/json").produces("application/json")
여기에서 두 가지 보안 정의를 설정합니다.
- OAuth2 - 제공된 URL을 통한 암시적 권한 부여
- API 키 - myHeader라는 HTTP 헤더에서 제공되는 api 키 사용
그런 다음 키를 참조하여 사용할 보안을 나머지 작업에 지정해야 합니다(petstore_auth 또는 api_key).
.get("/{id}/{date}").description("Find user by id and date").outType(User.class)
.security("api_key")
...
.put().description("Updates or create a user").type(User.class)
.security("petstore_auth", "write:pets,read:pets")
여기에서 get 작업은 Api Key 보안을 사용하며 put 작업은 허용되는 읽기 및 쓰기 상태의 OAuth 보안을 사용하고 있습니다.