-
Notifications
You must be signed in to change notification settings - Fork 3
/
PhotoalbumApplication.java
52 lines (43 loc) · 1.78 KB
/
PhotoalbumApplication.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.mgu.photoalbum;
import com.hubspot.dropwizard.guice.GuiceBundle;
import com.mgu.photoalbum.config.ServiceConfig;
import com.mgu.photoalbum.config.ServiceModule;
import com.mgu.photoalbum.security.Principal;
import io.dropwizard.Application;
import io.dropwizard.auth.AuthFactory;
import io.dropwizard.auth.basic.BasicAuthFactory;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
public class PhotoalbumApplication extends Application<ServiceConfig> {
private static final String APPLICATION_NAME = "Photoalbum Service";
private GuiceBundle<ServiceConfig> guiceBundle;
@Override
public void initialize(final Bootstrap<ServiceConfig> bootstrap) {
this.guiceBundle = GuiceBundle.<ServiceConfig>newBuilder()
.addModule(new ServiceModule())
.setConfigClass(ServiceConfig.class)
.enableAutoConfig(getClass().getPackage().getName())
.build();
bootstrap.addBundle(guiceBundle);
}
@Override
public void run(final ServiceConfig serviceConfig, final Environment environment) throws Exception {
// we let Guice manage everything with regard to web resources etc.
// no configuration required
final BasicAuthenticator authenticator = guiceBundle.getInjector().getInstance(BasicAuthenticator.class);
environment
.jersey()
.register(AuthFactory.binder(new BasicAuthFactory<>(authenticator, "Photoalbum Realm", Principal.class)));
}
@Override
public String getName() {
return APPLICATION_NAME;
}
public static void main(String[] args) {
try {
new PhotoalbumApplication().run(args);
} catch (Throwable t) {
System.err.println(t);
}
}
}