非常によく似た投稿がありますが、未回答です。
WebSocket を使用した私の JavaFX アプリは
- ユーザーID、パスワードをサーバーに送信
- セッションを維持して、ユーザーが個人データ管理などを行えるようにします。
から学ぶ
Oracle WebSocket、 Tyrus 8.14 クライアント HTTP 認証
私は持っている:
@ClientEndPoint
public class loginEndPoint {
final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
public static void main(String [] args) {
AuthConfig authConfig = AuthConfig.Builder.create().disableBasicAuth().build();
Credentials credentials = new Credentials("ws_user", "password");
client.getProperties().put(ClientProperties.AUTH_CONFIG, authConfig);
client.getProperties().put(ClientProperties.CREDENTIALS, credentials);
client.connectToServer(new Endpoint() {
@Override
public void onOpen(Session session, EndpointConfig config) {
try {
session.addMessageHandler((MessageHandler.Whole<String>) (String message) -> {
System.out.println("Received message: "+message);
messageLatch.countDown();
});
//let user do some data management
} catch (IOException e) {
System.out.println("Connect Fail.");
}
}
}, cec, new URI("ws://localhost/myApp/login"));
}
}
これらのコードは認証を行うのに適切ですか? @ServerEndPoint でサーバー側の認証をどこで行うことができますか?
@ServerEndpoint
public class loginServerEndPoint {
}
手伝ってくれてありがとう。