Spring security 在没有身份验证的情况下对rest服务进行单元测试

Spring security 在没有身份验证的情况下对rest服务进行单元测试,spring-security,restful-authentication,Spring Security,Restful Authentication,我用的是spring security的球衣。 我想用Junit测试我的rest服务,但存在身份验证问题。 我的项目服务使用spring安全性进行保护,客户端应该经过身份验证。 我想知道是否有办法(或者有办法)阻止我的测试的身份验证,或者像浏览器一样,记住客户端并运行多个测试 Client client = Client.create(); //I usually write some code here to authenticate client. WebResource webReso

我用的是spring security的球衣。 我想用Junit测试我的rest服务,但存在身份验证问题。 我的项目服务使用spring安全性进行保护,客户端应该经过身份验证。 我想知道是否有办法(或者有办法)阻止我的测试的身份验证,或者像浏览器一样,记住客户端并运行多个测试

Client client = Client.create();

//I usually write some code here to authenticate client.

WebResource webResource = client.resource("http://localhost:8080/SomeResources");

ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);

也许您可以使用抢占式身份验证:在测试中使用凭据(例如使用Apache HTTP组件)伪造正确的HTTP请求。