340.3. API doc에 보안 정의 추가

Camel 2.22.0에서 사용 가능

Rest DSL은 이제 생성된 API 문서에서 Swagger 보안Definition 선언을 지원합니다. 예를 들면 다음과 같습니다.

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 Key - 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 키 보안을 사용하고 put 작업은 읽기 및 쓰기가 허용되는 범위와 함께 OAuth 보안을 사용하고 있습니다.