0

我正在尝试在 java 中创建一个允许使用 Yubikey 进行身份验证的 RESTful Web 服务。我正在修改我在尝试了解 REST 时完成的现有教程。

我正在尝试从 javax.ws.rs.core.Response 函数中调用验证函数,但不断收到来自导入的 yubikey jar 包的错误。

我从构建路径->库->添加外部罐子导入了这些罐子

将表单发布到 RESTful url 时出现以下错误:

java.lang.NoClassDefFoundError: com/yubico/client/v2/exceptions/YubicoValidationException

package de.vogella.jersey.todo.resources;


import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import com.yubico.client.v2.exceptions.YubicoValidationException;
import com.yubico.client.v2.exceptions.YubicoValidationFailure;
import de.vogella.jersey.todo.resources.Validate;

@Path("/test")
public class Test {

@POST
public Response testCred(@FormParam("username") String username,
          @FormParam("password") String password,
          @FormParam("otp") String otp) throws YubicoValidationException, YubicoValidationFailure {
    int client_id = 11095; 
    boolean status;
    status = Validate.validate(otp, client_id);

    return Response.status(200)
        .entity("validation status: : " + status + ", for client " + otp)
        .build();

    }

}

验证类如下:

package de.vogella.jersey.todo.resources;

import com.yubico.client.v2.YubicoClient;
import com.yubico.client.v2.YubicoResponse;
import com.yubico.client.v2.YubicoResponseStatus;
import com.yubico.client.v2.exceptions.YubicoValidationException;
import com.yubico.client.v2.exceptions.YubicoValidationFailure;


public class Validate {

 public static boolean validate(String otp, int client_id) throws YubicoValidationException, YubicoValidationFailure {
        YubicoClient client = YubicoClient.getClient(client_id);
        YubicoResponse response = client.verify(otp);
        if(response != null && response.getStatus() == YubicoResponseStatus.OK) {
          return true;
        }
        return false;
     }

}
4

0 回答 0