Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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