Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use a configured header to provide a user into a Dropwizard application, e.g. from an upstream proxy

License

NotificationsYou must be signed in to change notification settings

nightowlengineer/dw-header-auth-bundle

Repository files navigation

This bundle provides the ability to define a header to take a user (or 'principal') ID from, and use as an authenticateduser throughout the application. This is mainly intended for use in applications that sit behind a reverse proxy thatwill extract or provide the user information as required. This bundle also registers the RolesAllowedDynamic feature,meaning you can add @RolesAllowed annotations to restrict calls as needed.

It's important that any application that relies on authentication done in this manner isproperly secured frommalicious requests (for example, by locking down the application to only accept connections from the upstream proxy)

Build Status

Maven Setup

<dependency>  <groupId>engineer.nightowl</groupId>  <artifactId>dw-header-auth-bundle</artifactId>  <version>1.3.5-1</version></dependency>

Getting Started

Implement the HeaderAuthConfiguration:

publicclassSampleConfigurationextendsConfigurationimplementsHeaderAuthConfiguration {@NotNull@JsonProperty("authentication")privateHeaderAuthConfigurationheaderAuthConfiguration;@OverridepublicHeaderAuthConfigurationgetHeaderAuthConfiguration() {returnheaderAuthConfiguration;  }}

Add the bundle:

publicclassSampleServiceextendsApplication<SampleConfiguration> {publicstaticvoidmain(String[]args)throwsException {newSampleService().run(args);    }@Overridepublicvoidinitialize(Bootstrap<SampleConfiguration>bootstrap) {// User represents your internal user representation which extends Principal// UserService represents your internal user information source which extends PrincipalServicefinalHeaderAuthBundle<User,UserService>headerAuthBundle =newHeaderAuthBundle<>(User.class,newUserService());bootstrap.addBundle(headerAuthBundle);    }@Overridepublicvoidrun(SampleConfigurationconfiguration,Environmentenvironment) {        ...    }}

Inside your service's configuration yml file, add the header name that should be inspected:

authentication:headerName:USER_ID

And that's it! Any request that is sent to your service will inspect the header USER_ID and use this to return a singleuser and their roles from your UserService.

About

Use a configured header to provide a user into a Dropwizard application, e.g. from an upstream proxy

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp