using javafx client with spring boot and spring security

I'm going to create a javafx client and http server using spring boot that includes authentication.

The server is planning to use spring security for login and appache httpClient for clients.

Can I create a login service from this structure?

Or should I choose a different method?

I understand Spring security authenticates using cookie and session.

1 answer

  • answered 2019-12-05 18:55 Shekhar Rai

    You can make a hybrid application using JavaFX and Spring-Boot. And of course, you can use Spring Security as well. I recommend you to use maven project to package your hybrid-application.

    Can I create a login service from this structure?

    Yes, you can!

    Or should I choose a different method?

    As you can use spring-security for your login service, you may not need other methods but you can use a lot of authentication-authorization libraries.

    Why Apache-HttpClient?

    It seems you are planning to use Apache-HttpClient to bind your JavaFX and Spring-Boot services. Actually you can use your login service in your JavaFX application without exposing the service as a Restful Service. You can use spring's Dependency Injection to wire your service in your JavaFX controller class. ex:

    @Autowired
    private LoginService loginService;
    

    If you are comfortable with spring applications you can also use functionalities that spring provides such as Spring Data JPA, etc.

    SpringBoot + JavaFX Application

    Here is a simple example of hybrid application,

    import javafx.stage.Stage;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.context.ConfigurableApplicationContext;
    
    @SpringBootApplication
    public class YourApp extends Application {
    
        protected ConfigurableApplicationContext springContext;
    
        public static void main(final String[] args) {
            Application.launch(args);
        }
    
        @Override
        public void init() throws Exception {
            springContext = springBootApplicationContext();
        }
    
        @Override
        public void start(Stage stage) throws Exception {
            ....
        }
    
        @Override
        public void stop() throws Exception {
            springContext.close();
        }
    
        private ConfigurableApplicationContext springBootApplicationContext() {
            SpringApplicationBuilder builder = new SpringApplicationBuilder(YourApp.class);
            String[] args = getParameters().getRaw().stream().toArray(String[]::new);
            return builder.run(args);
        }
    
    }
    

    It's not possible to define a boilerplate of application here but the above code does the tricks to start the application.

    P.S.: You can check this JavaFXSpringBootApp boilerplate to review the needed ideas.