Created
May 19, 2016 15:39
-
-
Save Allsimon/5387ca3a5f8ddb487fe78daa4ddf6ad2 to your computer and use it in GitHub Desktop.
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
package com.groww; | |
import com.fasterxml.jackson.databind.SerializationFeature; | |
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; | |
import com.groww.db.model.Users; | |
import com.groww.resources.SyncerResource; | |
import com.groww.resources.auth.GrowwAuthenticator; | |
import com.groww.resources.auth.GrowwAuthorizer; | |
import io.dropwizard.Application; | |
import io.dropwizard.auth.AuthDynamicFeature; | |
import io.dropwizard.auth.basic.BasicCredentialAuthFilter; | |
import io.dropwizard.db.DataSourceFactory; | |
import io.dropwizard.hibernate.HibernateBundle; | |
import io.dropwizard.setup.Bootstrap; | |
import io.dropwizard.setup.Environment; | |
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature; | |
public class serverApplication extends Application<serverConfiguration> { | |
private final HibernateBundle<serverConfiguration> hibernateBundle = new HibernateBundle<serverConfiguration>(Users.class) { | |
@Override | |
public DataSourceFactory getDataSourceFactory(serverConfiguration configuration) { | |
return configuration.getDataSourceFactory(); | |
} | |
}; | |
public static void main(final String[] args) throws Exception { | |
new serverApplication().run(args); | |
} | |
@Override | |
public String getName() { | |
return "server"; | |
} | |
@Override | |
public void initialize(final Bootstrap<serverConfiguration> bootstrap) { | |
bootstrap.addBundle(hibernateBundle); | |
bootstrap.getObjectMapper().registerModule(new Hibernate5Module().disable(Hibernate5Module.Feature.USE_TRANSIENT_ANNOTATION)); | |
} | |
@Override | |
public void run(final serverConfiguration configuration, | |
final Environment environment) { | |
environment.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); | |
environment.jersey().register(new SyncerResource(hibernateBundle.getSessionFactory())); | |
environment.jersey().register(new AuthDynamicFeature( | |
new BasicCredentialAuthFilter.Builder<Users>() | |
.setAuthenticator(new GrowwAuthenticator(hibernateBundle.getSessionFactory())) | |
.setAuthorizer(new GrowwAuthorizer()) | |
.setRealm("SUPER SECRET STUFF") | |
.buildAuthFilter())); | |
environment.jersey().register(RolesAllowedDynamicFeature.class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment