Skip to content

Instantly share code, notes, and snippets.

@christophercurrie
Last active December 21, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophercurrie/6343551 to your computer and use it in GitHub Desktop.
Save christophercurrie/6343551 to your computer and use it in GitHub Desktop.
Example of different authenticators in dropwizard
abstract class MyPrincipal {};
class BasicAuthPrincipal extends MyPrincipal {};
class OAuthPrincipal extends MyPrincipal {};
class BasicAuthenticator implements Authenticator<BasicCredentials, BasicAuthPrincipal> {
public Optional<BasicAuthPrincipal> authenticate(BasicCredentials creds) {
return new BasicAuthPrincipal();
}
};
class OAuthAuthenticator implements Authenticator<String, OAuthPrincipal> {
public Optional<OAuthPrincipal> authenticate(String creds) {
return new OAuthPrincipal();
}
};
@Path("/basic")
class BasicResource
{
@GET
public String get(@Auth BasicAuthPrincipal user) {
return "Basic!"
}
}
@Path("/ouath")
class OAuthResource
{
@GET
public String get(@Auth OAuthPrincipal user) {
return "OAuth!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment