Last active
December 21, 2015 17:49
-
-
Save christophercurrie/6343551 to your computer and use it in GitHub Desktop.
Example of different authenticators in dropwizard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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