Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在登录测试的SecurityContext中未找到身份验证对象_Java_Spring_Testing_Cucumber_Rest Assured - Fatal编程技术网

Java 在登录测试的SecurityContext中未找到身份验证对象

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 {

我是在春季环境中使用黄瓜的新手。我想在身份验证后进行登录测试。但得到“在SecurityContext中未找到身份验证对象”。我正在使用rest-assured来测试它。它在《邮递员》中运行良好,但在《放心》中出现了错误。任何帮助都将不胜感激

这是我的密码

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