swagger-api/swagger-codegen

[java spring] API Key based Authentication how to access ?

开放

#7,088 创建于 2017年12月1日

 (1 条评论) (1 个反应) (0 位负责人)HTML (5,474 个派生)batch import
Client: JavaGeneral: QuestionServer: JavaServer: Springhelp wanted

仓库指标

星标
 (12,701 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

This is more of a question.

We have a swagger file with authentication mechanism as apikey and appid

security:
  - apiKey: []
    appId: []

Upon generation of Server ( Java Spring ) and Client (Java) below snippets got generated

Server the interface GroupAPI has below code

 @ApiOperation(value = "Return the group which was created", nickname = "createGroup", notes = "Returns HTTP 201 if the group is successfully created.", response = Void.class, authorizations = {
        @Authorization(value = "apiKey"),
        @Authorization(value = "appId")
    }, tags={ "UserGroups", })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "OK. Request is OK."),
        @ApiResponse(code = 201, message = "The request has been fulfilled, and a new resource is created ."),
        @ApiResponse(code = 400, message = "Bad Request. The request cannot be fulfilled due to bad syntax."),
        @ApiResponse(code = 401, message = "Unauthorized. Authentication failed or not provided"),
        @ApiResponse(code = 403, message = "Forbidden. The user might not have the necessary permissions for a resource."),
        @ApiResponse(code = 500, message = "Internal Server Error. An unexpected condition was encountered."),
         })
    @RequestMapping(value = "/identity/groups",
        produces = { "application/json" }, 
        consumes = { "application/json" },
        method = RequestMethod.POST)
    ResponseEntity<Void> createGroup(@ApiParam(value = "" ,required=true )  @Valid @RequestBody Group body, @RequestHeader(value = "Accept", required = false) String accept) throws Exception;

How do we access the apikey and appId in the controller class method that looks like below ?

public ResponseEntity<Void> createGroup(@ApiParam(value = "" ,required=true )  @Valid @RequestBody Group body,
        @RequestHeader(value = "Accept", required = false) String accept) throws Exception {
        // do some magic!
        return new ResponseEntity<Void>(HttpStatus.OK);
    }

Is there any reference example , greatly appreciated .

贡献者指南