Java 在登录测试的SecurityContext中未找到身份验证对象
我是在春季环境中使用黄瓜的新手。我想在身份验证后进行登录测试。但得到“在SecurityContext中未找到身份验证对象”。我正在使用rest-assured来测试它。它在《邮递员》中运行良好,但在《放心》中出现了错误。任何帮助都将不胜感激 这是我的密码Java 在登录测试的SecurityContext中未找到身份验证对象,java,spring,testing,cucumber,rest-assured,Java,Spring,Testing,Cucumber,Rest Assured,我是在春季环境中使用黄瓜的新手。我想在身份验证后进行登录测试。但得到“在SecurityContext中未找到身份验证对象”。我正在使用rest-assured来测试它。它在《邮递员》中运行良好,但在《放心》中出现了错误。任何帮助都将不胜感激 这是我的密码 private static String token; @Given("authorized user") public void authorized_user() throws JSONException {
private static String token;
@Given("authorized user")
public void authorized_user() throws JSONException {
RequestSpecification request = RestAssured.given();
Response res = request
.auth().basic("USER", "password")
.contentType("application/x-www-form-urlencoded")
.formParam("username", "USER")
.formParam("password", "password")
.formParam("client_id", "android")
.formParam("grant_type", "password")
.formParam("scope", "trust")
.when()
.post("http://localhost:8080/com.abcde.webservices/oauth/token");
System.out.println("Response : "+res.asString());
System.out.println(res.getStatusCode());
JSONObject jsonObject = new JSONObject(res.getBody().asString());
token = jsonObject.get("access_token").toString();
String tokenType = jsonObject.get("token_type").toString();
System.out.println("Oauth Token with type " + tokenType + " " + token);
}
@Then("login as a user")
public void login_as_a_user() {
RequestSpecification request = RestAssured.given();
System.out.println(token);
Response res = request
.contentType("application/json")
.formParam("access_token", token)
.when()
.post("http://localhost:8080/com.abcde.webservices/services/m/user/login");
System.out.println("Response : "+res.asString());
System.out.println(res.getStatusCode());
}
我是在以用户方法运行登录时得到这个消息的
{"error":"unauthorized",
"error_description":"An Authentication object was not found in the SecurityContext"}
401