I've built a small sample API using drop wizard.
I would like to implement basic authentication for the server. So that when users access the service, the service returns the data based on the user credentials sent with the request.
I went over the documentation for authentication: http://dropwizard.codahale.com/manual/auth/ but don't quite understand how it would work in an actual running example.
Can someone shed some light on how authentication would work on a url like /foo/bar/{id}/{username}
?
This is how the method looks like for the above URL at the moment. Notice I am just passing the username as a text and no authentication is done at the moment.
@GET
@Path(/foo/bar/{id}/{username})
public Foo getStuff (@PathParam("id") int id, @PathParam("username")) {
return mydao.getFooFromDb(id,username)
}
Have a look at the Dropwizard OpenID example I wrote a while back on GitHub.
It provides all the source code you'll need to get it working and should act as a useful starting point for your project.
如果您希望使用安全过滤器进行非常基本的身份验证和授权,这可能有助于您开始使用: 如何在Dropwizard中对资源进行基本身份验证
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.