Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.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 SimpleFramework在服务器上验证客户端凭据_Java_Https_Simple Framework - Fatal编程技术网

使用Java SimpleFramework在服务器上验证客户端凭据

使用Java SimpleFramework在服务器上验证客户端凭据,java,https,simple-framework,Java,Https,Simple Framework,我正在使用Java SimpleFramework开发一个支持SSL/TLS的服务器。我想知道如何在服务器上验证客户端身份验证 在服务器端,我正在扩展org.simpleframework.http.core.ContainerServer并覆盖流程方法,如下所示: @Override public void process(Socket socket) throws IOException { // Ensures client authentication is required

我正在使用Java SimpleFramework开发一个支持SSL/TLS的服务器。我想知道如何在服务器上验证客户端身份验证

在服务器端,我正在扩展org.simpleframework.http.core.ContainerServer并覆盖流程方法,如下所示:

@Override
public void process(Socket socket) throws IOException {
    // Ensures client authentication is required
    socket.getEngine().setNeedClientAuth(true);

    super.process(socket);
}
这是为了确保客户端进行身份验证。请注意,如果我删除对setNeedClientAuth的调用,我的程序将正常运行

在客户端,使用以下代码:

HttpClient client = new HttpClient();

Credentials defaultcreds = new UsernamePasswordCredentials("username", "password");
client.getState().setCredentials(AuthScope.ANY, defaultcreds);

GetMethod get = new GetMethod("https://url.to.server");
get.setDoAuthentication(true);

client.executeMethod(get);
启用身份验证要求时,我得到以下异常:

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
我猜这与传递的凭据从未经过验证这一事实有关


总结一下我的问题,我应该如何继续验证服务器上的客户端

我使用SimpleFramework进行自己的web开发。而且它没有一个名为HttpClient的类,所以我敢肯定您要么感到困惑,要么正在使用一个超旧版本的SimpleFrameWork。您是对的。HttpClient是apachecommons库的一部分。但是,我的问题与服务器端更相关,在服务器端使用SimpleFramework。在服务器上设置setNeedClientAuthtrue后,我需要了解如何拦截和验证客户端凭据。当我使用simpleframework时,我甚至不使用setNeedClientAuth,我只使用令牌cookie和/login路由自己进行身份验证。另外,看看这是否有助于您: