Skip to content

KastorDriver/WebApp

Repository files navigation

Spring Boot Web Application with OpenID Connect Authentication

This is a Spring Boot web application that demonstrates OpenID Connect authentication using Keycloak. The application has two endpoints:

  1. A public endpoint accessible to everyone
  2. A protected endpoint accessible only to authenticated users

Features

  • Spring Boot 3.1.5
  • Spring Security with OpenID Connect
  • Thymeleaf templates for the frontend
  • Bootstrap 5 for styling

Pages

  • Home Page: Publicly accessible. Greets authenticated users by name.
  • User Page: Protected page accessible only to authenticated users. Displays user information.
  • Login Page: Provides a link to authenticate with Keycloak.

Prerequisites

  • Java 17 or higher
  • Gradle
  • Keycloak server (for OpenID Connect authentication)

Running the Application

  1. Clone the repository
  2. Configure Keycloak (see below)
  3. Update application.properties with your Keycloak settings
  4. Run the application:
    ./gradlew bootRun
    
  5. Access the application at http://localhost:8080

Configuring Keycloak

  1. Install and start Keycloak
  2. Create a new realm (e.g., webapp2-realm)
  3. Create a new client:
    • Client ID: webapp2-client
    • Client Protocol: openid-connect
    • Access Type: confidential
    • Valid Redirect URIs: http://localhost:8080/*
  4. After creating the client, go to the "Credentials" tab to get the client secret
  5. Create a user in the realm
  6. Update the application.properties file with your Keycloak settings:
    spring.security.oauth2.client.registration.keycloak.client-id=webapp2-client
    spring.security.oauth2.client.registration.keycloak.client-secret=your-client-secret
    spring.security.oauth2.client.provider.keycloak.issuer-uri=http://localhost:8180/auth/realms/webapp2-realm
    

Application Structure

  • Main.java: Spring Boot application entry point
  • HomeController.java: Controller for the public endpoint
  • UserController.java: Controller for the protected endpoint
  • SecurityConfig.java: Security configuration for OpenID Connect
  • templates/home.html: Home page template
  • templates/user/home.html: User page template
  • templates/login.html: Login page template
  • application.properties: Application configuration

Notes

  • The application uses Spring Security's OAuth2 client support for OpenID Connect authentication
  • Thymeleaf templates use Bootstrap 5 for styling
  • The application includes debug logging for Spring Security to help with troubleshooting

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published