using javafx client with spring boot and spring security

左心房为你撑大大i 提交于 2020-01-06 03:21:27

问题


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:


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.



来源:https://stackoverflow.com/questions/59198935/using-javafx-client-with-spring-boot-and-spring-security

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!