2

在我基于 Jersey 2 的 rest 应用程序中,我添加了 spring 安全过滤器链来检查身份验证。一切正常,除了在单元测试期间,如果我尝试添加该安全链,我会收到 500 错误(并且代码指针永远不会转到服务资源方法)。根据这张票,现在应该修复在 JerseyTest 中添加过滤器链。

但我还没有找到一种方法来正确地做到这一点。我的 JerseySpringTest 类如下所示:

@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();
}

任何帮助将不胜感激。

4

0 回答 0