use of org.sdase.commons.server.auth.key.RsaPublicKeyLoader in project sda-dropwizard-commons by SDA-SE.
the class AuthBundle method run.
@Override
public void run(T configuration, Environment environment) {
AuthConfig config = configProvider.apply(configuration);
if (config.isDisableAuth()) {
LOG.warn("Authentication is disabled. This setting should NEVER be used in production.");
}
Tracer currentTracer = tracer == null ? GlobalTracer.get() : tracer;
Client client = createKeyLoaderClient(environment, config, currentTracer);
RsaPublicKeyLoader keyLoader = new RsaPublicKeyLoader();
config.getKeys().stream().map(k -> this.createKeySources(k, client)).forEach(keyLoader::addKeySource);
ScheduledExecutorService executorService = environment.lifecycle().scheduledExecutorService("reloadKeysExecutorService").build();
RsaKeyLoaderScheduler.create(keyLoader, executorService).start();
AuthService authRSA256Service = new AuthRSA256Service(keyLoader, config.getLeeway());
JwtAuthenticator authenticator = new JwtAuthenticator(authRSA256Service, config.isDisableAuth());
JwtAuthFilter<JwtPrincipal> authFilter = new JwtAuthFilter.Builder<JwtPrincipal>().withTracer(currentTracer).setAcceptAnonymous(!useAnnotatedAuthorization).setAuthenticator(authenticator).buildAuthFilter();
if (useAnnotatedAuthorization) {
// Use the AuthDynamicFeature to only affect endpoints that are
// annotated
environment.jersey().register(new AuthDynamicFeature(authFilter));
} else {
// Apply the filter for all calls
environment.jersey().register(authFilter);
}
environment.jersey().register(JwtAuthExceptionMapper.class);
environment.jersey().register(ForbiddenExceptionMapper.class);
}
use of org.sdase.commons.server.auth.key.RsaPublicKeyLoader in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method setUp.
@BeforeEach
void setUp() {
this.keyLoader = new RsaPublicKeyLoader();
this.service = new AuthRSA256Service(this.keyLoader, 0);
}
Aggregations