In my Jersey 2 based rest application, I have added spring security filter chain to check authentication. Everything works well except during unit-test if I try to add that security chain I get 500 error (and the code pointer never goes to service resource methods). According to this ticket, adding filter chain in JerseyTest should be fixed by now.
But I am yet to find a way to do it properly. My JerseySpringTest class look like this:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:META-INF/applicationContext-test.xml", "classpath:META-INF/security-context.xml"})
@ActiveProfiles("unit-test")
@WebAppConfiguration
public abstract class JerseySpringTest {
private JerseyTest _jerseyTest;
public final WebTarget target(final String path) {
return _jerseyTest.target(path);
}
@Before
public void setupJerseyTest() throws Exception {
_jerseyTest.setUp();
}
@After
public void tearDownJerseyTest() throws Exception {
_jerseyTest.tearDown();
}
@Autowired
public void setApplicationContext(final ApplicationContext context) {
_jerseyTest = new JerseyTest() {
@Override
protected Application configure() {
ResourceConfig application = JerseySpringTest.this.configure();
application.register(CustormDelegatingFilterProxy.class);
application.property("springSecurityFilterChain", "/services/*");
application.property("contextConfig", context);
return application;
}
};
}
protected abstract ResourceConfig configure();
}
Any help will be appreciated.