1

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 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I have the same hybrid type of application and everything works fine, I want to use WebClient API of spring boot, it gives errors, why is that so?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.