Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Dropwizard with Spring Security

I have found Dropwizard to be amazing framework to quickly build REST services and most of my enterprise conserns are taken care by this f/w except one. It does provide mechanism to secure you service but it is not as extensive as Spring Security.

I want to understand how these two can marry and whether gluing them together is right or not. Any suggestions?

like image 913
ajjain Avatar asked Apr 10 '14 06:04

ajjain


People also ask

Does Dropwizard use spring?

Of the available Dropwizard integrations, Spring support is also included.

Which is better Dropwizard or spring boot?

Spring Boot consumes much more memory. This was true. Spring Boot loaded 7591 classes whereas Dropwizard loaded 6255 classes. Also, heap space consumption of Spring Boot was twice compared to Dropwizard.

What is Dropwizard?

Dropwizard is an open source Java framework for developing ops-friendly, high-performance RESTful backends. It was developed by Yammer to power their JVM based backend.


1 Answers

I have been able to successfully integrate Spring Security with Dropwizard in the project I just finished. Spring Security is really just a glorified ServletFilter that you can add to the Dropwizard application.

Jacek Furmankiewicz has a small sample project that integrates Spring with Dropwizard and this is the specific part regarding how to add the Spring Security filter to the DW app.

https://github.com/jacek99/dropwizard-spring-di-security-onejar-example/blob/master/src/main/java/com/github/jacek99/myapp/MyAppService.java

One thing to keep in mind with the example provided is that this is for Dropwizard 0.6.2 and the current recommended release is 0.7.0.

So instead of this (0.6.2):

environment.addFilter(DelegatingFilterProxy.class,"/*").setName("springSecurityFilterChain");

use this:

FilterRegistration.Dynamic filterRegistration = environment.servlets().addFilter("springSecurityFilterChain", DelegatingFilterProxy.class);
filterRegistration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");

-Matt

like image 190
user2138266 Avatar answered Nov 15 '22 11:11

user2138266