How to authenticate JavaFX client in JavaEE

I am developing a three-tier application with JavaFX on the client side, JavaEE / Glassfish on the server side and MySQL as a database management system. I also used REST and JSON to transmit data over the network. Now I'm trying to configure authentication using JavaEE security. I use a declarative approach with beans annotations at the corporate level, I have already configured the Glassfish file area (add user / group) and the Glassfish-web.xml handle (add the group name and role tags). The JavaEE tutorial says that if all the necessary preparations are made when the client is trying to get a secure Glassfish resource, ask the client to enter a username / password pair. I understand how this works if it is a web client, but in my case it is a JavaFX desktop client, and I don’t understandhow Glassfish requests a client in a desktop application. How to create an authentication mechanism using JavaFX-Glassfish. Please help.

UPDATE Authentication popup window, if I try to call a servlet from a browser (Chrome, IE) and the authentication mechanism may work. But when I open the JavaFX window, I see nothing (white scene). Here is the class code (JavaFX WebView) that I unsuccessfully used to open the login window:

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

    public class WebViewSample extends Application {
        private Scene scene;

        @Override
        public void start(Stage stage) {
            // create the scene
            stage.setTitle("Web View");
            scene = new Scene(new Browser(), 750, 500, Color.web("#666970"));
            stage.setScene(scene);
            scene.getStylesheets().add("webviewsample/BrowserToolbar.css");
            stage.show();
        }

        public static void main(String[] args) {
            launch(args);
        }
    }

    class Browser extends Region {

        final WebView browser = new WebView();
        final WebEngine webEngine = browser.getEngine();

        public Browser() {

        getStyleClass().add("browser");
    webEngine.load("http://localhost:8080/ForthDynamicWebProject/FirstServlet");
        getChildren().add(browser);
            }
        }
+4
source share
1 answer

You should not use standard Java EE cookie authentication because your client is not a web application.

You can use Token authentication solution. The following is a guide.

  • . . , , userId, , ... JWT (Json Web Token). / .

  • JavaFX: . . , . .

  • JavaFX: HTTP- ( ..). Java EE , , . , . Java EE Filter .

+2

Source: https://habr.com/ru/post/1688647/


All Articles