DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How To Implement OAuth2 Security in Microservices
  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS
  • Component Tests for Spring Cloud Microservices
  • Authentication With Remote LDAP Server in Spring Web MVC

Trending

  • Proactive Security in Distributed Systems: A Developer’s Approach
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Tired of Spring Overhead? Try Dropwizard for Your Next Java Microservice
  • How to Use AWS Aurora Database for a Retail Point of Sale (POS) Transaction System
  1. DZone
  2. Data Engineering
  3. Data
  4. Spring Web Flux UI with Spring Security

Spring Web Flux UI with Spring Security

Take a look at how to construct an application using Spring Web Flux and Thymeleaf, with Spring security, a gateway services, and other microservices.

By 
Rajesh Venugopal user avatar
Rajesh Venugopal
·
Aug. 02, 20 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
5.4K Views

Join the DZone community and get the full member experience.

Join For Free

This is an example of UI application built using Spring Web Flux and Thymeleaf templates. It has a login page and on authentication shows a list of customers. It interacts with Spring Gateway service which acts as the backend for this frontend.   

The UI application has the following pages:

  1. Login Page - The default spring security login page
  2. Customer List - This page shows a list of customers
  3. Customer List Reactive - Another way of showing the same customer list with web flux reactive call

Along with this, other services involved are:

  1. Customer Service application - A simple microservice which has the rest endpoint to return list of customers.
  2. Spring Gateway application - A Spring Cloud gateway service which does the authentication and routing.
  3. Discovery Service - Both the customer microservice and Spring Gateway microservice are registered with this service.

All the components here are developed using Spring Boot.

The flow from UI to the Customer Service application is shown below:

  1. The UI service calls the Gateway service for authentication.
  2. After authentication, it lands on a page that shows the list of customers.
  3. Another link is available to retrieve the customers list in a reactive way.

User and customer database

The codebase for this whole setup is available here. 

To run this application, open command prompt or terminal and go to the corresponding folder where pom files are present and run the below command. 

PowerShell
 




xxxxxxxxxx
1


 
1
mvn spring-boot:run


Start the services in the following order:

  1. Spring Discovery Service - This runs on port 8761
  2. Customer Service - This runs on port 8082. It has its own H2 database. When application is started, a "customer" table is created with 50 customer records. The names for the customers have been taken from here.
  3. Gateway Service - This runs on port 8080. It uses feign client to interact with Customer Service. It also has H2 dtabase. When the application is started, a "user" and "user_role" table are created with some default entries. 
  4. Spring Web Flux application - This runs on port 9080. The html has been built using Thymeleaf and bootstrap.

After all the services have started, open "http://localhost:9080/login" in your browser.  You should see the below window. Enter "user1" for Username and Password.

Sign in page

Next, it should take you to the customer list page which shows a list of 50 customers.

Customer list

On clicking the "Customers Reactive" link on the left navigation pane, it should display the same list in a reactive way. To show the reactive behavior, a delay of 200 ms has been introduced. Please check the method "findAllReactive" in "CustomerController.java" within spring-web-flux project.

Java
 




xxxxxxxxxx
1
10


 
1
    @GetMapping("/findAllCustomersReactive")
2
    public String findAllReactive(Model model, Authentication authentication) {
3
        String token = jwtUtils.generateJwtToken(authentication);
4
        List<Customer> customers = this.customerServcie.findAllCustomers(token);
5
        // Introducing a delay of 200 ms to show the streaming behaviour
6
        IReactiveDataDriverContextVariable data = new ReactiveDataDriverContextVariable(Flux.fromIterable(customers).delayElements(Duration.ofMillis(200)));
7
        model.addAttribute("customers", data);
8

          
9
        return "customers-reactive";
10
    }



Hope this example will help as a starting point to build reactive web UI using spring web flux. 

Spring Framework Spring Security Web Service Flux (machine-learning framework) microservice application

Opinions expressed by DZone contributors are their own.

Related

  • How To Implement OAuth2 Security in Microservices
  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS
  • Component Tests for Spring Cloud Microservices
  • Authentication With Remote LDAP Server in Spring Web MVC

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!