dropwizard-simpleauth

A Dropwizard library for simple @Auth

License

License

Categories

Categories

DropWizard Container Microservices
GroupId

GroupId

org.whispersystems
ArtifactId

ArtifactId

dropwizard-simpleauth
Last Version

Last Version

0.4.0
Release Date

Release Date

Type

Type

jar
Description

Description

dropwizard-simpleauth
A Dropwizard library for simple @Auth
Project URL

Project URL

https://github.com/WhisperSystems/dropwizard-simpleauth
Source Code Management

Source Code Management

https://github.com/WhisperSystems/dropwizard-simpleauth

Download dropwizard-simpleauth

How to add to project

<!-- https://jarcasting.com/artifacts/org.whispersystems/dropwizard-simpleauth/ -->
<dependency>
    <groupId>org.whispersystems</groupId>
    <artifactId>dropwizard-simpleauth</artifactId>
    <version>0.4.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.whispersystems/dropwizard-simpleauth/
implementation 'org.whispersystems:dropwizard-simpleauth:0.4.0'
// https://jarcasting.com/artifacts/org.whispersystems/dropwizard-simpleauth/
implementation ("org.whispersystems:dropwizard-simpleauth:0.4.0")
'org.whispersystems:dropwizard-simpleauth:jar:0.4.0'
<dependency org="org.whispersystems" name="dropwizard-simpleauth" rev="0.4.0">
  <artifact name="dropwizard-simpleauth" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.whispersystems', module='dropwizard-simpleauth', version='0.4.0')
)
libraryDependencies += "org.whispersystems" % "dropwizard-simpleauth" % "0.4.0"
[org.whispersystems/dropwizard-simpleauth "0.4.0"]

Dependencies

compile (1)

Group / Artifact Type Version
io.dropwizard : dropwizard-auth jar 1.3.1

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19

Project Modules

There are no modules declared in this project.

dropwizard-simpleauth

A Dropwizard library that lets you use simple @Auth annotations for authenticating multiple types, without having to deal with @RolesAllowed style authorizations.

Install from maven central:

<dependency>
  <groupId>org.whispersystems</groupId>
  <artifactId>dropwizard-simpleauth</artifactId>
  <version>${latest_version}</version>
</dependency>

The details

This library allows writing an authenticated Dropwizard resource to look like this:

@Path("/api/v1/mail")
public class MailResource {

  @Timed
  @POST
  @Path("/{destination}/")
  @Consumes(MediaType.APPLICATION_JSON_TYPE)
  public void sendMessage(@Auth User sender,
                          @PathParam("destination") String destination,
                          @Valid Message message)
  {
    ...
  }
  
  @Timed
  @DELETE
  @Path("/{messageId}/")
  public void sendMessage(@Auth Admin admin,
                          @PathParam("messageId") long messageId)
  {
    ...
  }
  
  
}

No "authorization" tags like @AllowAll, @DenyAll, @RolesAllowed are used. Instead, the @Auth tag allows you to authenticate multiple different "principal" types (in this example both User and Admin), neither of which have to extend Principal.

Registering authenticators

To support authenticating multiple types, register multiple AuthFilters:

@Override
public void run(ExampleConfiguration configuration,
                Environment environment) 
{
    environment.jersey().register(new AuthDynamicFeature(
            new BasicCredentialAuthFilter.Builder<User>()
                .setAuthenticator(new UserAuthenticator())
                .setPrincipal(User.class)
                .buildAuthFilter(),
            new BasicCredentialAuthFilter.Builder<Admin>()
                .setAuthenticator(new AdminAuthenticator())
                .setPrincipal(Admin.class)
                .buildAuthFilter()));

    environment.jersey().register(new AuthValueFactoryProvider.Binder());
}

That's it!

org.whispersystems

Open Whisper Systems

The Signal repositories have moved to github.com/signalapp

Versions

Version
0.4.0
0.3.0
0.2.0
0.1.1
0.1.0