i am using the dropwizard framework for developing REST apis
i have successfully managed to integrate Spring Security into the dropwizard project and it works like a charm.
Unfortunately i have not been able to get Spring Session to work with dropwizard.
i have followed the guide for using Spring Session with Spring Security and Rest , no session is created or any http-headers seen even though i could see the Spring session configuration initialised in the dropwizard logs
INFO [2016-01-21 04:05:53,326] org.springframework.beans.factory.support.DefaultListableBeanFactory: Overriding bean definition for bean 'httpSessionStrategy': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=springSecurityConfig; factoryMethodName=httpSessionStrategy; initMethodName=null; destroyMethodName=(inferred); defined in com.cr.security.SpringSecurityConfig] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=springSessionConfig; factoryMethodName=httpSessionStrategy; initMethodName=null; destroyMethodName=(inferred); defined in com.cr.security.SpringSessionConfig]
what is the correct way to register Spring session with dropwizard, i need help to tie up spring session with dropwizard.
EDIT:
i have added an example with Spring-security integrated into dropwizard.
Github Repository
This is the code section to wire spring security into dropwizard.
//initialize spring context
AnnotationConfigWebApplicationContext parent=new AnnotationConfigWebApplicationContext();
AnnotationConfigWebApplicationContext ctx=new AnnotationConfigWebApplicationContext();
parent.refresh();
parent.getBeanFactory().registerSingleton("configuration", configuration);
parent.registerShutdownHook();
parent.start();
//real main app context has to link to parent context
ctx.setParent(parent);
ctx.register(SecurityConfig.class);
//scan all APIS
ctx.scan("com.poc.dropwizard");
ctx.scan("com.poc.spring");
ctx.refresh();
ctx.registerShutdownHook();
ctx.start();
//link spring to embedded jetty
environment.servlets().addServletListeners(new ContextLoaderListener(ctx));
//activate spring security filter
Dynamic filterRegistration=environment.servlets().addFilter("springSecurityFilterChain",DelegatingFilterProxy.class);
filterRegistration.setInitParameter("listener-class", ContextLoaderListener.class.toString());
filterRegistration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
This is the section where i am not sure how to force jetty-dropwizard to use the spring-session
//link spring-session to embedded jetty
//TODO - link spring session
environment.servlets().setSessionHandler(new SessionHandler());