Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do authentication in dropwizard

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)
}
like image 387
birdy Avatar asked Jan 27 '26 21:01

birdy


1 Answers

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.

like image 192
Gary Rowe Avatar answered Jan 29 '26 09:01

Gary Rowe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!