我正在开发一个dropwizard REST服务.我使用https://bitbucket.org/b_c/jose4j/wiki/Home在jwt中添加了身份验证
令牌必须进入Authorization标头
Authorization: Bearer [TOKEN]
我想找到一个很好的方法来添加一些swagger注释,以便在swagger-ui上拥有授权标头.
我找到了一个解决方法,隐藏了身份验证参数并添加了一个虚拟参数 @HeaderParam
@POST @Path("/test/") public Foo postBar( @Auth @ApiParam(hidden = true) Principal user, @ApiParam("data") Foo bar, @HeaderParam(value="Authorization")String dummy)
这将添加到参数中:
{ "name" : "Authorization", "in" : "header", "required" : false, "type" : "string" }
如果我把@HeadParam
对Principal user
我得到的运行时间:
Caused by: org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization. [[FATAL] No injection source found for a parameter of type public java.util.Map com.foo.bar.AppResource.get(java.security.Principal) at index 0.; source='ResourceMethod{httpMethod=GET, cOnsumedTypes=[], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class com.mykronoz.data.tracking.resources.AppResource, handlerCOnstructors=[org.glassfish.jersey.server.model.HandlerConstructor@6374d682]}, definitiOnMethod=public java.util.Map com.foo.bar.AppResource.get(java.security.Principal), parameters=[Parameter [type=interface java.security.Principal, source=Authorization, defaultValue=null]], respOnseType=java.util.Map}, nameBindings=[]}']
有没有更好的方法呢?