0

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());
austin
  • 1,171
  • 1
  • 13
  • 32
  • I'm not familiar with dropwizard but link to the guide? Sounds like you are missing the Initializer (which implements WebApplicationInitializer) on your classpath. See samples: https://github.com/spring-projects/spring-session/search?utf8=%E2%9C%93&q=Initializer – Selwyn Jan 21 '16 at 14:20
  • Are you able to post an example (i.e. to github)? – Rob Winch Jan 21 '16 at 16:58
  • @RobWinch posted a sample in github https://github.com/austinpio/SpringSession-Dropwizard – austin Jan 25 '16 at 00:36
  • @Austin I think you have misunderstood the guide. That guide is for integration with `spring-security` project(s) NOT `spring-session`. In the pom file you provided you are not importing the `spring-session` artifact. Moreover, the `new SessionHandler()` is a jetty Object and lives in org.eclipse.jetty.server.session.`SessionHandler` and not the spring-session project. – Selwyn Jan 26 '16 at 10:38

0 Answers0